mirror of
https://github.com/docling-project/docling.git
synced 2026-05-17 13:10:38 +00:00
* Update sample image path to be relative The example script currently uses a relative path (tests\data\...) to load the sample image. This causes a FileNotFoundError if the script is not executed strictly from the repository root (e.g., when running directly from an IDE or the script's own directory). Signed-off-by: Nikhil Singh <124866156+Ritinikhil@users.noreply.github.com> * Update docs/examples/experimental/process_table_crops.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Peter W. J. Staar <91719829+PeterStaar-IBM@users.noreply.github.com> * formatter and linter Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> --------- Signed-off-by: Nikhil Singh <124866156+Ritinikhil@users.noreply.github.com> Signed-off-by: Peter W. J. Staar <91719829+PeterStaar-IBM@users.noreply.github.com> Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> Co-authored-by: Peter W. J. Staar <91719829+PeterStaar-IBM@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Michele Dolfi <dol@zurich.ibm.com>
44 lines
1.3 KiB
Python
Vendored
44 lines
1.3 KiB
Python
Vendored
"""Run Docling on an image using the experimental TableCrops layout model."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import docling
|
|
from docling.datamodel.document import InputFormat
|
|
from docling.datamodel.pipeline_options import ThreadedPdfPipelineOptions
|
|
from docling.document_converter import DocumentConverter, ImageFormatOption
|
|
from docling.experimental.datamodel.table_crops_layout_options import (
|
|
TableCropsLayoutOptions,
|
|
)
|
|
from docling.experimental.models.table_crops_layout_model import TableCropsLayoutModel
|
|
from docling.models.factories import get_layout_factory
|
|
|
|
|
|
def main() -> None:
|
|
# Go up 3 levels to escape 'docs' and reach the repo root
|
|
sample_image = (
|
|
Path(__file__).parent / "../../../tests/data/2305.03393v1-table_crop.png"
|
|
)
|
|
|
|
pipeline_options = ThreadedPdfPipelineOptions(
|
|
layout_options=TableCropsLayoutOptions(),
|
|
do_table_structure=True,
|
|
generate_page_images=True,
|
|
)
|
|
|
|
converter = DocumentConverter(
|
|
allowed_formats=[InputFormat.IMAGE],
|
|
format_options={
|
|
InputFormat.IMAGE: ImageFormatOption(pipeline_options=pipeline_options)
|
|
},
|
|
)
|
|
|
|
conv_res = converter.convert(sample_image)
|
|
|
|
print(conv_res.document.tables[0].export_to_markdown())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|