Skip to content

Commit 35c6fdb

Browse files
committed
update Use this model snippets for PaddleOCR's models
1 parent 1ad5dc0 commit 35c6fdb

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,16 +1018,60 @@ export const paddlenlp = (model: ModelData): string[] => {
10181018
}
10191019
};
10201020

1021-
export const paddleocr = (model: ModelData): string[] => [
1022-
`# pip install paddleocr
1023-
from paddleocr import TextDetection
1024-
model = TextDetection(model_name="${model.id}")
1021+
export const paddleocr = (model: ModelData): string[] => {
1022+
const mapping: Record<string, { className: string }> = {
1023+
textline_detection: { className: "TextDetection" },
1024+
textline_recognition: { className: "TextRecognition" },
1025+
seal_text_detection: { className: "SealTextDetection" },
1026+
doc_img_unwarping: { className: "TextImageUnwarping" },
1027+
doc_img_orientation_classification: { className: "DocImgOrientationClassification" },
1028+
textline_orientation_classification: { className: "TextLineOrientationClassification" },
1029+
doc_vlm: { className: "DocVLM" },
1030+
chart_parsing: { className: "ChartParsing" },
1031+
formula_recognition: { className: "FormulaRecognition" },
1032+
layout_detection: { className: "LayoutDetection" },
1033+
table_cells_detection: { className: "TableCellsDetection" },
1034+
wired_table_classification: { className: "TableClassification" },
1035+
table_structure_recognition: { className: "TableStructureRecognition" },
1036+
};
1037+
1038+
if (model.tags.includes("doc_vlm")) {
1039+
return [
1040+
`# pip install paddleocr
1041+
from paddleocr import DocVLM
1042+
model = DocVLM(model_name="${model.id}")
1043+
output = model.predict(
1044+
input={"image": "path/to/image.png", "query": "Parsing this image and output the content in Markdown format."},
1045+
batch_size=1
1046+
)
1047+
for res in output:
1048+
res.print()
1049+
res.save_to_img(save_path="./output/")
1050+
res.save_to_json(save_path="./output/res.json")`,
1051+
]
1052+
}
1053+
1054+
for (const tag of model.tags) {
1055+
if (tag in mapping) {
1056+
const { className } = mapping[tag];
1057+
return [
1058+
`# pip install paddleocr
1059+
from paddleocr import ${className}
1060+
model = ${className}(model_name="${model.id}")
10251061
output = model.predict(input="path/to/image.png", batch_size=1)
10261062
for res in output:
10271063
res.print()
10281064
res.save_to_img(save_path="./output/")
10291065
res.save_to_json(save_path="./output/res.json")`,
1030-
];
1066+
];
1067+
}
1068+
}
1069+
1070+
return [
1071+
`# Please refer to the document for information on how to use the model.
1072+
# https://paddlepaddle.github.io/PaddleOCR/latest/en/version3.x/module_usage/module_overview.html`,
1073+
];
1074+
};
10311075

10321076
export const perception_encoder = (model: ModelData): string[] => {
10331077
const clip_model = `# Use PE-Core models as CLIP models

0 commit comments

Comments
 (0)