docling 0.1.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.
- docling/__init__.py +0 -0
- docling/backend/__init__.py +0 -0
- docling/backend/abstract_backend.py +55 -0
- docling/backend/pypdfium2_backend.py +223 -0
- docling/datamodel/__init__.py +0 -0
- docling/datamodel/base_models.py +247 -0
- docling/datamodel/document.py +351 -0
- docling/datamodel/settings.py +32 -0
- docling/document_converter.py +207 -0
- docling/models/__init__.py +0 -0
- docling/models/ds_glm_model.py +82 -0
- docling/models/easyocr_model.py +77 -0
- docling/models/layout_model.py +318 -0
- docling/models/page_assemble_model.py +160 -0
- docling/models/table_structure_model.py +114 -0
- docling/pipeline/__init__.py +0 -0
- docling/pipeline/base_model_pipeline.py +18 -0
- docling/pipeline/standard_model_pipeline.py +40 -0
- docling/utils/__init__.py +0 -0
- docling/utils/layout_utils.py +806 -0
- docling/utils/utils.py +41 -0
- docling-0.1.0.dist-info/LICENSE +21 -0
- docling-0.1.0.dist-info/METADATA +130 -0
- docling-0.1.0.dist-info/RECORD +25 -0
- docling-0.1.0.dist-info/WHEEL +4 -0
docling/utils/utils.py
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
import hashlib
|
2
|
+
from io import BytesIO
|
3
|
+
from itertools import islice
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import List, Union
|
6
|
+
|
7
|
+
|
8
|
+
def chunkify(iterator, chunk_size):
|
9
|
+
"""Yield successive chunks of chunk_size from the iterable."""
|
10
|
+
if isinstance(iterator, List):
|
11
|
+
iterator = iter(iterator)
|
12
|
+
for first in iterator: # Take the first element from the iterator
|
13
|
+
yield [first] + list(islice(iterator, chunk_size - 1))
|
14
|
+
|
15
|
+
|
16
|
+
def create_file_hash(path_or_stream: Union[BytesIO, Path]) -> str:
|
17
|
+
"""Create a stable page_hash of the path_or_stream of a file"""
|
18
|
+
|
19
|
+
block_size = 65536
|
20
|
+
hasher = hashlib.sha256()
|
21
|
+
|
22
|
+
def _hash_buf(binary_stream):
|
23
|
+
buf = binary_stream.read(block_size) # read and page_hash in chunks
|
24
|
+
while len(buf) > 0:
|
25
|
+
hasher.update(buf)
|
26
|
+
buf = binary_stream.read(block_size)
|
27
|
+
|
28
|
+
if isinstance(path_or_stream, Path):
|
29
|
+
with path_or_stream.open("rb") as afile:
|
30
|
+
_hash_buf(afile)
|
31
|
+
elif isinstance(path_or_stream, BytesIO):
|
32
|
+
_hash_buf(path_or_stream)
|
33
|
+
|
34
|
+
return hasher.hexdigest()
|
35
|
+
|
36
|
+
|
37
|
+
def create_hash(string: str):
|
38
|
+
hasher = hashlib.sha256()
|
39
|
+
hasher.update(string.encode("utf-8"))
|
40
|
+
|
41
|
+
return hasher.hexdigest()
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) [year] [fullname]
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,130 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: docling
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Docling PDF conversion package
|
5
|
+
License: MIT
|
6
|
+
Keywords: docling,convert,document,pdf,layout model,segmentation,table structure,table former
|
7
|
+
Author: Christoph Auer
|
8
|
+
Author-email: cau@zurich.ibm.com
|
9
|
+
Requires-Python: >=3.11,<4.0
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
14
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
20
|
+
Requires-Dist: deepsearch-glm (>=0.18.4,<1)
|
21
|
+
Requires-Dist: deepsearch-toolkit (>=0.47.0,<1)
|
22
|
+
Requires-Dist: docling-core (>=0.2.0,<0.3.0)
|
23
|
+
Requires-Dist: docling-ibm-models (>=0.2.0,<0.3.0)
|
24
|
+
Requires-Dist: filetype (>=1.2.0,<2.0.0)
|
25
|
+
Requires-Dist: huggingface_hub (>=0.23,<1)
|
26
|
+
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
|
27
|
+
Requires-Dist: pydantic-settings (>=2.3.0,<3.0.0)
|
28
|
+
Requires-Dist: pypdfium2 (>=4.30.0,<5.0.0)
|
29
|
+
Description-Content-Type: text/markdown
|
30
|
+
|
31
|
+
<p align="center">
|
32
|
+
<a href="https://github.com/ds4sd/docling"> <img loading="lazy" alt="Docling" src="logo.png" width="150" /> </a>
|
33
|
+
</p>
|
34
|
+
|
35
|
+
# Docling
|
36
|
+
|
37
|
+
Dockling bundles PDF document conversion to JSON and Markdown in an easy, self-contained package.
|
38
|
+
|
39
|
+
## Features
|
40
|
+
* ⚡ Converts any PDF document to JSON or Markdown format, stable and lightning fast
|
41
|
+
* 📑 Understands detailed page layout, reading order and recovers table structures
|
42
|
+
* 📝 Extracts metadata from the document, such as title, authors, references and language
|
43
|
+
* 🔍 Optionally applies OCR (use with scanned PDFs)
|
44
|
+
|
45
|
+
## Setup
|
46
|
+
|
47
|
+
You need Python 3.11 and poetry. Install poetry from [here](https://python-poetry.org/docs/#installing-with-the-official-installer).
|
48
|
+
|
49
|
+
Once you have `poetry` installed, create an environment and install the package:
|
50
|
+
|
51
|
+
```bash
|
52
|
+
poetry env use $(which python3.11)
|
53
|
+
poetry shell
|
54
|
+
poetry install
|
55
|
+
```
|
56
|
+
|
57
|
+
**Notes**:
|
58
|
+
* Works on macOS and Linux environments. Windows platforms are currently not tested.
|
59
|
+
|
60
|
+
|
61
|
+
## Usage
|
62
|
+
|
63
|
+
For basic usage, see the [convert.py](examples/convert.py) example module. Run with:
|
64
|
+
|
65
|
+
```
|
66
|
+
python examples/convert.py
|
67
|
+
```
|
68
|
+
The output of the above command will be written to `./scratch`.
|
69
|
+
|
70
|
+
### Enable or disable pipeline features
|
71
|
+
|
72
|
+
You can control if table structure recognition or OCR should be performed by arguments passed to `DocumentConverter`
|
73
|
+
```python
|
74
|
+
doc_converter = DocumentConverter(
|
75
|
+
artifacts_path=artifacts_path,
|
76
|
+
pipeline_options=PipelineOptions(do_table_structure=False, # Controls if table structure is recovered.
|
77
|
+
do_ocr=True), # Controls if OCR is applied (ignores programmatic content)
|
78
|
+
)
|
79
|
+
```
|
80
|
+
|
81
|
+
### Impose limits on the document size
|
82
|
+
|
83
|
+
You can limit the file size and number of pages which should be allowed to process per document.
|
84
|
+
```python
|
85
|
+
paths = [Path("./test/data/2206.01062.pdf")]
|
86
|
+
|
87
|
+
input = DocumentConversionInput.from_paths(
|
88
|
+
paths, limits=DocumentLimits(max_num_pages=100, max_file_size=20971520)
|
89
|
+
)
|
90
|
+
```
|
91
|
+
|
92
|
+
### Convert from binary PDF streams
|
93
|
+
|
94
|
+
You can convert PDFs from a binary stream instead of from the filesystem as follows:
|
95
|
+
```python
|
96
|
+
buf = BytesIO(your_binary_stream)
|
97
|
+
docs = [DocumentStream(filename="my_doc.pdf", stream=buf)]
|
98
|
+
input = DocumentConversionInput.from_streams(docs)
|
99
|
+
converted_docs = doc_converter.convert(input)
|
100
|
+
```
|
101
|
+
### Limit resource usage
|
102
|
+
|
103
|
+
You can limit the CPU threads used by `docling` by setting the environment variable `OMP_NUM_THREADS` accordingly. The default setting is using 4 CPU threads.
|
104
|
+
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
Please read [Contributing to Docling](./CONTRIBUTING.md) for details.
|
109
|
+
|
110
|
+
|
111
|
+
## References
|
112
|
+
|
113
|
+
If you use `Docling` in your projects, please consider citing the following:
|
114
|
+
|
115
|
+
```bib
|
116
|
+
@software{Docling,
|
117
|
+
author = {Deep Search Team},
|
118
|
+
month = {7},
|
119
|
+
title = {{Docling}},
|
120
|
+
url = {https://github.com/DS4SD/docling},
|
121
|
+
version = {main},
|
122
|
+
year = {2024}
|
123
|
+
}
|
124
|
+
```
|
125
|
+
|
126
|
+
## License
|
127
|
+
|
128
|
+
The `Docling` codebase is under MIT license.
|
129
|
+
For individual model usage, please refer to the model licenses found in the original packages.
|
130
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
docling/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
docling/backend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
docling/backend/abstract_backend.py,sha256=dINr8oTax9Fq31Y1AR0CGWNZtAHN5aqB_M7TAPkJNVQ,1122
|
4
|
+
docling/backend/pypdfium2_backend.py,sha256=sJMoActFyc3qdKB6RFly3auHXuXM4noQAG0ypUlj26o,7647
|
5
|
+
docling/datamodel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
docling/datamodel/base_models.py,sha256=UUbimBhbRQSIM5pTsfQmSNi6NoNM5U03Vc0htHDkFZY,6132
|
7
|
+
docling/datamodel/document.py,sha256=JIp4TRl9NrVLXwNU-9llkbrFGUKly9B2pwzXaH0GEsE,12615
|
8
|
+
docling/datamodel/settings.py,sha256=t5g6wrEJnPa9gBzMMl8ppgBRUYz-8xgopEtfMS0ZH28,733
|
9
|
+
docling/document_converter.py,sha256=MZw23oPlRmRi1ggzoD1PukUnqo-6boO3RZB06dZ5Xt0,7305
|
10
|
+
docling/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
docling/models/ds_glm_model.py,sha256=wmb--2JKFQby-kvidw6PyM8wURPXYPQ_Z_eKKCBAdYQ,3192
|
12
|
+
docling/models/easyocr_model.py,sha256=NaHVs8IN0eW9KB076E2Kae1s-bq74_4IMWueze9QqtE,2290
|
13
|
+
docling/models/layout_model.py,sha256=4AfPFiu6pXc8wIQ1sQlEZnHRt7SnBmfzDdctiRveOWw,10944
|
14
|
+
docling/models/page_assemble_model.py,sha256=jhjQt0NOkVi-dWBaovJ2KsBim5FF6e47y21uZ8EWfBg,5906
|
15
|
+
docling/models/table_structure_model.py,sha256=uvkK2NPvltk9-zScbORUA05JbvymkGX6Dfsal4wLwsI,4103
|
16
|
+
docling/pipeline/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
docling/pipeline/base_model_pipeline.py,sha256=ozHdJak0yQAxQf7pQN_C480vI35A2e5KL5Qq1xSkq5c,560
|
18
|
+
docling/pipeline/standard_model_pipeline.py,sha256=pDbgVO0oOJry7Q-3KYdMuaypXCQOdoVikR80veizo9o,1489
|
19
|
+
docling/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
|
+
docling/utils/layout_utils.py,sha256=FOFbL0hKzUoWXdZaeUvEtFqKv0IkPifIr4sdGW4suKs,31804
|
21
|
+
docling/utils/utils.py,sha256=llhXSbIDNZ1MHOwBEfLHBAoJIAYI7QlPIonlI1jLUJ0,1208
|
22
|
+
docling-0.1.0.dist-info/LICENSE,sha256=ACwmltkrXIz5VsEQcrqljq-fat6ZXAMepjXGoe40KtE,1069
|
23
|
+
docling-0.1.0.dist-info/METADATA,sha256=TYMDWosLJnMmi8cDMck1L0uBiCwXtRBTeM6oBFAl8Ls,4228
|
24
|
+
docling-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
25
|
+
docling-0.1.0.dist-info/RECORD,,
|