docling 2.21.0__tar.gz → 2.23.0__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 (70) hide show
  1. {docling-2.21.0 → docling-2.23.0}/PKG-INFO +3 -3
  2. docling-2.23.0/docling/backend/csv_backend.py +125 -0
  3. docling-2.23.0/docling/backend/xml/jats_backend.py +772 -0
  4. {docling-2.21.0 → docling-2.23.0}/docling/cli/main.py +7 -0
  5. {docling-2.21.0 → docling-2.23.0}/docling/datamodel/base_models.py +6 -3
  6. {docling-2.21.0 → docling-2.23.0}/docling/datamodel/document.py +37 -4
  7. {docling-2.21.0 → docling-2.23.0}/docling/datamodel/pipeline_options.py +30 -4
  8. {docling-2.21.0 → docling-2.23.0}/docling/datamodel/settings.py +2 -1
  9. {docling-2.21.0 → docling-2.23.0}/docling/document_converter.py +14 -5
  10. {docling-2.21.0 → docling-2.23.0}/docling/exceptions.py +4 -0
  11. {docling-2.21.0 → docling-2.23.0}/docling/models/picture_description_api_model.py +11 -4
  12. {docling-2.21.0 → docling-2.23.0}/docling/models/tesseract_ocr_model.py +1 -2
  13. {docling-2.21.0 → docling-2.23.0}/docling/pipeline/standard_pdf_pipeline.py +9 -0
  14. docling-2.23.0/docling/utils/accelerator_utils.py +68 -0
  15. {docling-2.21.0 → docling-2.23.0}/pyproject.toml +3 -3
  16. docling-2.21.0/docling/backend/xml/pubmed_backend.py +0 -592
  17. docling-2.21.0/docling/utils/accelerator_utils.py +0 -42
  18. {docling-2.21.0 → docling-2.23.0}/LICENSE +0 -0
  19. {docling-2.21.0 → docling-2.23.0}/README.md +0 -0
  20. {docling-2.21.0 → docling-2.23.0}/docling/__init__.py +0 -0
  21. {docling-2.21.0 → docling-2.23.0}/docling/backend/__init__.py +0 -0
  22. {docling-2.21.0 → docling-2.23.0}/docling/backend/abstract_backend.py +0 -0
  23. {docling-2.21.0 → docling-2.23.0}/docling/backend/asciidoc_backend.py +0 -0
  24. {docling-2.21.0 → docling-2.23.0}/docling/backend/docling_parse_backend.py +0 -0
  25. {docling-2.21.0 → docling-2.23.0}/docling/backend/docling_parse_v2_backend.py +0 -0
  26. {docling-2.21.0 → docling-2.23.0}/docling/backend/html_backend.py +0 -0
  27. {docling-2.21.0 → docling-2.23.0}/docling/backend/json/__init__.py +0 -0
  28. {docling-2.21.0 → docling-2.23.0}/docling/backend/json/docling_json_backend.py +0 -0
  29. {docling-2.21.0 → docling-2.23.0}/docling/backend/md_backend.py +0 -0
  30. {docling-2.21.0 → docling-2.23.0}/docling/backend/msexcel_backend.py +0 -0
  31. {docling-2.21.0 → docling-2.23.0}/docling/backend/mspowerpoint_backend.py +0 -0
  32. {docling-2.21.0 → docling-2.23.0}/docling/backend/msword_backend.py +0 -0
  33. {docling-2.21.0 → docling-2.23.0}/docling/backend/pdf_backend.py +0 -0
  34. {docling-2.21.0 → docling-2.23.0}/docling/backend/pypdfium2_backend.py +0 -0
  35. {docling-2.21.0 → docling-2.23.0}/docling/backend/xml/__init__.py +0 -0
  36. {docling-2.21.0 → docling-2.23.0}/docling/backend/xml/uspto_backend.py +0 -0
  37. {docling-2.21.0 → docling-2.23.0}/docling/chunking/__init__.py +0 -0
  38. {docling-2.21.0 → docling-2.23.0}/docling/cli/__init__.py +0 -0
  39. {docling-2.21.0 → docling-2.23.0}/docling/cli/models.py +0 -0
  40. {docling-2.21.0 → docling-2.23.0}/docling/cli/tools.py +0 -0
  41. {docling-2.21.0 → docling-2.23.0}/docling/datamodel/__init__.py +0 -0
  42. {docling-2.21.0 → docling-2.23.0}/docling/models/__init__.py +0 -0
  43. {docling-2.21.0 → docling-2.23.0}/docling/models/base_model.py +0 -0
  44. {docling-2.21.0 → docling-2.23.0}/docling/models/base_ocr_model.py +0 -0
  45. {docling-2.21.0 → docling-2.23.0}/docling/models/code_formula_model.py +0 -0
  46. {docling-2.21.0 → docling-2.23.0}/docling/models/document_picture_classifier.py +0 -0
  47. {docling-2.21.0 → docling-2.23.0}/docling/models/ds_glm_model.py +0 -0
  48. {docling-2.21.0 → docling-2.23.0}/docling/models/easyocr_model.py +0 -0
  49. {docling-2.21.0 → docling-2.23.0}/docling/models/layout_model.py +0 -0
  50. {docling-2.21.0 → docling-2.23.0}/docling/models/ocr_mac_model.py +0 -0
  51. {docling-2.21.0 → docling-2.23.0}/docling/models/page_assemble_model.py +0 -0
  52. {docling-2.21.0 → docling-2.23.0}/docling/models/page_preprocessing_model.py +0 -0
  53. {docling-2.21.0 → docling-2.23.0}/docling/models/picture_description_base_model.py +0 -0
  54. {docling-2.21.0 → docling-2.23.0}/docling/models/picture_description_vlm_model.py +0 -0
  55. {docling-2.21.0 → docling-2.23.0}/docling/models/rapid_ocr_model.py +0 -0
  56. {docling-2.21.0 → docling-2.23.0}/docling/models/table_structure_model.py +0 -0
  57. {docling-2.21.0 → docling-2.23.0}/docling/models/tesseract_ocr_cli_model.py +0 -0
  58. {docling-2.21.0 → docling-2.23.0}/docling/pipeline/__init__.py +0 -0
  59. {docling-2.21.0 → docling-2.23.0}/docling/pipeline/base_pipeline.py +0 -0
  60. {docling-2.21.0 → docling-2.23.0}/docling/pipeline/simple_pipeline.py +0 -0
  61. {docling-2.21.0 → docling-2.23.0}/docling/py.typed +0 -0
  62. {docling-2.21.0 → docling-2.23.0}/docling/utils/__init__.py +0 -0
  63. {docling-2.21.0 → docling-2.23.0}/docling/utils/export.py +0 -0
  64. {docling-2.21.0 → docling-2.23.0}/docling/utils/glm_utils.py +0 -0
  65. {docling-2.21.0 → docling-2.23.0}/docling/utils/layout_postprocessor.py +0 -0
  66. {docling-2.21.0 → docling-2.23.0}/docling/utils/model_downloader.py +0 -0
  67. {docling-2.21.0 → docling-2.23.0}/docling/utils/ocr_utils.py +0 -0
  68. {docling-2.21.0 → docling-2.23.0}/docling/utils/profiling.py +0 -0
  69. {docling-2.21.0 → docling-2.23.0}/docling/utils/utils.py +0 -0
  70. {docling-2.21.0 → docling-2.23.0}/docling/utils/visualization.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: docling
