deepdoctection 1.2.5__tar.gz → 1.2.7__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 (58) hide show
  1. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/PKG-INFO +1 -1
  2. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/pyproject.toml +1 -1
  3. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/__init__.py +2 -2
  4. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/anngen.py +17 -5
  5. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/refine.py +44 -31
  6. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/segment.py +2 -2
  7. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection.egg-info/PKG-INFO +1 -1
  8. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/README.md +0 -0
  9. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/setup.cfg +0 -0
  10. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/analyzer/__init__.py +0 -0
  11. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/analyzer/config.py +0 -0
  12. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/analyzer/dd.py +0 -0
  13. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/analyzer/factory.py +0 -0
  14. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/configs/__init__.py +0 -0
  15. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/configs/conf_dd_one.yaml +0 -0
  16. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/configs/conf_tesseract.yaml +0 -0
  17. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/configs/profiles.jsonl +0 -0
  18. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/eval/__init__.py +0 -0
  19. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/eval/accmetric.py +0 -0
  20. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/eval/base.py +0 -0
  21. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/eval/cocometric.py +0 -0
  22. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/eval/eval.py +0 -0
  23. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/eval/registry.py +0 -0
  24. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/eval/tedsmetric.py +0 -0
  25. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/__init__.py +0 -0
  26. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/base.py +0 -0
  27. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/d2detect.py +0 -0
  28. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/deskew.py +0 -0
  29. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/doctrocr.py +0 -0
  30. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/hfdetr.py +0 -0
  31. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/hflayoutlm.py +0 -0
  32. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/hflm.py +0 -0
  33. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/model.py +0 -0
  34. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/pdftext.py +0 -0
  35. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/tessocr.py +0 -0
  36. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/extern/texocr.py +0 -0
  37. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/__init__.py +0 -0
  38. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/base.py +0 -0
  39. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/common.py +0 -0
  40. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/concurrency.py +0 -0
  41. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/doctectionpipe.py +0 -0
  42. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/language.py +0 -0
  43. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/layout.py +0 -0
  44. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/lm.py +0 -0
  45. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/order.py +0 -0
  46. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/registry.py +0 -0
  47. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/sub_layout.py +0 -0
  48. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/text.py +0 -0
  49. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/pipe/transform.py +0 -0
  50. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/py.typed +0 -0
  51. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/train/__init__.py +0 -0
  52. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/train/d2_frcnn_train.py +0 -0
  53. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/train/hf_detr_train.py +0 -0
  54. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection/train/hf_layoutlm_train.py +0 -0
  55. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection.egg-info/SOURCES.txt +0 -0
  56. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection.egg-info/dependency_links.txt +0 -0
  57. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection.egg-info/requires.txt +0 -0
  58. {deepdoctection-1.2.5 → deepdoctection-1.2.7}/src/deepdoctection.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deepdoctection
3
- Version: 1.2.5
3
+ Version: 1.2.7
4
4
  Summary: Repository for Document AI - server/inference core package
5
5
  Author: Dr. Janis Meyer
6
6
  License: Apache License 2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "deepdoctection"
7
- version = "1.2.5"
7
+ version = "1.2.7"
8
8
  authors = [
9
9
  {name = "Dr. Janis Meyer"}
10
10
  ]
@@ -12,7 +12,7 @@ from dd_core.utils.env_info import collect_env_info
12
12
  from dd_core.utils.file_utils import _LazyModule
13
13
  from dd_core.utils.logger import LoggingRecord, logger
14
14
 
