docling 2.69.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.

Potentially problematic release.


This version of docling might be problematic. Click here for more details.

Files changed (138) hide show
  1. docling/__init__.py +0 -0
  2. docling/backend/__init__.py +0 -0
  3. docling/backend/abstract_backend.py +84 -0
  4. docling/backend/asciidoc_backend.py +443 -0
  5. docling/backend/csv_backend.py +125 -0
  6. docling/backend/docling_parse_backend.py +237 -0
  7. docling/backend/docling_parse_v2_backend.py +276 -0
  8. docling/backend/docling_parse_v4_backend.py +260 -0
  9. docling/backend/docx/__init__.py +0 -0
  10. docling/backend/docx/drawingml/utils.py +131 -0
  11. docling/backend/docx/latex/__init__.py +0 -0
  12. docling/backend/docx/latex/latex_dict.py +274 -0
  13. docling/backend/docx/latex/omml.py +459 -0
  14. docling/backend/html_backend.py +1502 -0
  15. docling/backend/image_backend.py +188 -0
  16. docling/backend/json/__init__.py +0 -0
  17. docling/backend/json/docling_json_backend.py +58 -0
  18. docling/backend/md_backend.py +618 -0
  19. docling/backend/mets_gbs_backend.py +399 -0
  20. docling/backend/msexcel_backend.py +686 -0
  21. docling/backend/mspowerpoint_backend.py +398 -0
  22. docling/backend/msword_backend.py +1663 -0
  23. docling/backend/noop_backend.py +51 -0
  24. docling/backend/pdf_backend.py +82 -0
  25. docling/backend/pypdfium2_backend.py +417 -0
  26. docling/backend/webvtt_backend.py +572 -0
  27. docling/backend/xml/__init__.py +0 -0
  28. docling/backend/xml/jats_backend.py +819 -0
  29. docling/backend/xml/uspto_backend.py +1905 -0
  30. docling/chunking/__init__.py +12 -0
  31. docling/cli/__init__.py +0 -0
  32. docling/cli/main.py +974 -0
  33. docling/cli/models.py +196 -0
  34. docling/cli/tools.py +17 -0
  35. docling/datamodel/__init__.py +0 -0
  36. docling/datamodel/accelerator_options.py +69 -0
  37. docling/datamodel/asr_model_specs.py +494 -0
  38. docling/datamodel/backend_options.py +102 -0
  39. docling/datamodel/base_models.py +493 -0
  40. docling/datamodel/document.py +699 -0
  41. docling/datamodel/extraction.py +39 -0
  42. docling/datamodel/layout_model_specs.py +91 -0
  43. docling/datamodel/pipeline_options.py +457 -0
  44. docling/datamodel/pipeline_options_asr_model.py +78 -0
  45. docling/datamodel/pipeline_options_vlm_model.py +136 -0
  46. docling/datamodel/settings.py +65 -0
  47. docling/datamodel/vlm_model_specs.py +365 -0
  48. docling/document_converter.py +559 -0
  49. docling/document_extractor.py +327 -0
  50. docling/exceptions.py +10 -0
  51. docling/experimental/__init__.py +5 -0
  52. docling/experimental/datamodel/__init__.py +1 -0
  53. docling/experimental/datamodel/table_crops_layout_options.py +13 -0
  54. docling/experimental/datamodel/threaded_layout_vlm_pipeline_options.py +45 -0
  55. docling/experimental/models/__init__.py +3 -0
  56. docling/experimental/models/table_crops_layout_model.py +114 -0
  57. docling/experimental/pipeline/__init__.py +1 -0
  58. docling/experimental/pipeline/threaded_layout_vlm_pipeline.py +439 -0
  59. docling/models/__init__.py +0 -0
  60. docling/models/base_layout_model.py +39 -0
  61. docling/models/base_model.py +230 -0
  62. docling/models/base_ocr_model.py +241 -0
  63. docling/models/base_table_model.py +45 -0
  64. docling/models/extraction/__init__.py +0 -0
  65. docling/models/extraction/nuextract_transformers_model.py +305 -0
  66. docling/models/factories/__init__.py +47 -0
  67. docling/models/factories/base_factory.py +122 -0
  68. docling/models/factories/layout_factory.py +7 -0
  69. docling/models/factories/ocr_factory.py +11 -0
  70. docling/models/factories/picture_description_factory.py +11 -0
  71. docling/models/factories/table_factory.py +7 -0
  72. docling/models/picture_description_base_model.py +149 -0
  73. docling/models/plugins/__init__.py +0 -0
  74. docling/models/plugins/defaults.py +60 -0
  75. docling/models/stages/__init__.py +0 -0
  76. docling/models/stages/code_formula/__init__.py +0 -0
  77. docling/models/stages/code_formula/code_formula_model.py +342 -0
  78. docling/models/stages/layout/__init__.py +0 -0
  79. docling/models/stages/layout/layout_model.py +249 -0
  80. docling/models/stages/ocr/__init__.py +0 -0
  81. docling/models/stages/ocr/auto_ocr_model.py +132 -0
  82. docling/models/stages/ocr/easyocr_model.py +200 -0
  83. docling/models/stages/ocr/ocr_mac_model.py +145 -0
  84. docling/models/stages/ocr/rapid_ocr_model.py +328 -0
  85. docling/models/stages/ocr/tesseract_ocr_cli_model.py +331 -0
  86. docling/models/stages/ocr/tesseract_ocr_model.py +262 -0
  87. docling/models/stages/page_assemble/__init__.py +0 -0
  88. docling/models/stages/page_assemble/page_assemble_model.py +156 -0
  89. docling/models/stages/page_preprocessing/__init__.py +0 -0
  90. docling/models/stages/page_preprocessing/page_preprocessing_model.py +145 -0
  91. docling/models/stages/picture_classifier/__init__.py +0 -0
  92. docling/models/stages/picture_classifier/document_picture_classifier.py +246 -0
  93. docling/models/stages/picture_description/__init__.py +0 -0
  94. docling/models/stages/picture_description/picture_description_api_model.py +66 -0
  95. docling/models/stages/picture_description/picture_description_vlm_model.py +123 -0
  96. docling/models/stages/reading_order/__init__.py +0 -0
  97. docling/models/stages/reading_order/readingorder_model.py +431 -0
  98. docling/models/stages/table_structure/__init__.py +0 -0
  99. docling/models/stages/table_structure/table_structure_model.py +305 -0
  100. docling/models/utils/__init__.py +0 -0
  101. docling/models/utils/generation_utils.py +157 -0
  102. docling/models/utils/hf_model_download.py +45 -0
  103. docling/models/vlm_pipeline_models/__init__.py +1 -0
  104. docling/models/vlm_pipeline_models/api_vlm_model.py +180 -0
  105. docling/models/vlm_pipeline_models/hf_transformers_model.py +391 -0
  106. docling/models/vlm_pipeline_models/mlx_model.py +325 -0
  107. docling/models/vlm_pipeline_models/vllm_model.py +344 -0
  108. docling/pipeline/__init__.py +0 -0
  109. docling/pipeline/asr_pipeline.py +431 -0
  110. docling/pipeline/base_extraction_pipeline.py +72 -0
  111. docling/pipeline/base_pipeline.py +326 -0
  112. docling/pipeline/extraction_vlm_pipeline.py +207 -0
  113. docling/pipeline/legacy_standard_pdf_pipeline.py +262 -0
  114. docling/pipeline/simple_pipeline.py +55 -0
  115. docling/pipeline/standard_pdf_pipeline.py +859 -0
  116. docling/pipeline/threaded_standard_pdf_pipeline.py +5 -0
  117. docling/pipeline/vlm_pipeline.py +416 -0
  118. docling/py.typed +1 -0
  119. docling/utils/__init__.py +0 -0
  120. docling/utils/accelerator_utils.py +97 -0
  121. docling/utils/api_image_request.py +205 -0
  122. docling/utils/deepseekocr_utils.py +388 -0
  123. docling/utils/export.py +146 -0
  124. docling/utils/glm_utils.py +361 -0
  125. docling/utils/layout_postprocessor.py +683 -0
  126. docling/utils/locks.py +3 -0
  127. docling/utils/model_downloader.py +168 -0
  128. docling/utils/ocr_utils.py +69 -0
  129. docling/utils/orientation.py +65 -0
  130. docling/utils/profiling.py +65 -0
  131. docling/utils/utils.py +65 -0
  132. docling/utils/visualization.py +85 -0
  133. docling-2.69.0.dist-info/METADATA +237 -0
  134. docling-2.69.0.dist-info/RECORD +138 -0
  135. docling-2.69.0.dist-info/WHEEL +5 -0
  136. docling-2.69.0.dist-info/entry_points.txt +6 -0
  137. docling-2.69.0.dist-info/licenses/LICENSE +21 -0
  138. docling-2.69.0.dist-info/top_level.txt +1 -0
