Spaces:
Running
Running
Commit
·
03a594f
1
Parent(s):
b538fd3
Adding PaddleOCR
Browse files- app.py +23 -2
- requirements.txt +60 -2
app.py
CHANGED
|
@@ -3,6 +3,9 @@ import gradio as gr
|
|
| 3 |
from docling.document_converter import DocumentConverter, PdfFormatOption
|
| 4 |
from docling.datamodel.pipeline_options import PdfPipelineOptions
|
| 5 |
from docling.datamodel.base_models import InputFormat
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
pipeline_options = PdfPipelineOptions(enable_remote_services=True)
|
| 8 |
converter = DocumentConverter(
|
|
@@ -20,9 +23,26 @@ def get_docling_ocr(pdf_path, page_num):
|
|
| 20 |
markdown_text_docling = result.document.export_to_markdown()
|
| 21 |
return markdown_text_docling
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def inference(pdf_path, page_num):
|
| 24 |
docling_ocr = get_docling_ocr(pdf_path, page_num)
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
title = "OCR Arena"
|
| 28 |
description = "A simple Gradio interface to extract text from PDFs and compare OCR models"
|
|
@@ -46,10 +66,11 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
|
| 46 |
clear_btn = gr.ClearButton(components=[pdf, page_num])
|
| 47 |
submit_btn = gr.Button("Submit", variant='primary')
|
| 48 |
|
| 49 |
-
submit_btn.click(inference, inputs=[pdf, page_num], outputs=docling_ocr_out)
|
| 50 |
|
| 51 |
with gr.Column():
|
| 52 |
docling_ocr_out = gr.Textbox(label="Docling OCR Output", type="text")
|
|
|
|
| 53 |
|
| 54 |
examples_obj = gr.Examples(examples=examples, inputs=[pdf])
|
| 55 |
|
|
|
|
| 3 |
from docling.document_converter import DocumentConverter, PdfFormatOption
|
| 4 |
from docling.datamodel.pipeline_options import PdfPipelineOptions
|
| 5 |
from docling.datamodel.base_models import InputFormat
|
| 6 |
+
from paddleocr import PPStructureV3
|
| 7 |
+
from pdf2image import convert_from_path
|
| 8 |
+
import numpy as np
|
| 9 |
|
| 10 |
pipeline_options = PdfPipelineOptions(enable_remote_services=True)
|
| 11 |
converter = DocumentConverter(
|
|
|
|
| 23 |
markdown_text_docling = result.document.export_to_markdown()
|
| 24 |
return markdown_text_docling
|
| 25 |
|
| 26 |
+
def get_paddle_ocr(page_image):
|
| 27 |
+
pipeline = PPStructureV3()
|
| 28 |
+
output = pipeline.predict(input=np.array(page_image))
|
| 29 |
+
|
| 30 |
+
markdown_list = []
|
| 31 |
+
|
| 32 |
+
for res in output:
|
| 33 |
+
md_info = res.markdown
|
| 34 |
+
markdown_list.append(md_info)
|
| 35 |
+
|
| 36 |
+
markdown_text_paddleOCR = pipeline.concatenate_markdown_pages(markdown_list)
|
| 37 |
+
return markdown_text_paddleOCR
|
| 38 |
+
|
| 39 |
def inference(pdf_path, page_num):
|
| 40 |
docling_ocr = get_docling_ocr(pdf_path, page_num)
|
| 41 |
+
# Extract the first page as an image
|
| 42 |
+
images = convert_from_path(pdf_path, first_page=page_num, last_page=page_num)
|
| 43 |
+
page_image = images[0]
|
| 44 |
+
paddle_ocr = get_paddle_ocr(page_image)
|
| 45 |
+
return docling_ocr, paddle_ocr
|
| 46 |
|
| 47 |
title = "OCR Arena"
|
| 48 |
description = "A simple Gradio interface to extract text from PDFs and compare OCR models"
|
|
|
|
| 66 |
clear_btn = gr.ClearButton(components=[pdf, page_num])
|
| 67 |
submit_btn = gr.Button("Submit", variant='primary')
|
| 68 |
|
| 69 |
+
submit_btn.click(inference, inputs=[pdf, page_num], outputs=[docling_ocr_out, paddle_ocr_out])
|
| 70 |
|
| 71 |
with gr.Column():
|
| 72 |
docling_ocr_out = gr.Textbox(label="Docling OCR Output", type="text")
|
| 73 |
+
paddle_ocr_out = gr.Textbox(label="Paddle OCR Output", type="text")
|
| 74 |
|
| 75 |
examples_obj = gr.Examples(examples=examples, inputs=[pdf])
|
| 76 |
|
requirements.txt
CHANGED
|
@@ -1,58 +1,103 @@
|
|
| 1 |
aiofiles==24.1.0
|
|
|
|
|
|
|
|
|
|
| 2 |
annotated-types==0.7.0
|
| 3 |
anyio==4.9.0
|
|
|
|
| 4 |
attrs==25.3.0
|
| 5 |
beautifulsoup4==4.13.4
|
|
|
|
| 6 |
certifi==2025.6.15
|
|
|
|
| 7 |
charset-normalizer==3.4.2
|
| 8 |
click==8.2.1
|
| 9 |
colorama==0.4.6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
dill==0.4.0
|
|
|
|
| 11 |
docling==2.39.0
|
| 12 |
docling-core==2.39.0
|
| 13 |
docling-ibm-models==3.6.0
|
| 14 |
docling-parse==4.1.0
|
| 15 |
easyocr==1.7.2
|
|
|
|
| 16 |
et_xmlfile==2.0.0
|
| 17 |
fastapi==0.115.14
|
| 18 |
ffmpy==0.6.0
|
| 19 |
filelock==3.18.0
|
| 20 |
filetype==1.2.0
|
|
|
|
| 21 |
fsspec==2025.5.1
|
|
|
|
|
|
|
| 22 |
gradio==5.35.0
|
| 23 |
gradio_client==1.10.4
|
|
|
|
| 24 |
groovy==0.1.2
|
| 25 |
h11==0.16.0
|
| 26 |
httpcore==1.0.9
|
| 27 |
httpx==0.28.1
|
|
|
|
| 28 |
huggingface-hub==0.33.1
|
| 29 |
idna==3.10
|
| 30 |
imageio==2.37.0
|
|
|
|
| 31 |
Jinja2==3.1.6
|
|
|
|
|
|
|
| 32 |
jsonlines==3.1.0
|
|
|
|
|
|
|
| 33 |
jsonref==1.1.0
|
| 34 |
jsonschema==4.24.0
|
| 35 |
jsonschema-specifications==2025.4.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
latex2mathml==3.78.0
|
| 37 |
lazy_loader==0.4
|
| 38 |
lxml==5.4.0
|
| 39 |
markdown-it-py==3.0.0
|
| 40 |
marko==2.1.4
|
| 41 |
MarkupSafe==3.0.2
|
|
|
|
| 42 |
mdurl==0.1.2
|
|
|
|
| 43 |
mpire==2.10.2
|
| 44 |
mpmath==1.3.0
|
|
|
|
| 45 |
multiprocess==0.70.18
|
| 46 |
-
|
|
|
|
| 47 |
ninja==1.11.1.4
|
| 48 |
numpy==2.2.6
|
|
|
|
|
|
|
| 49 |
opencv-python-headless==4.11.0.86
|
| 50 |
openpyxl==3.1.5
|
|
|
|
| 51 |
orjson==3.10.18
|
| 52 |
-
packaging==
|
|
|
|
|
|
|
|
|
|
| 53 |
pandas==2.3.0
|
|
|
|
| 54 |
pillow==11.2.1
|
| 55 |
pluggy==1.6.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
pyclipper==1.3.0.post6
|
| 57 |
pydantic==2.11.7
|
| 58 |
pydantic-settings==2.10.1
|
|
@@ -73,13 +118,17 @@ PyYAML==6.0.2
|
|
| 73 |
referencing==0.36.2
|
| 74 |
regex==2024.11.6
|
| 75 |
requests==2.32.4
|
|
|
|
| 76 |
rich==14.0.0
|
| 77 |
rpds-py==0.25.1
|
| 78 |
rtree==1.4.0
|
|
|
|
|
|
|
| 79 |
ruff==0.12.1
|
| 80 |
safehttpx==0.1.6
|
| 81 |
safetensors==0.5.3
|
| 82 |
scikit-image==0.25.2
|
|
|
|
| 83 |
scipy==1.15.3
|
| 84 |
semantic-version==2.10.0
|
| 85 |
semchunk==2.2.2
|
|
@@ -89,10 +138,14 @@ shellingham==1.5.4
|
|
| 89 |
six==1.17.0
|
| 90 |
sniffio==1.3.1
|
| 91 |
soupsieve==2.7
|
|
|
|
| 92 |
starlette==0.46.2
|
| 93 |
sympy==1.14.0
|
| 94 |
tabulate==0.9.0
|
|
|
|
|
|
|
| 95 |
tifffile==2025.5.10
|
|
|
|
| 96 |
tokenizers==0.21.2
|
| 97 |
tomlkit==0.13.3
|
| 98 |
torch==2.7.1
|
|
@@ -100,10 +153,15 @@ torchvision==0.22.1
|
|
| 100 |
tqdm==4.67.1
|
| 101 |
transformers==4.53.0
|
| 102 |
typer==0.16.0
|
|
|
|
| 103 |
typing-inspection==0.4.1
|
| 104 |
typing_extensions==4.14.0
|
| 105 |
tzdata==2025.2
|
|
|
|
| 106 |
urllib3==2.5.0
|
| 107 |
uvicorn==0.34.3
|
|
|
|
| 108 |
websockets==15.0.1
|
| 109 |
xlsxwriter==3.2.5
|
|
|
|
|
|
|
|
|
| 1 |
aiofiles==24.1.0
|
| 2 |
+
aiohappyeyeballs==2.6.1
|
| 3 |
+
aiohttp==3.12.13
|
| 4 |
+
aiosignal==1.3.2
|
| 5 |
annotated-types==0.7.0
|
| 6 |
anyio==4.9.0
|
| 7 |
+
astor==0.8.1
|
| 8 |
attrs==25.3.0
|
| 9 |
beautifulsoup4==4.13.4
|
| 10 |
+
cachetools==6.1.0
|
| 11 |
certifi==2025.6.15
|
| 12 |
+
chardet==5.2.0
|
| 13 |
charset-normalizer==3.4.2
|
| 14 |
click==8.2.1
|
| 15 |
colorama==0.4.6
|
| 16 |
+
colorlog==6.9.0
|
| 17 |
+
cssselect==1.3.0
|
| 18 |
+
cssutils==2.11.1
|
| 19 |
+
dataclasses-json==0.6.7
|
| 20 |
+
decorator==5.2.1
|
| 21 |
dill==0.4.0
|
| 22 |
+
distro==1.9.0
|
| 23 |
docling==2.39.0
|
| 24 |
docling-core==2.39.0
|
| 25 |
docling-ibm-models==3.6.0
|
| 26 |
docling-parse==4.1.0
|
| 27 |
easyocr==1.7.2
|
| 28 |
+
einops==0.8.1
|
| 29 |
et_xmlfile==2.0.0
|
| 30 |
fastapi==0.115.14
|
| 31 |
ffmpy==0.6.0
|
| 32 |
filelock==3.18.0
|
| 33 |
filetype==1.2.0
|
| 34 |
+
frozenlist==1.7.0
|
| 35 |
fsspec==2025.5.1
|
| 36 |
+
ftfy==6.3.1
|
| 37 |
+
GPUtil==1.4.0
|
| 38 |
gradio==5.35.0
|
| 39 |
gradio_client==1.10.4
|
| 40 |
+
greenlet==3.2.3
|
| 41 |
groovy==0.1.2
|
| 42 |
h11==0.16.0
|
| 43 |
httpcore==1.0.9
|
| 44 |
httpx==0.28.1
|
| 45 |
+
httpx-sse==0.4.1
|
| 46 |
huggingface-hub==0.33.1
|
| 47 |
idna==3.10
|
| 48 |
imageio==2.37.0
|
| 49 |
+
imagesize==1.4.1
|
| 50 |
Jinja2==3.1.6
|
| 51 |
+
jiter==0.10.0
|
| 52 |
+
joblib==1.5.1
|
| 53 |
jsonlines==3.1.0
|
| 54 |
+
jsonpatch==1.33
|
| 55 |
+
jsonpointer==3.0.0
|
| 56 |
jsonref==1.1.0
|
| 57 |
jsonschema==4.24.0
|
| 58 |
jsonschema-specifications==2025.4.1
|
| 59 |
+
langchain==0.3.26
|
| 60 |
+
langchain-community==0.3.26
|
| 61 |
+
langchain-core==0.3.66
|
| 62 |
+
langchain-openai==0.3.27
|
| 63 |
+
langchain-text-splitters==0.3.8
|
| 64 |
+
langsmith==0.4.4
|
| 65 |
latex2mathml==3.78.0
|
| 66 |
lazy_loader==0.4
|
| 67 |
lxml==5.4.0
|
| 68 |
markdown-it-py==3.0.0
|
| 69 |
marko==2.1.4
|
| 70 |
MarkupSafe==3.0.2
|
| 71 |
+
marshmallow==3.26.1
|
| 72 |
mdurl==0.1.2
|
| 73 |
+
more-itertools==10.7.0
|
| 74 |
mpire==2.10.2
|
| 75 |
mpmath==1.3.0
|
| 76 |
+
multidict==6.6.0
|
| 77 |
multiprocess==0.70.18
|
| 78 |
+
mypy_extensions==1.1.0
|
| 79 |
+
networkx==3.5
|
| 80 |
ninja==1.11.1.4
|
| 81 |
numpy==2.2.6
|
| 82 |
+
openai==1.93.0
|
| 83 |
+
opencv-contrib-python==4.10.0.84
|
| 84 |
opencv-python-headless==4.11.0.86
|
| 85 |
openpyxl==3.1.5
|
| 86 |
+
opt-einsum==3.3.0
|
| 87 |
orjson==3.10.18
|
| 88 |
+
packaging==24.2
|
| 89 |
+
paddleocr==3.0.3
|
| 90 |
+
paddlepaddle==3.0.0
|
| 91 |
+
paddlex==3.0.3
|
| 92 |
pandas==2.3.0
|
| 93 |
+
pdf2image==1.17.0
|
| 94 |
pillow==11.2.1
|
| 95 |
pluggy==1.6.0
|
| 96 |
+
premailer==3.10.0
|
| 97 |
+
prettytable==3.16.0
|
| 98 |
+
propcache==0.3.2
|
| 99 |
+
protobuf==6.31.1
|
| 100 |
+
py-cpuinfo==9.0.0
|
| 101 |
pyclipper==1.3.0.post6
|
| 102 |
pydantic==2.11.7
|
| 103 |
pydantic-settings==2.10.1
|
|
|
|
| 118 |
referencing==0.36.2
|
| 119 |
regex==2024.11.6
|
| 120 |
requests==2.32.4
|
| 121 |
+
requests-toolbelt==1.0.0
|
| 122 |
rich==14.0.0
|
| 123 |
rpds-py==0.25.1
|
| 124 |
rtree==1.4.0
|
| 125 |
+
ruamel.yaml==0.18.14
|
| 126 |
+
ruamel.yaml.clib==0.2.12
|
| 127 |
ruff==0.12.1
|
| 128 |
safehttpx==0.1.6
|
| 129 |
safetensors==0.5.3
|
| 130 |
scikit-image==0.25.2
|
| 131 |
+
scikit-learn==1.7.0
|
| 132 |
scipy==1.15.3
|
| 133 |
semantic-version==2.10.0
|
| 134 |
semchunk==2.2.2
|
|
|
|
| 138 |
six==1.17.0
|
| 139 |
sniffio==1.3.1
|
| 140 |
soupsieve==2.7
|
| 141 |
+
SQLAlchemy==2.0.41
|
| 142 |
starlette==0.46.2
|
| 143 |
sympy==1.14.0
|
| 144 |
tabulate==0.9.0
|
| 145 |
+
tenacity==9.1.2
|
| 146 |
+
threadpoolctl==3.6.0
|
| 147 |
tifffile==2025.5.10
|
| 148 |
+
tiktoken==0.9.0
|
| 149 |
tokenizers==0.21.2
|
| 150 |
tomlkit==0.13.3
|
| 151 |
torch==2.7.1
|
|
|
|
| 153 |
tqdm==4.67.1
|
| 154 |
transformers==4.53.0
|
| 155 |
typer==0.16.0
|
| 156 |
+
typing-inspect==0.9.0
|
| 157 |
typing-inspection==0.4.1
|
| 158 |
typing_extensions==4.14.0
|
| 159 |
tzdata==2025.2
|
| 160 |
+
ujson==5.10.0
|
| 161 |
urllib3==2.5.0
|
| 162 |
uvicorn==0.34.3
|
| 163 |
+
wcwidth==0.2.13
|
| 164 |
websockets==15.0.1
|
| 165 |
xlsxwriter==3.2.5
|
| 166 |
+
yarl==1.20.1
|
| 167 |
+
zstandard==0.23.0
|