docling-ocr-onnxtr 0.1.3__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/PKG-INFO +58 -2
  2. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/README.md +57 -1
  3. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr/onnxtr_model.py +6 -4
  4. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr/options.py +4 -4
  5. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr/plugin.py +1 -1
  6. docling_ocr_onnxtr-0.2.1/docling_ocr_onnxtr/version.py +1 -0
  7. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr.egg-info/PKG-INFO +58 -2
  8. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/setup.py +2 -2
  9. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/tests/test_plugin.py +3 -10
  10. docling_ocr_onnxtr-0.1.3/docling_ocr_onnxtr/version.py +0 -1
  11. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/LICENSE +0 -0
  12. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr/__init__.py +0 -0
  13. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr/py.typed +0 -0
  14. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr.egg-info/SOURCES.txt +0 -0
  15. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr.egg-info/dependency_links.txt +0 -0
  16. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr.egg-info/entry_points.txt +0 -0
  17. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr.egg-info/requires.txt +0 -0
  18. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr.egg-info/top_level.txt +0 -0
  19. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/docling_ocr_onnxtr.egg-info/zip-safe +0 -0
  20. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/pyproject.toml +0 -0
  21. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/setup.cfg +0 -0
  22. {docling_ocr_onnxtr-0.1.3 → docling_ocr_onnxtr-0.2.1}/tests/test_pipeline_invalid_cases.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docling-ocr-onnxtr
3
- Version: 0.1.3
3
+ Version: 0.2.1
4
4
  Summary: Onnx Text Recognition (OnnxTR) OCR plugin for docling
5
5
  Author-email: Felix Dittrich <felixdittrich92@gmail.com>
6
6
  Maintainer: Felix Dittrich