3
- Version: 2.21.0
3
+ Version: 2.23.0
4
4
  Summary: SDK and CLI for parsing PDF, DOCX, HTML, and more, to a unified document representation for powering downstream workflows such as gen AI applications.
5
5
  Home-page: https://github.com/DS4SD/docling
6
6
  License: MIT
@@ -28,7 +28,7 @@ Provides-Extra: vlm
28
28
  Requires-Dist: beautifulsoup4 (>=4.12.3,<4.13.0)
29
29
  Requires-Dist: certifi (>=2024.7.4)
30
30
  Requires-Dist: deepsearch-glm (>=1.0.0,<2.0.0)
31
- Requires-Dist: docling-core[chunking] (>=2.18.0,<3.0.0)
31
+ Requires-Dist: docling-core[chunking] (>=2.19.0,<3.0.0)
32
32
  Requires-Dist: docling-ibm-models (>=3.3.0,<4.0.0)
33
33
  Requires-Dist: docling-parse (>=3.3.0,<4.0.0)
34
34
  Requires-Dist: easyocr (>=1.7,<2.0)
@@ -41,7 +41,7 @@ Requires-Dist: onnxruntime (>=1.7.0,<1.20.0) ; (python_version < "3.10") and (ex
41
41
  Requires-Dist: onnxruntime (>=1.7.0,<2.0.0) ; (python_version >= "3.10") and (extra == "rapidocr")
42
42
  Requires-Dist: openpyxl (>=3.1.5,<4.0.0)
43
43
  Requires-Dist: pandas (>=2.1.4,<3.0.0)
44
- Requires-Dist: pillow (>=10.0.0,<11.0.0)
44
+ Requires-Dist: pillow (>=10.0.0,<12.0.0)
45
45
  Requires-Dist: pydantic (>=2.0.0,<3.0.0)
46
46
  Requires-Dist: pydantic-settings (>=2.3.0,<3.0.0)
47
47
  Requires-Dist: pypdfium2 (>=4.30.0,<5.0.0)
@@ -0,0 +1,125 @@
1
+ import csv
2
+ import logging
3
+ import warnings
4
+ from io import BytesIO, StringIO
5
+ from pathlib import Path
6
+ from typing import Set, Union
7
+
8
+ from docling_core.types.doc import DoclingDocument, DocumentOrigin, TableCell, TableData
9
+
10
+ from docling.backend.abstract_backend import DeclarativeDocumentBackend
11
+ from docling.datamodel.base_models import InputFormat
12
+ from docling.datamodel.document import InputDocument
13
+
14
+ _log = logging.getLogger(__name__)
15
+
16
+
17
+ class CsvDocumentBackend(DeclarativeDocumentBackend):
18
+ content: StringIO
19
+
20
+ def __init__(self, in_doc: "InputDocument", path_or_stream: Union[BytesIO, Path]):
21
+ super().__init__(in_doc, path_or_stream)
22
+
23
+ # Load content
24
+ try:
25
+ if isinstance(self.path_or_stream, BytesIO):
26
+ self.content = StringIO(self.path_or_stream.getvalue().decode("utf-8"))
27
+ elif isinstance(self.path_or_stream, Path):
28
+ self.content = StringIO(self.path_or_stream.read_text("utf-8"))
29
+ self.valid = True
30
+ except Exception as e:
31
+ raise RuntimeError(
32
+ f"CsvDocumentBackend could not load document with hash {self.document_hash}"
33
+ ) from e
34
+ return
35
+
36
+ def is_valid(self) -> bool:
37
+ return self.valid
38
+
39
+ @classmethod
40
+ def supports_pagination(cls) -> bool:
41
+ return False
42
+
43
+ def unload(self):
44
+ if isinstance(self.path_or_stream, BytesIO):
45
+ self.path_or_stream.close()
46
+ self.path_or_stream = None
47
+
48
+ @classmethod
49
+ def supported_formats(cls) -> Set[InputFormat]:
50
+ return {InputFormat.CSV}
51
+
52
+ def convert(self) -> DoclingDocument:
53
+ """
54
+ Parses the CSV data into a structured document model.
55
+ """
56
+
57
+ # Detect CSV dialect
58
+ head = self.content.readline()
59
+ dialect = csv.Sniffer().sniff(head, ",;\t|:")
60
+ _log.info(f'Parsing CSV with delimiter: "{dialect.delimiter}"')
61
+ if not dialect.delimiter in {",", ";", "\t", "|", ":"}:
62
+ raise RuntimeError(
63
+ f"Cannot convert csv with unknown delimiter {dialect.delimiter}."
64
+ )
65
+
66
+ # Parce CSV
67
+ self.content.seek(0)
68
+ result = csv.reader(self.content, dialect=dialect, strict=True)
69
+ self.csv_data = list(result)
70
+ _log.info(f"Detected {len(self.csv_data)} lines")
71
+
72
+ # Ensure uniform column length
73
+ expected_length = len(self.csv_data[0])
74
+ is_uniform = all(len(row) == expected_length for row in self.csv_data)
75
+ if not is_uniform:
76
+ warnings.warn(
77
+ f"Inconsistent column lengths detected in CSV data. "
78
+ f"Expected {expected_length} columns, but found rows with varying lengths. "
79
+ f"Ensure all rows have the same number of columns."
80
+ )
81
+
82
+ # Parse the CSV into a structured document model
83
+ origin = DocumentOrigin(
84
+ filename=self.file.name or "file.csv",
85
+ mimetype="text/csv",
86
+ binary_hash=self.document_hash,
87
+ )
88
+
89
+ doc = DoclingDocument(name=self.file.stem or "file.csv", origin=origin)
90
+
91
+ if self.is_valid():
92
+ # Convert CSV data to table
93
+ if self.csv_data:
94
+ num_rows = len(self.csv_data)
95
+ num_cols = max(len(row) for row in self.csv_data)
96
+
97
+ table_data = TableData(
98
+ num_rows=num_rows,
99
+ num_cols=num_cols,
100
+ table_cells=[],
101
+ )
102
+
103
+ # Convert each cell to TableCell
104
+ for row_idx, row in enumerate(self.csv_data):
105
+ for col_idx, cell_value in enumerate(row):
106
+ cell = TableCell(
107
+ text=str(cell_value),
108
+ row_span=1, # CSV doesn't support merged cells
109
+ col_span=1,
110
+ start_row_offset_idx=row_idx,
111
+ end_row_offset_idx=row_idx + 1,
112
+ start_col_offset_idx=col_idx,
113
+ end_col_offset_idx=col_idx + 1,
114
+ col_header=row_idx == 0, # First row as header
115
+ row_header=False,
116
+ )
117
+ table_data.table_cells.append(cell)
118
+
119
+ doc.add_table(data=table_data)
120
+ else:
121
+ raise RuntimeError(
122
+ f"Cannot convert doc with {self.document_hash} because the backend failed to init."
123
+ )
124
+
125
+ return doc