Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [WIP] Support Document Index as a layout class #132

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docling/datamodel/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

layout_label_to_ds_type = {
"Title": "title",
"Document Index": "table-of-path_or_stream",
"Document Index": "table", # table-of-contents",
"Section-header": "subtitle-level-1",
"Checkbox-Selected": "checkbox-selected",
"Checkbox-Unselected": "checkbox-unselected",
Expand Down
2 changes: 1 addition & 1 deletion docling/document_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def download_models_hf(
repo_id="ds4sd/docling-models",
force_download=force,
local_dir=local_dir,
revision="v2.0.0",
revision="v2.0.1",
)

return Path(download_path)
Expand Down
4 changes: 2 additions & 2 deletions docling/models/layout_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LayoutModel:
]
PAGE_HEADER_LABELS = ["Page-header", "Page-footer"]

TABLE_LABEL = "Table"
TABLE_LABELS = ["Table", "Document Index"]
FIGURE_LABEL = "Picture"
FORMULA_LABEL = "Formula"

Expand Down Expand Up @@ -70,7 +70,7 @@ def postprocess(self, clusters: List[Cluster], cells: List[Cell], page_height):
"Key-Value Region": 0.45,
}

CLASS_REMAPPINGS = {"Document Index": "Table", "Title": "Section-header"}
CLASS_REMAPPINGS = {"Title": "Section-header"}

_log.debug("================= Start postprocess function ====================")
start_time = time.time()
Expand Down
2 changes: 1 addition & 1 deletion docling/models/page_assemble_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __call__(self, page_batch: Iterable[Page]) -> Iterable[Page]:
headers.append(text_el)
else:
body.append(text_el)
elif cluster.label == LayoutModel.TABLE_LABEL:
elif cluster.label in LayoutModel.TABLE_LABELS:
tbl = None
if page.predictions.tablestructure:
tbl = page.predictions.tablestructure.table_map.get(
Expand Down
4 changes: 2 additions & 2 deletions docling/models/table_structure_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __call__(self, page_batch: Iterable[Page]) -> Iterable[Page]:
],
)
for cluster in page.predictions.layout.clusters
if cluster.label == "Table"
if cluster.label in ["Table", "Document Index"]
]
if not len(in_tables):
yield page
Expand Down Expand Up @@ -149,7 +149,7 @@ def __call__(self, page_batch: Iterable[Page]) -> Iterable[Page]:
id=table_cluster.id,
page_no=page.page_no,
cluster=table_cluster,
label="Table",
label=table_cluster.label,
)

page.predictions.tablestructure.table_map[table_cluster.id] = tbl
Expand Down
Loading