Skip to content

🐛 update Use this model snippets for PaddleOCR models #1645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions packages/tasks/src/model-libraries-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,16 +1018,59 @@ export const paddlenlp = (model: ModelData): string[] => {
}
};

export const paddleocr = (model: ModelData): string[] => [
`# pip install paddleocr
from paddleocr import TextDetection
model = TextDetection(model_name="${model.id}")
export const paddleocr = (model: ModelData): string[] => {
const mapping: Record<string, { className: string }> = {
textline_detection: { className: "TextDetection" },
textline_recognition: { className: "TextRecognition" },
seal_text_detection: { className: "SealTextDetection" },
doc_img_unwarping: { className: "TextImageUnwarping" },
doc_img_orientation_classification: { className: "DocImgOrientationClassification" },
textline_orientation_classification: { className: "TextLineOrientationClassification" },
chart_parsing: { className: "ChartParsing" },
formula_recognition: { className: "FormulaRecognition" },
layout_detection: { className: "LayoutDetection" },
table_cells_detection: { className: "TableCellsDetection" },
wired_table_classification: { className: "TableClassification" },
table_structure_recognition: { className: "TableStructureRecognition" },
};

if (model.tags.includes("doc_vlm")) {
return [
`# pip install paddleocr
from paddleocr import DocVLM
model = DocVLM(model_name="${model.id}")
output = model.predict(
input={"image": "path/to/image.png", "query": "Parsing this image and output the content in Markdown format."},
batch_size=1
)
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")`,
];
}

for (const tag of model.tags) {
if (tag in mapping) {
const { className } = mapping[tag];
return [
`# pip install paddleocr
from paddleocr import ${className}
model = ${className}(model_name="${model.id}")
output = model.predict(input="path/to/image.png", batch_size=1)
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")`,
];
];
}
}

return [
`# Please refer to the document for information on how to use the model.
# https://paddlepaddle.github.io/PaddleOCR/latest/en/version3.x/module_usage/module_overview.html`,
];
};

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