diff --git a/packages/tasks/src/model-libraries-snippets.ts b/packages/tasks/src/model-libraries-snippets.ts index c506c52fd9..1fc0f5f3fc 100644 --- a/packages/tasks/src/model-libraries-snippets.ts +++ b/packages/tasks/src/model-libraries-snippets.ts @@ -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 = { + 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