docling/cli/models.py ADDED
@@ -0,0 +1,196 @@
1
+ import logging
2
+ import warnings
3
+ from enum import Enum
4
+ from pathlib import Path
5
+ from typing import Annotated, Optional
6
+
7
+ import typer
8
+ from rich.console import Console
9
+ from rich.logging import RichHandler
10
+
11
+ from docling.datamodel.settings import settings
12
+ from docling.models.utils.hf_model_download import download_hf_model
13
+ from docling.utils.model_downloader import download_models
14
+
15
+ warnings.filterwarnings(action="ignore", category=UserWarning, module="pydantic|torch")
16
+ warnings.filterwarnings(action="ignore", category=FutureWarning, module="easyocr")
17
+
18
+ console = Console()
19
+ err_console = Console(stderr=True)
20
+
21
+
22
+ app = typer.Typer(
23
+ name="Docling models helper",
24
+ no_args_is_help=True,
25
+ add_completion=False,
26
+ pretty_exceptions_enable=False,
27
+ )
28
+
29
+
30
+ class _AvailableModels(str, Enum):
31
+ LAYOUT = "layout"
32
+ TABLEFORMER = "tableformer"
33
+ CODE_FORMULA = "code_formula"
34
+ PICTURE_CLASSIFIER = "picture_classifier"
35
+ SMOLVLM = "smolvlm"
36
+ GRANITEDOCLING = "granitedocling"
37
+ GRANITEDOCLING_MLX = "granitedocling_mlx"
38
+ SMOLDOCLING = "smoldocling"
39
+ SMOLDOCLING_MLX = "smoldocling_mlx"
40
+ GRANITE_VISION = "granite_vision"
41
+ RAPIDOCR = "rapidocr"
42
+ EASYOCR = "easyocr"
43
+
44
+
45
+ _default_models = [
46
+ _AvailableModels.LAYOUT,
47
+ _AvailableModels.TABLEFORMER,
48
+ _AvailableModels.CODE_FORMULA,
49
+ _AvailableModels.PICTURE_CLASSIFIER,
50
+ _AvailableModels.RAPIDOCR,
51
+ ]
52
+
53
+
54
+ @app.command("download")
55
+ def download(
56
+ output_dir: Annotated[
57
+ Path,
58
+ typer.Option(
59
+ ...,
60
+ "-o",
61
+ "--output-dir",
62
+ help="The directory where to download the models.",
63
+ ),
64
+ ] = (settings.cache_dir / "models"),
65
+ force: Annotated[
66
+ bool, typer.Option(..., help="If true, the download will be forced.")
67
+ ] = False,
68
+ models: Annotated[
69
+ Optional[list[_AvailableModels]],
70
+ typer.Argument(
71
+ help="Models to download (default behavior: a predefined set of models will be downloaded).",
72
+ ),
73
+ ] = None,
74
+ all: Annotated[
75
+ bool,
76
+ typer.Option(
77
+ ...,
78
+ "--all",
79
+ help="If true, all available models will be downloaded (mutually exclusive with passing specific models).",
80
+ show_default=True,
81
+ ),
82
+ ] = False,
83
+ quiet: Annotated[
84
+ bool,
85
+ typer.Option(
86
+ ...,
87
+ "-q",
88
+ "--quiet",
89
+ help="No extra output is generated, the CLI prints only the directory with the cached models.",
90
+ ),
91
+ ] = False,
92
+ ):
93
+ if models and all:
94
+ raise typer.BadParameter(
95
+ "Cannot simultaneously set 'all' parameter and specify models to download."
96
+ )
97
+ if not quiet:
98
+ logging.basicConfig(
99
+ level=logging.INFO,
100
+ format="[blue]%(message)s[/blue]",
101
+ datefmt="[%X]",
102
+ handlers=[RichHandler(show_level=False, show_time=False, markup=True)],
103
+ )
104
+ to_download = models or (list(_AvailableModels) if all else _default_models)
105
+ output_dir = download_models(
106
+ output_dir=output_dir,
107
+ force=force,
108
+ progress=(not quiet),
109
+ with_layout=_AvailableModels.LAYOUT in to_download,
110
+ with_tableformer=_AvailableModels.TABLEFORMER in to_download,
111
+ with_code_formula=_AvailableModels.CODE_FORMULA in to_download,
112
+ with_picture_classifier=_AvailableModels.PICTURE_CLASSIFIER in to_download,
113
+ with_smolvlm=_AvailableModels.SMOLVLM in to_download,
114
+ with_granitedocling=_AvailableModels.GRANITEDOCLING in to_download,
115
+ with_granitedocling_mlx=_AvailableModels.GRANITEDOCLING_MLX in to_download,
116
+ with_smoldocling=_AvailableModels.SMOLDOCLING in to_download,
117
+ with_smoldocling_mlx=_AvailableModels.SMOLDOCLING_MLX in to_download,
118
+ with_granite_vision=_AvailableModels.GRANITE_VISION in to_download,
119
+ with_rapidocr=_AvailableModels.RAPIDOCR in to_download,
120
+ with_easyocr=_AvailableModels.EASYOCR in to_download,
121
+ )
122
+
123
+ if quiet:
124
+ typer.echo(output_dir)
125
+ else:
126
+ typer.secho(f"\nModels downloaded into: {output_dir}.", fg="green")
127
+
128
+ console.print(
129
+ "\n",
130
+ "Docling can now be configured for running offline using the local artifacts.\n\n",
131
+ "Using the CLI:",
132
+ f"`docling --artifacts-path={output_dir} FILE`",
133
+ "\n",
134
+ "Using Python: see the documentation at <https://docling-project.github.io/docling/usage>.",
135
+ )
136
+
137
+
138
+ @app.command("download-hf-repo")
139
+ def download_hf_repo(
140
+ models: Annotated[
141
+ list[str],
142
+ typer.Argument(
143
+ help="Specific models to download from HuggingFace identified by their repo id. For example: docling-project/docling-models .",
144
+ ),
145
+ ],
146
+ output_dir: Annotated[
147
+ Path,
148
+ typer.Option(
149
+ ...,
150
+ "-o",
151
+ "--output-dir",
152
+ help="The directory where to download the models.",
153
+ ),
154
+ ] = (settings.cache_dir / "models"),
155
+ force: Annotated[
156
+ bool, typer.Option(..., help="If true, the download will be forced.")
157
+ ] = False,
158
+ quiet: Annotated[
159
+ bool,
160
+ typer.Option(
161
+ ...,
162
+ "-q",
163
+ "--quiet",
164
+ help="No extra output is generated, the CLI prints only the directory with the cached models.",
165
+ ),
166
+ ] = False,
167
+ ):
168
+ if not quiet:
169
+ logging.basicConfig(
170
+ level=logging.INFO,
171
+ format="[blue]%(message)s[/blue]",
172
+ datefmt="[%X]",
173
+ handlers=[RichHandler(show_level=False, show_time=False, markup=True)],
174
+ )
175
+
176
+ for item in models:
177
+ typer.secho(f"\nDownloading {item} model from HuggingFace...")
178
+ download_hf_model(
179
+ repo_id=item,
180
+ # would be better to reuse "repo_cache_folder" property: https://github.com/docling-project/docling/blob/main/docling/datamodel/pipeline_options_vlm_model.py#L76
181
+ # but creating options objects seams like an overkill
182
+ local_dir=output_dir / item.replace("/", "--"),
183
+ force=force,
184
+ progress=(not quiet),
185
+ )
186
+
187
+ if quiet:
188
+ typer.echo(output_dir)
189
+ else:
190
+ typer.secho(f"\nModels downloaded into: {output_dir}.", fg="green")
191
+
192
+
193
+ click_app = typer.main.get_command(app)
194
+
195
+ if __name__ == "__main__":
196
+ app()
docling/cli/tools.py ADDED
@@ -0,0 +1,17 @@
1
+ import typer
2
+
3
+ from docling.cli.models import app as models_app
4
+
5
+ app = typer.Typer(
6
+ name="Docling helpers",
7
+ no_args_is_help=True,
8
+ add_completion=False,
9
+ pretty_exceptions_enable=False,
10
+ )
11
+
12
+ app.add_typer(models_app, name="models")
13
+
14
+ click_app = typer.main.get_command(app)
15
+
16
+ if __name__ == "__main__":
17
+ app()
File without changes
@@ -0,0 +1,69 @@
1
+ import logging
2
+ import os
3
+ import re
4
+ from enum import Enum
5
+ from typing import Any, Union
6
+
7
+ from pydantic import field_validator, model_validator
8
+ from pydantic_settings import BaseSettings, SettingsConfigDict
9
+
10
+ _log = logging.getLogger(__name__)
11
+
12
+
13
+ class AcceleratorDevice(str, Enum):
14
+ """Devices to run model inference"""
15
+
16
+ AUTO = "auto"
17
+ CPU = "cpu"
18
+ CUDA = "cuda"
19
+ MPS = "mps"
20
+ XPU = "xpu"
21
+
22
+
23
+ class AcceleratorOptions(BaseSettings):
24
+ model_config = SettingsConfigDict(
25
+ env_prefix="DOCLING_", env_nested_delimiter="_", populate_by_name=True
26
+ )
27
+
28
+ num_threads: int = 4
29
+ device: Union[str, AcceleratorDevice] = "auto"
30
+ cuda_use_flash_attention2: bool = False
31
+
32
+ @field_validator("device")
33
+ def validate_device(cls, value):
34
+ # "auto", "cpu", "cuda", "mps", "xpu", or "cuda:N"
35
+ if value in {d.value for d in AcceleratorDevice} or re.match(
36
+ r"^cuda(:\d+)?$", value
37
+ ):
38
+ return value
39
+ raise ValueError(
40
+ "Invalid device option. Use 'auto', 'cpu', 'mps', 'xpu', 'cuda', or 'cuda:N'."
41
+ )
42
+
43
+ @model_validator(mode="before")
44
+ @classmethod
45
+ def check_alternative_envvars(cls, data: Any) -> Any:
46
+ r"""
47
+ Set num_threads from the "alternative" envvar OMP_NUM_THREADS.
48
+ The alternative envvar is used only if it is valid and the regular envvar is not set.
49
+
50
+ Notice: The standard pydantic settings mechanism with parameter "aliases" does not provide
51
+ the same functionality. In case the alias envvar is set and the user tries to override the
52
+ parameter in settings initialization, Pydantic treats the parameter provided in __init__()
53
+ as an extra input instead of simply overwriting the evvar value for that parameter.
54
+ """
55
+ if isinstance(data, dict):
56
+ input_num_threads = data.get("num_threads")
57
+ # Check if to set the num_threads from the alternative envvar
58
+ if input_num_threads is None:
59
+ docling_num_threads = os.getenv("DOCLING_NUM_THREADS")
60
+ omp_num_threads = os.getenv("OMP_NUM_THREADS")
61
+ if docling_num_threads is None and omp_num_threads is not None:
62
+ try:
63
+ data["num_threads"] = int(omp_num_threads)
64
+ except ValueError:
65
+ _log.error(
66
+ "Ignoring misformatted envvar OMP_NUM_THREADS '%s'",
67
+ omp_num_threads,
68
+ )
69
+ return data