@@ -266,7 +266,7 @@ Dynamic: license-file
266
266
  [![codecov](https://codecov.io/gh/felixdittrich92/docling-OCR-OnnxTR/graph/badge.svg?token=L3AHXKV86A)](https://codecov.io/gh/felixdittrich92/docling-OCR-OnnxTR)
267
267
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/0d250447650240ee9ca573950fea8b99)](https://app.codacy.com/gh/felixdittrich92/docling-OCR-OnnxTR/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
268
268
  [![CodeFactor](https://www.codefactor.io/repository/github/felixdittrich92/docling-ocr-onnxtr/badge)](https://www.codefactor.io/repository/github/felixdittrich92/docling-ocr-onnxtr)
269
- [![Pypi](https://img.shields.io/badge/pypi-v0.1.3-blue.svg)](https://pypi.org/project/docling-ocr-onnxtr/)
269
+ [![Pypi](https://img.shields.io/badge/pypi-v0.2.0-blue.svg)](https://pypi.org/project/docling-ocr-onnxtr/)
270
270
  ![PyPI - Downloads](https://img.shields.io/pypi/dm/docling-ocr-onnxtr)
271
271
 
272
272
  The `docling-OCR-OnnxTR` repository provides a plugin that integrates the [OnnxTR OCR engine](https://github.com/felixdittrich92/OnnxTR) into the [Docling framework](https://github.com/docling-project/docling), enhancing document processing capabilities with efficient and accurate text recognition.
@@ -358,6 +358,62 @@ def main():
358
358
  print(md)
359
359
 
360
360
 
361
+ if __name__ == "__main__":
362
+ main()
363
+ ```
364
+
365
+ It is also possible to load the models from local files instead of using the Hugging Face Hub or downloading them from the repo:
366
+
367
+ ```python
368
+ from docling.datamodel.pipeline_options import PdfPipelineOptions
369
+ from docling.document_converter import (
370
+ ConversionResult,
371
+ DocumentConverter,
372
+ InputFormat,
373
+ PdfFormatOption,
374
+ )
375
+ from docling_ocr_onnxtr import OnnxtrOcrOptions
376
+ from onnxtr.models import db_mobilenet_v3_large, parseq
377
+
378
+
379
+ def main():
380
+ # Source document to convert
381
+ source = "https://arxiv.org/pdf/2408.09869v4"
382
+
383
+ # Load models from local files
384
+ # NOTE: You need to download the models first and then adjust the paths accordingly.
385
+ det_model = db_mobilenet_v3_large("/home/felix/.cache/onnxtr/models/db_mobilenet_v3_large-1866973f.onnx")
386
+ reco_model = parseq("/home/felix/.cache/onnxtr/models/parseq-00b40714.onnx")
387
+
388
+ ocr_options = OnnxtrOcrOptions(
389
+ # Text detection model
390
+ det_arch=det_model,
391
+ # Text recognition model
392
+ reco_arch=reco_model,
393
+ # This can be set to `True` to auto-correct the orientation of the pages
394
+ auto_correct_orientation=False,
395
+ )
396
+
397
+ pipeline_options = PdfPipelineOptions(
398
+ ocr_options=ocr_options,
399
+ )
400
+ pipeline_options.allow_external_plugins = True # <-- enabled the external plugins
401
+
402
+ # Convert the document
403
+ converter = DocumentConverter(
404
+ format_options={
405
+ InputFormat.PDF: PdfFormatOption(
406
+ pipeline_options=pipeline_options,
407
+ ),
408
+ },
409
+ )
410
+
411
+ conversion_result: ConversionResult = converter.convert(source=source)
412
+ doc = conversion_result.document
413
+ md = doc.export_to_markdown()
414
+ print(md)
415
+
416
+
361
417
  if __name__ == "__main__":
362
418
  main()
363
419
  ```
@@ -7,7 +7,7 @@
7
7
  [![codecov](https://codecov.io/gh/felixdittrich92/docling-OCR-OnnxTR/graph/badge.svg?token=L3AHXKV86A)](https://codecov.io/gh/felixdittrich92/docling-OCR-OnnxTR)
8
8
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/0d250447650240ee9ca573950fea8b99)](https://app.codacy.com/gh/felixdittrich92/docling-OCR-OnnxTR/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
9
9
  [![CodeFactor](https://www.codefactor.io/repository/github/felixdittrich92/docling-ocr-onnxtr/badge)](https://www.codefactor.io/repository/github/felixdittrich92/docling-ocr-onnxtr)
10
- [![Pypi](https://img.shields.io/badge/pypi-v0.1.3-blue.svg)](https://pypi.org/project/docling-ocr-onnxtr/)
10
+ [![Pypi](https://img.shields.io/badge/pypi-v0.2.0-blue.svg)](https://pypi.org/project/docling-ocr-onnxtr/)
11
11
  ![PyPI - Downloads](https://img.shields.io/pypi/dm/docling-ocr-onnxtr)
12
12
 
13
13
  The `docling-OCR-OnnxTR` repository provides a plugin that integrates the [OnnxTR OCR engine](https://github.com/felixdittrich92/OnnxTR) into the [Docling framework](https://github.com/docling-project/docling), enhancing document processing capabilities with efficient and accurate text recognition.
@@ -99,6 +99,62 @@ def main():
99
99
  print(md)
100
100
 
101
101
 
102
+ if __name__ == "__main__":
103
+ main()
104
+ ```
105
+
106
+ It is also possible to load the models from local files instead of using the Hugging Face Hub or downloading them from the repo:
107
+
108
+ ```python
109
+ from docling.datamodel.pipeline_options import PdfPipelineOptions
110
+ from docling.document_converter import (
111
+ ConversionResult,
112
+ DocumentConverter,
113
+ InputFormat,
114
+ PdfFormatOption,
115
+ )
116
+ from docling_ocr_onnxtr import OnnxtrOcrOptions
117
+ from onnxtr.models import db_mobilenet_v3_large, parseq
118
+
119
+
120
+ def main():
121
+ # Source document to convert
122
+ source = "https://arxiv.org/pdf/2408.09869v4"
123
+
124
+ # Load models from local files
125
+ # NOTE: You need to download the models first and then adjust the paths accordingly.
126
+ det_model = db_mobilenet_v3_large("/home/felix/.cache/onnxtr/models/db_mobilenet_v3_large-1866973f.onnx")
127
+ reco_model = parseq("/home/felix/.cache/onnxtr/models/parseq-00b40714.onnx")
128
+
129
+ ocr_options = OnnxtrOcrOptions(
130
+ # Text detection model
131
+ det_arch=det_model,
132
+ # Text recognition model
133
+ reco_arch=reco_model,
134
+ # This can be set to `True` to auto-correct the orientation of the pages
135
+ auto_correct_orientation=False,
136
+ )
137
+
138
+ pipeline_options = PdfPipelineOptions(
139
+ ocr_options=ocr_options,
140
+ )
141
+ pipeline_options.allow_external_plugins = True # <-- enabled the external plugins
142
+
143
+ # Convert the document
144
+ converter = DocumentConverter(
145
+ format_options={
146
+ InputFormat.PDF: PdfFormatOption(
147
+ pipeline_options=pipeline_options,
148
+ ),
149
+ },
150
+ )
151
+
152
+ conversion_result: ConversionResult = converter.convert(source=source)
153
+ doc = conversion_result.document
154
+ md = doc.export_to_markdown()
155
+ print(md)
156
+
157
+
102
158
  if __name__ == "__main__":
103
159
  main()
104
160
  ```
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2021-2025, Felix Dittrich.
1
+ # Copyright (C) 2021-2026, Felix Dittrich.
2
2
 
3
3
  # This program is licensed under the Apache License 2.0.
4
4
  # See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
@@ -12,7 +12,7 @@ import numpy
12
12
  import numpy as np
13
13
  from docling.datamodel.base_models import Page
14
14
  from docling.datamodel.document import ConversionResult
15
- from docling.datamodel.pipeline_options import (
15
+ from docling.datamodel.pipeline_options import ( # type: ignore[attr-defined]
16
16
  AcceleratorOptions,
17
17
  OcrOptions,
18
18
  )
@@ -91,11 +91,13 @@ class OnnxtrOcrModel(BaseOcrModel):
91
91
 
92
92
  self.reader = ocr_predictor(
93
93
  det_arch=(
94
- from_hub(self.options.det_arch) if self.options.det_arch.count("/") == 1 else self.options.det_arch
94
+ from_hub(self.options.det_arch)
95
+ if isinstance(self.options.det_arch, str) and self.options.det_arch.count("/") == 1
96
+ else self.options.det_arch
95
97
  ),
96
98
  reco_arch=(
97
99
  from_hub(self.options.reco_arch)
98
- if self.options.reco_arch.count("/") == 1
100
+ if isinstance(self.options.reco_arch, str) and self.options.reco_arch.count("/") == 1
99
101
  else self.options.reco_arch
100
102
  ),
101
103
  det_bs=1, # NOTE: Should be always 1, because docling handles batching
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2021-2025, Felix Dittrich.
1
+ # Copyright (C) 2021-2026, Felix Dittrich.
2
2
 
3
3
  # This program is licensed under the Apache License 2.0.
4
4
  # See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
@@ -22,9 +22,9 @@ class OnnxtrOcrOptions(OcrOptions):
22
22
  # detection model objectness score threshold 'fast algorithm'
23
23
  objectness_score: float = 0.3
24
24
 
25
- # NOTE: This can be also a hf hub model
26
- det_arch: str = "fast_base"
27
- reco_arch: str = "crnn_vgg16_bn"
25
+ # NOTE: This can be also a hf hub model or an instance of a model class.
26
+ det_arch: Any = "fast_base"
27
+ reco_arch: Any = "crnn_vgg16_bn"
28
28
  reco_bs: int = 512
29
29
  auto_correct_orientation: bool = False
30
30
  preserve_aspect_ratio: bool = True
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2021-2025, Felix Dittrich.
1
+ # Copyright (C) 2021-2026, Felix Dittrich.
2
2
 
3
3
  # This program is licensed under the Apache License 2.0.
4
4
  # See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
@@ -0,0 +1 @@
1
+ __version__ = 'v0.2.1'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docling-ocr-onnxtr
3
- Version: 0.1.3
3
+ Version: 0.2.1
4
4
  Summary: Onnx Text Recognition (OnnxTR) OCR plugin for docling
5
5
  Author-email: Felix Dittrich <felixdittrich92@gmail.com>
6
6
  Maintainer: Felix Dittrich
@@ -266,7 +266,7 @@ Dynamic: license-file
266
266
  [![codecov](https://codecov.io/gh/felixdittrich92/docling-OCR-OnnxTR/graph/badge.svg?token=L3AHXKV86A)](https://codecov.io/gh/felixdittrich92/docling-OCR-OnnxTR)
267
267
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/0d250447650240ee9ca573950fea8b99)](https://app.codacy.com/gh/felixdittrich92/docling-OCR-OnnxTR/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
268
268
  [![CodeFactor](https://www.codefactor.io/repository/github/felixdittrich92/docling-ocr-onnxtr/badge)](https://www.codefactor.io/repository/github/felixdittrich92/docling-ocr-onnxtr)
269
- [![Pypi](https://img.shields.io/badge/pypi-v0.1.3-blue.svg)](https://pypi.org/project/docling-ocr-onnxtr/)
269
+ [![Pypi](https://img.shields.io/badge/pypi-v0.2.0-blue.svg)](https://pypi.org/project/docling-ocr-onnxtr/)
270
270
  ![PyPI - Downloads](https://img.shields.io/pypi/dm/docling-ocr-onnxtr)
271
271
 
272
272
  The `docling-OCR-OnnxTR` repository provides a plugin that integrates the [OnnxTR OCR engine](https://github.com/felixdittrich92/OnnxTR) into the [Docling framework](https://github.com/docling-project/docling), enhancing document processing capabilities with efficient and accurate text recognition.
@@ -358,6 +358,62 @@ def main():
358
358
  print(md)
359
359
 
360
360
 
361
+ if __name__ == "__main__":
362
+ main()
363
+ ```
364
+
365
+ It is also possible to load the models from local files instead of using the Hugging Face Hub or downloading them from the repo:
366
+
367
+ ```python
368
+ from docling.datamodel.pipeline_options import PdfPipelineOptions
369
+ from docling.document_converter import (
370
+ ConversionResult,
371
+ DocumentConverter,
372
+ InputFormat,
373
+ PdfFormatOption,
374
+ )
375
+ from docling_ocr_onnxtr import OnnxtrOcrOptions
376
+ from onnxtr.models import db_mobilenet_v3_large, parseq
377
+
378
+
379
+ def main():
380
+ # Source document to convert
381
+ source = "https://arxiv.org/pdf/2408.09869v4"
382
+
383
+ # Load models from local files
384
+ # NOTE: You need to download the models first and then adjust the paths accordingly.
385
+ det_model = db_mobilenet_v3_large("/home/felix/.cache/onnxtr/models/db_mobilenet_v3_large-1866973f.onnx")
386
+ reco_model = parseq("/home/felix/.cache/onnxtr/models/parseq-00b40714.onnx")
387
+
388
+ ocr_options = OnnxtrOcrOptions(
389
+ # Text detection model
390
+ det_arch=det_model,
391
+ # Text recognition model
392
+ reco_arch=reco_model,
393
+ # This can be set to `True` to auto-correct the orientation of the pages
394
+ auto_correct_orientation=False,
395
+ )
396
+
397
+ pipeline_options = PdfPipelineOptions(
398
+ ocr_options=ocr_options,
399
+ )
400
+ pipeline_options.allow_external_plugins = True # <-- enabled the external plugins
401
+
402
+ # Convert the document
403
+ converter = DocumentConverter(
404
+ format_options={
405
+ InputFormat.PDF: PdfFormatOption(
406
+ pipeline_options=pipeline_options,
407
+ ),
408
+ },
409
+ )
410
+
411
+ conversion_result: ConversionResult = converter.convert(source=source)
412
+ doc = conversion_result.document
413
+ md = doc.export_to_markdown()
414
+ print(md)
415
+
416
+
361
417
  if __name__ == "__main__":
362
418
  main()
363
419
  ```
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2021-2025, Felix Dittrich.
1
+ # Copyright (C) 2021-2026, Felix Dittrich.
2
2
 
3
3
  # This program is licensed under the Apache License 2.0.
4
4
  # See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
@@ -9,7 +9,7 @@ from pathlib import Path
9
9
  from setuptools import setup
10
10
 
11
11
  PKG_NAME = "docling_ocr_onnxtr"
12
- VERSION = os.getenv("BUILD_VERSION", "0.1.3a0")
12
+ VERSION = os.getenv("BUILD_VERSION", "0.2.1a0")
13
13
 
14
14
 
15
15
  if __name__ == "__main__":
@@ -15,9 +15,8 @@ from docling.document_converter import DocumentConverter, PdfFormatOption
15
15
  from docling_ocr_onnxtr import OnnxtrOcrOptions
16
16
 
17
17
  from .test_data_gen_flag import GEN_TEST_DATA
18
- from .verify_utils import verify_conversion_result_v1, verify_conversion_result_v2
18
+ from .verify_utils import verify_conversion_result_v2
19
19
 
20
- GENERATE_V1 = GEN_TEST_DATA
21
20
  GENERATE_V2 = GEN_TEST_DATA
22
21
 
23
22
 
@@ -73,7 +72,7 @@ def test_e2e_conversions(ocr_options: OcrOptions):
73
72
  print(f"Converting with ocr_engine: {ocr_options.kind}, language: {ocr_options.lang}")
74
73
  converter = get_converter(ocr_options=ocr_options)
75
74
  for pdf_path in pdf_paths:
76
- if not ocr_options.auto_correct_orientation and "rotated" in pdf_path.name:
75
+ if not ocr_options.auto_correct_orientation and ("rotated" in pdf_path.name or "rotation" in pdf_path.name):
77
76
  # Skip rotated PDFs if orientation correction is disabled
78
77
  print(f"Skipping {pdf_path} due to orientation correction settings.")
79
78
  continue
@@ -82,12 +81,6 @@ def test_e2e_conversions(ocr_options: OcrOptions):
82
81
  doc_result: ConversionResult = converter.convert(pdf_path)
83
82
 
84
83
  try:
85
- verify_conversion_result_v1(
86
- input_path=pdf_path,
87
- doc_result=doc_result,
88
- generate=GENERATE_V1,
89
- fuzzy=True,
90
- )
91
84
  verify_conversion_result_v2(
92
85
  input_path=pdf_path,
93
86
  doc_result=doc_result,
@@ -95,7 +88,7 @@ def test_e2e_conversions(ocr_options: OcrOptions):
95
88
  fuzzy=True,
96
89
  )
97
90
  except AssertionError as e:
98
- if "rotated" in pdf_path.name:
91
+ if "rotated" in pdf_path.name or "rotation" in pdf_path.name or ocr_options.auto_correct_orientation:
99
92
  pytest.xfail(f"Skipping {pdf_path} due to orientation correction settings: {e}")
100
93
  else:
101
94
  raise # Unexpected failure — re-raise the error
@@ -1 +0,0 @@
1
- __version__ = 'v0.1.3'