15
- __version__ = "1.2.5"
15
+ __version__ = "1.2.7"
16
16
  _IMPORT_STRUCTURE = {
17
17
  "analyzer": ["config_sanity_checks", "get_dd_analyzer", "ServiceFactory", "update_cfg_from_defaults"],
18
18
  "eval": [
@@ -108,7 +108,7 @@ _IMPORT_STRUCTURE = {
108
108
  "TextLineService",
109
109
  "TextOrderService",
110
110
  "TableSegmentationRefinementService",
111
- "generate_html_string",
111
+ "generate_html_payload",
112
112
  "pipeline_component_registry",
113
113
  "TableSegmentationService",
114
114
  "PubtablesSegmentationService",
@@ -25,7 +25,13 @@ from typing import Any, Optional, Sequence, Union
25
25
 
26
26
  import numpy as np
27
27
 
28
- from dd_core.datapoint.annotation import DEFAULT_CATEGORY_ID, CategoryAnnotation, ContainerAnnotation, ImageAnnotation
28
+ from dd_core.datapoint.annotation import (
29
+ DEFAULT_CATEGORY_ID,
30
+ CategoryAnnotation,
31
+ ContainerAnnotation,
32
+ ImageAnnotation,
33
+ ReferencePayload,
34
+ )
29
35
  from dd_core.datapoint.box import BoundingBox, local_to_global_coords, rescale_coords
30
36
  from dd_core.datapoint.image import Image
31
37
  from dd_core.mapper.maputils import MappingContextManager
@@ -89,9 +95,15 @@ def _set_image_keys_to_none(d: Any) -> None:
89
95
  _set_image_keys_to_none(item)
90
96
 
91
97
 
92
- def _image_to_cache_dict(image: Image) -> dict[str, Any]:
98
+ def image_to_cache_dict(image: Image) -> dict[str, Any]:
99
+ """
100
+ Converting image to dict, by adding extras and removing higher hierarchies
101
+
102
+ Args:
103
+ image (Image): The image object to serialize and store.
104
+ """
93
105
  image.remove_image_from_lower_hierarchy()
94
- export_dict = image.as_dict()
106
+ export_dict = image.as_dict(add_extras=True)
95
107
  _set_image_keys_to_none(export_dict)
96
108
  return export_dict
97
109
 
@@ -152,7 +164,7 @@ class LocalDataPointCacheStore(DataPointCacheStore):
152
164
  if pages is None:
153
165
  pages = {}
154
166
  self._pages[cache_key] = pages
155
- pages[page_number] = _image_to_cache_dict(image)
167
+ pages[page_number] = image_to_cache_dict(image)
156
168
  if self._max_pages > 0 and len(pages) > self._max_pages:
157
169
  for k in sorted(pages.keys())[: -self._max_pages]:
158
170
  pages.pop(k, None)
@@ -446,7 +458,7 @@ class DatapointManager:
446
458
  category_id: Optional[int],
447
459
  sub_cat_key: ObjectTypes,
448
460
  annotation_id: str,
449
- value: Union[str, list[str]],
461
+ value: Union[str, list[str], ReferencePayload],
450
462
  score: Optional[float] = None,
451
463
  ) -> Optional[str]:
452
464
  """
@@ -25,11 +25,11 @@ from collections import defaultdict
25
25
  from copy import copy
26
26
  from dataclasses import asdict
27
27
  from itertools import chain, product
28
- from typing import DefaultDict, Optional, Sequence, Union
28
+ from typing import DefaultDict, Optional, Sequence
29
29
 
30
30
  from lazy_imports import try_import
31
31
 
32
- from dd_core.datapoint.annotation import ImageAnnotation
32
+ from dd_core.datapoint.annotation import AnnotationRef, ImageAnnotation, ReferencePayload
33
33
  from dd_core.datapoint.box import merge_boxes
34
34
  from dd_core.datapoint.image import Image, MetaAnnotation
35
35
  from dd_core.mapper.maputils import MappingContextManager
@@ -45,7 +45,7 @@ with try_import() as import_guard:
45
45
  import networkx as nx # type: ignore
46
46
 
47
47
 
48
- __all__ = ["TableSegmentationRefinementService", "generate_html_string"]
48
+ __all__ = ["TableSegmentationRefinementService", "generate_html_payload"]
49
49
 
50
50
 
51
51
  def tiles_to_cells(
@@ -233,8 +233,9 @@ def _tiling_to_cell_position(inputs: set[tuple[int, int]]) -> tuple[int, int, in
233
233
 
234
234
 
235
235
  def _html_cell(
236
- cell_position: Union[tuple[int, int, int, int], tuple[()]], position_filled_list: list[tuple[int, int]]
237
- ) -> list[str]:
236
+ cell_position: tuple[int, int, int, int] | tuple[()],
237
+ position_filled_list: list[tuple[int, int]],
238
+ ) -> list[str | AnnotationRef]:
238
239
  """
239
240
  Generates an HTML table cell string.
240
241
 
@@ -263,7 +264,7 @@ def _html_cell(
263
264
  )
264
265
  html.append(">")
265
266
  str_html = "".join(html)
266
- html_list = [str_html, "</td>"]
267
+ html_list: list[str | AnnotationRef] = [str_html, "</td>"]
267
268
  return html_list
268
269
 
269
270
 
@@ -273,7 +274,8 @@ def _html_row(
273
274
  this_row: int,
274
275
  number_of_cols: int,
275
276
  row_ann_id_list: list[str],
276
- ) -> list[str]:
277
+ image_id: str | None = None,
278
+ ) -> list[str | AnnotationRef]:
277
279
  """
278
280
  Generates an HTML table row string.
279
281
 
@@ -283,16 +285,17 @@ def _html_row(
283
285
  this_row: The current row number.
284
286
  number_of_cols: The total number of columns.
285
287
  row_ann_id_list: List of annotation ids for the row.
288
+ image_id: Image id of the table image.
286
289
 
287
290
  Returns:
288
- List of HTML strings representing the row.
291
+ List of HTML strings and AnnotationRef objects representing the row.
289
292
  """
290
- html = ["<tr>"]
293
+ html: list[str | AnnotationRef] = ["<tr>"]
291
294
  for idx in range(1, number_of_cols + 1):
292
295
  position_filled_this_row = list(filter(lambda x: x[0] == this_row, position_filled_list))
293
296
  column_filled_this_row = list(zip(*position_filled_this_row))
294
297
  column_filled_this_row = (
295
- [column_filled_this_row, column_filled_this_row] # type:ignore
298
+ [column_filled_this_row, column_filled_this_row] # type: ignore
296
299
  if not column_filled_this_row
297
300
  else column_filled_this_row
298
301
  )
@@ -305,7 +308,7 @@ def _html_row(
305
308
  cell_position = cell_position_list[0]
306
309
  cell_id = row_ann_id_list.pop(0)
307
310
  ret_html = _html_cell(cell_position, position_filled_list)
308
- ret_html.insert(1, cell_id)
311
+ ret_html.insert(1, AnnotationRef(image_id=image_id, annotation_id=cell_id))
309
312
  else:
310
313
  cell_position = () # type: ignore
311
314
  ret_html = _html_cell(cell_position, position_filled_list)
@@ -319,62 +322,63 @@ def _html_table(
319
322
  cells_ann_list: list[tuple[int, list[str]]],
320
323
  number_of_rows: int,
321
324
  number_of_cols: int,
322
- ) -> list[str]:
325
+ image_id: str | None = None,
326
+ ) -> list[str | AnnotationRef]:
323
327
  """
324
- Generates an HTML table string.
328
+ Generates an HTML table representation with unresolved AnnotationRef placeholders.
325
329
 
326
330
  Args:
327
331
  table_list: List of tuples with row number and list of cell position tuples.
328
332
  cells_ann_list: List of tuples with row number and list of annotation ids.
329
333
  number_of_rows: The total number of rows.
330
334
  number_of_cols: The total number of columns.
335
+ image_id: Image id of the table image.
331
336
 
332
337
  Returns:
333
- List of HTML strings representing the table.
338
+ List of HTML strings and AnnotationRef objects representing the table.
334
339
  """
335
- html = ["<table>"]
340
+ html: list[str | AnnotationRef] = ["<table>"]
336
341
  position_filled: list[tuple[int, int]] = []
337
342
  for idx in range(1, number_of_rows + 1):
338
343
  row_idx = list(filter(lambda x: x[0] == idx, table_list))[0][1] # pylint:disable=W0640
339
344
  row_ann_ids = list(filter(lambda x: x[0] == idx, cells_ann_list))[0][1] # pylint:disable=W0640
340
- ret_html = _html_row(row_idx, position_filled, idx, number_of_cols, row_ann_ids)
345
+ ret_html = _html_row(row_idx, position_filled, idx, number_of_cols, row_ann_ids, image_id)
341
346
  html.extend(ret_html)
342
347
  html.append("</table>")
343
348
  return html
344
349
 
345
350
 
346
- def generate_html_string(table: ImageAnnotation, cell_names: Sequence[ObjectTypes]) -> list[str]:
351
+ def generate_html_payload(table: ImageAnnotation, cell_names: Sequence[ObjectTypes]) -> ReferencePayload:
347
352
  """
348
- Generates an HTML representation of a table using table segmentation by row number, column number, etc.
349
-
350
- Note:
351
- It must be ensured that all cells have a row number, column number, row span, and column span, and that the
352
- dissection by rows and columns is completely covered by cells.
353
+ Generates an unresolved HTML representation of a table using AnnotationRef placeholders.
353
354
 
354
355
  Args:
355
356
  table: An annotation that has a not None image and fully segmented cell annotation.
356
357
  cell_names: List of cell names that are used for the table segmentation.
357
358
 
358
359
  Returns:
359
- HTML representation of the table.
360
+ ReferencePayload with HTML fragments and AnnotationRef placeholders.
360
361
 
361
362
  Raises:
362
- `ImageError`: If `table.image` is None.
363
+ ImageError: If table.image is None.
363
364
  """
364
365
  if table.image is None:
365
366
  raise ImageError("table.image cannot be None")
367
+
366
368
  table_image = table.image
367
369
  cells = table_image.get_annotation(category_names=cell_names)
368
370
  number_of_rows = table_image.summary.get_sub_category(TableKey.NUMBER_OF_ROWS).category_id
369
371
  number_of_cols = table_image.summary.get_sub_category(TableKey.NUMBER_OF_COLUMNS).category_id
372
+
370
373
  table_list = []
371
374
  cells_ann_list = []
375
+
372
376
  for row_number in range(1, number_of_rows + 1):
373
377
  cells_of_row = list(
374
378
  sorted(
375
379
  filter(
376
380
  lambda cell: cell.get_sub_category(CellKey.ROW_NUMBER).category_id
377
- == row_number, # pylint: disable=W0640
381
+ == row_number, # pylint:disable=W0640
378
382
  cells,
379
383
  ),
380
384
  key=lambda cell: cell.get_sub_category(CellKey.COLUMN_NUMBER).category_id,
@@ -392,7 +396,16 @@ def generate_html_string(table: ImageAnnotation, cell_names: Sequence[ObjectType
392
396
  ann_list = [cell.annotation_id for cell in cells_of_row]
393
397
  table_list.append((row_number, row_list))
394
398
  cells_ann_list.append((row_number, ann_list))
395
- return _html_table(table_list, cells_ann_list, number_of_rows, number_of_cols)
399
+
400
+ html_fragments = _html_table(
401
+ table_list=table_list,
402
+ cells_ann_list=cells_ann_list,
403
+ number_of_rows=number_of_rows,
404
+ number_of_cols=number_of_cols,
405
+ image_id=None,
406
+ )
407
+
408
+ return ReferencePayload(content=html_fragments)
396
409
 
397
410
 
398
411
  @pipeline_component_registry.register("TableSegmentationRefinementService")
@@ -523,10 +536,10 @@ class TableSegmentationRefinementService(PipelineComponent):
523
536
  and TableKey.MAX_ROW_SPAN in table.image.summary.sub_categories
524
537
  and TableKey.MAX_COL_SPAN in table.image.summary.sub_categories
525
538
  ):
526
- table.image.summary.remove_sub_category(TableKey.NUMBER_OF_ROWS)
527
- table.image.summary.remove_sub_category(TableKey.NUMBER_OF_COLUMNS)
528
- table.image.summary.remove_sub_category(TableKey.MAX_ROW_SPAN)
529
- table.image.summary.remove_sub_category(TableKey.MAX_COL_SPAN)
539
+ table.image.summary.pop_sub_category(TableKey.NUMBER_OF_ROWS)
540
+ table.image.summary.pop_sub_category(TableKey.NUMBER_OF_COLUMNS)
541
+ table.image.summary.pop_sub_category(TableKey.MAX_ROW_SPAN)
542
+ table.image.summary.pop_sub_category(TableKey.MAX_COL_SPAN)
530
543
 
531
544
  self.dp_manager.set_summary_annotation(
532
545
  TableKey.NUMBER_OF_ROWS, TableKey.NUMBER_OF_ROWS, number_of_rows, annotation_id=table.annotation_id
@@ -543,7 +556,7 @@ class TableSegmentationRefinementService(PipelineComponent):
543
556
  self.dp_manager.set_summary_annotation(
544
557
  TableKey.MAX_COL_SPAN, TableKey.MAX_COL_SPAN, max_col_span, annotation_id=table.annotation_id
545
558
  )
546
- html = generate_html_string(table, self.cell_names)
559
+ html = generate_html_payload(table, self.cell_names)
547
560
  self.dp_manager.set_container_annotation(TableKey.HTML, -1, TableKey.HTML, table.annotation_id, html)
548
561
 
549
562
  def clone(self) -> TableSegmentationRefinementService:
@@ -53,7 +53,7 @@ from dd_core.utils.object_types import (
53
53
 
54
54
  from ..extern.base import DetectionResult
55
55
  from .base import PipelineComponent
56
- from .refine import generate_html_string
56
+ from .refine import generate_html_payload
57
57
  from .registry import pipeline_component_registry
58
58
 
59
59
  __all__ = ["TableSegmentationService", "SegmentationResult", "PubtablesSegmentationService"]
@@ -1350,7 +1350,7 @@ class PubtablesSegmentationService(PipelineComponent):
1350
1350
  self.dp_manager.set_summary_annotation(
1351
1351
  TableKey.MAX_COL_SPAN, TableKey.MAX_COL_SPAN, max_col_span, annotation_id=table.annotation_id
1352
1352
  )
1353
- html = generate_html_string(table, self.cell_names + self.spanning_cell_names)
1353
+ html = generate_html_payload(table, self.cell_names + self.spanning_cell_names)
1354
1354
  self.dp_manager.set_container_annotation(TableKey.HTML, -1, TableKey.HTML, table.annotation_id, html)
1355
1355
 
1356
1356
  def clone(self) -> PubtablesSegmentationService:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deepdoctection
3
- Version: 1.2.5
3
+ Version: 1.2.7
4
4
  Summary: Repository for Document AI - server/inference core package
5
5
  Author: Dr. Janis Meyer
6
6
  License: Apache License 2.0
File without changes
File without changes