docling-ocr-onnxtr 0.1.2__py3-none-any.whl → 0.2.0__py3-none-any.whl

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.
@@ -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
@@ -195,7 +197,7 @@ class OnnxtrOcrModel(BaseOcrModel):
195
197
  )
196
198
 
197
199
  # Post-process the cells
198
- page.cells = self.post_process_cells(all_ocr_cells, page.cells)
200
+ self.post_process_cells(all_ocr_cells, page)
199
201
 
200
202
  # DEBUG code:
201
203
  if settings.debug.visualize_ocr:
@@ -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 +1 @@
1
- __version__ = 'v0.1.2'
1
+ __version__ = 'v0.2.0'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docling-ocr-onnxtr
3
- Version: 0.1.2
3
+ Version: 0.2.0
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
@@ -262,11 +262,11 @@ Dynamic: license-file
262
262
  </p>
263
263
 
264
264
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
265
- [![Test Status](https://github.com/felixdittrich92/docling-OCR-OnnxTR/actions/workflows/main.yml/badge.svg)](https://github.com/felixdittrich92/docling-OCR-OnnxTR/actions/workflows/main.yml)
265
+ [![Build Status](https://github.com/felixdittrich92/docling-OCR-OnnxTR/actions/workflows/builds.yml/badge.svg)](https://github.com/felixdittrich92/docling-OCR-OnnxTR/actions/workflows/builds.yml)
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.2-blue.svg)](https://pypi.org/project//)
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.
@@ -289,19 +289,19 @@ For GPU support please take a look at: [ONNX Runtime](https://onnxruntime.ai/get
289
289
 
290
290
  ```bash
291
291
  # For CPU
292
- pip install docling-ocr-onnxtr[cpu]
292
+ pip install "docling-ocr-onnxtr[cpu]"
293
293
  # For Nvidia GPU
294
- pip install docling-ocr-onnxtr[gpu]
294
+ pip install "docling-ocr-onnxtr[gpu]"
295
295
  # For Intel GPU / Integrated Graphics
296
- pip install docling-ocr-onnxtr[openvino]
296
+ pip install "docling-ocr-onnxtr[openvino]"
297
297
 
298
298
  # Headless mode (no GUI)
299
299
  # For CPU
300
- pip install docling-ocr-onnxtr[cpu-headless]
300
+ pip install "docling-ocr-onnxtr[cpu-headless]"
301
301
  # For Nvidia GPU
302
- pip install docling-ocr-onnxtr[gpu-headless]
302
+ pip install "docling-ocr-onnxtr[gpu-headless]"
303
303
  # For Intel GPU / Integrated Graphics
304
- pip install docling-ocr-onnxtr[openvino-headless]
304
+ pip install "docling-ocr-onnxtr[openvino-headless]"
305
305
  ```
306
306
 
307
307
  By integrating OnnxTR with Docling, users can achieve more efficient and accurate OCR results, enhancing the overall document processing experience.
@@ -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
  ```
@@ -0,0 +1,13 @@
1
+ docling_ocr_onnxtr/__init__.py,sha256=w8M8ctJDcDcxxrRJ_GT-G7JP3H7E1O50AuoK4l2djf0,85
2
+ docling_ocr_onnxtr/onnxtr_model.py,sha256=4CWDtT2B4PVxEb01glcgmiTGd6bNj5ig0tvTK4UmXCk,8628
3
+ docling_ocr_onnxtr/options.py,sha256=TBzwwDFmmkdhoXmmImKrV3tSEGX2FD8wtey5Mh1Z3EY,1299
4
+ docling_ocr_onnxtr/plugin.py,sha256=qtPPjpsiXyExvK7Vu8ssZhqxDV2gqFTHIIBBv1qz1lA,317
5
+ docling_ocr_onnxtr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ docling_ocr_onnxtr/version.py,sha256=F-dLDdnsmwBrwqQCEb3nX0LORU_q1xg9pmFGVU_3j8o,23
7
+ docling_ocr_onnxtr-0.2.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ docling_ocr_onnxtr-0.2.0.dist-info/METADATA,sha256=58vZ_WCZUCZ0k6fLC2X7_WAxhjxgyMKCXgwIq9Nq-0I,23822
9
+ docling_ocr_onnxtr-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ docling_ocr_onnxtr-0.2.0.dist-info/entry_points.txt,sha256=4bUh15gjHVjgG1_vEtZgZ0Kyo7ygkWeAugc_W-EtSfo,57
11
+ docling_ocr_onnxtr-0.2.0.dist-info/top_level.txt,sha256=vmOD5JYg8FKSI-iXyYH73_9AwJdxPOP1TsSY1nDp5iE,24
12
+ docling_ocr_onnxtr-0.2.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
13
+ docling_ocr_onnxtr-0.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,13 +0,0 @@
1
- docling_ocr_onnxtr/__init__.py,sha256=w8M8ctJDcDcxxrRJ_GT-G7JP3H7E1O50AuoK4l2djf0,85
2
- docling_ocr_onnxtr/onnxtr_model.py,sha256=FEEyFbRttBh4ckz5QgfT_n5zgtmfCNLr_bLhoobnl68,8490
3
- docling_ocr_onnxtr/options.py,sha256=gOzKHo86zwAVI_5-YxOr4NaRkNFwlv1RXeag7ZKWxtM,1266
4
- docling_ocr_onnxtr/plugin.py,sha256=qtPPjpsiXyExvK7Vu8ssZhqxDV2gqFTHIIBBv1qz1lA,317
5
- docling_ocr_onnxtr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- docling_ocr_onnxtr/version.py,sha256=t2ZLy6eqIRREzP9MNv-0UaNqpTXYFxlbMzz0JwDxS9I,23
7
- docling_ocr_onnxtr-0.1.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- docling_ocr_onnxtr-0.1.2.dist-info/METADATA,sha256=2uPk15A60jvJM8tXk5mOpKTdeyZi5jh6QcLFl1F1P98,22059
9
- docling_ocr_onnxtr-0.1.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
10
- docling_ocr_onnxtr-0.1.2.dist-info/entry_points.txt,sha256=4bUh15gjHVjgG1_vEtZgZ0Kyo7ygkWeAugc_W-EtSfo,57
11
- docling_ocr_onnxtr-0.1.2.dist-info/top_level.txt,sha256=vmOD5JYg8FKSI-iXyYH73_9AwJdxPOP1TsSY1nDp5iE,24
12
- docling_ocr_onnxtr-0.1.2.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
13
- docling_ocr_onnxtr-0.1.2.dist-info/RECORD,,