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: Update to docling-parse v2 without history #170

Merged
merged 6 commits into from
Oct 23, 2024
Merged
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
6 changes: 3 additions & 3 deletions docling/backend/docling_parse_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pypdfium2 as pdfium
from docling_core.types.doc import BoundingBox, CoordOrigin, Size
from docling_parse.docling_parse import pdf_parser
from docling_parse.docling_parse import pdf_parser_v1
from PIL import Image, ImageDraw
from pypdfium2 import PdfPage

Expand All @@ -19,7 +19,7 @@

class DoclingParsePageBackend(PdfPageBackend):
def __init__(
self, parser: pdf_parser, document_hash: str, page_no: int, page_obj: PdfPage
self, parser: pdf_parser_v1, document_hash: str, page_no: int, page_obj: PdfPage
):
self._ppage = page_obj
parsed_page = parser.parse_pdf_from_key_on_page(document_hash, page_no)
Expand Down Expand Up @@ -192,7 +192,7 @@ def __init__(self, in_doc: "InputDocument", path_or_stream: Union[BytesIO, Path]
super().__init__(in_doc, path_or_stream)

self._pdoc = pdfium.PdfDocument(self.path_or_stream)
self.parser = pdf_parser()
self.parser = pdf_parser_v1()

success = False
if isinstance(self.path_or_stream, BytesIO):
Expand Down
14 changes: 11 additions & 3 deletions docling/backend/docling_parse_v2_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def __init__(
self._ppage = page_obj
parsed_page = parser.parse_pdf_from_key_on_page(document_hash, page_no)

self.valid = "pages" in parsed_page
self.valid = "pages" in parsed_page and len(parsed_page["pages"]) == 1
if self.valid:
self._dpage = parsed_page["pages"][page_no]
self._dpage = parsed_page["pages"][0]
else:
_log.info(
f"An error occured when loading page {page_no} of document {document_hash}."
Expand Down Expand Up @@ -223,7 +223,15 @@ def __init__(self, in_doc: "InputDocument", path_or_stream: Union[BytesIO, Path]
)

def page_count(self) -> int:
return len(self._pdoc) # To be replaced with docling-parse API
# return len(self._pdoc) # To be replaced with docling-parse API

len_1 = len(self._pdoc)
len_2 = self.parser.number_of_pages(self.document_hash)

if len_1 != len_2:
_log.error(f"Inconsistent number of pages: {len_1}!={len_2}")

return len_2

def load_page(self, page_no: int) -> DoclingParseV2PageBackend:
return DoclingParseV2PageBackend(
Expand Down
Loading
Loading