mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 20:58:11 +00:00
Cleaned up logs, added pages to vlm_pipeline, basic timing per page measurement in smol_docling models
Signed-off-by: Maksym Lysak <mly@zurich.ibm.com>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from docling.backend.docling_parse_backend import DoclingParseDocumentBackend
|
||||
from docling.datamodel.base_models import InputFormat
|
||||
@@ -6,12 +9,18 @@ from docling.datamodel.pipeline_options import PdfPipelineOptions
|
||||
from docling.document_converter import DocumentConverter, PdfFormatOption
|
||||
from docling.pipeline.vlm_pipeline import VlmPipeline
|
||||
|
||||
source = "https://arxiv.org/pdf/2408.09869" # document per local path or URL
|
||||
# source = "https://arxiv.org/pdf/2408.09869" # document per local path or URL
|
||||
# source = "tests/data/2305.03393v1-pg9-img.png"
|
||||
# source = "tests/data/2305.03393v1-pg9.pdf"
|
||||
source = "tests/data/2305.03393v1-pg9.pdf"
|
||||
# source = "demo_data/page.png"
|
||||
# source = "demo_data/original_tables.pdf"
|
||||
|
||||
parsed = urlparse(source)
|
||||
if parsed.scheme in ("http", "https"):
|
||||
out_name = os.path.basename(parsed.path)
|
||||
else:
|
||||
out_name = os.path.basename(source)
|
||||
|
||||
pipeline_options = PdfPipelineOptions()
|
||||
pipeline_options.generate_page_images = True
|
||||
pipeline_options.artifacts_path = "model_artifacts"
|
||||
@@ -32,6 +41,7 @@ converter = DocumentConverter(
|
||||
}
|
||||
)
|
||||
|
||||
start_time = time.time()
|
||||
print("============")
|
||||
print("starting...")
|
||||
print("============")
|
||||
@@ -39,12 +49,6 @@ print("")
|
||||
|
||||
result = converter.convert(source)
|
||||
|
||||
# print("------------")
|
||||
# print("result:")
|
||||
# print("------------")
|
||||
# print("")
|
||||
# print(result)
|
||||
|
||||
print("------------")
|
||||
print("MD:")
|
||||
print("------------")
|
||||
@@ -53,12 +57,16 @@ print(result.document.export_to_markdown())
|
||||
|
||||
Path("scratch").mkdir(parents=True, exist_ok=True)
|
||||
result.document.save_as_html(
|
||||
filename=Path("scratch/smol_export.html"),
|
||||
filename=Path("scratch/{}.html".format(out_name)),
|
||||
image_mode=ImageRefMode.REFERENCED,
|
||||
labels=[*DEFAULT_EXPORT_LABELS, DocItemLabel.FOOTNOTE],
|
||||
)
|
||||
|
||||
pg_num = result.document.num_pages()
|
||||
|
||||
print("")
|
||||
inference_time = time.time() - start_time
|
||||
print(f"Total document prediction time: {inference_time:.2f} seconds, pages: {pg_num}")
|
||||
print("============")
|
||||
print("done!")
|
||||
print("============")
|
||||
|
||||
Reference in New Issue
Block a user