mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-09 13:18:24 +00:00
feat: Update to docling-parse v2 without history (#170)
* updated the pyproject (still need to run poetry lock after docling-parse is accepted) Signed-off-by: Peter Staar <taa@zurich.ibm.com> * Update imports for docling_parse.pdf_parser_v1 Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * Lock docling-parse 2.0.0 Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * Lock docling-parse 2.0.0 Signed-off-by: Christoph Auer <cau@zurich.ibm.com> * repin poetry.lock Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> --------- Signed-off-by: Peter Staar <taa@zurich.ibm.com> Signed-off-by: Christoph Auer <cau@zurich.ibm.com> Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> Co-authored-by: Christoph Auer <cau@zurich.ibm.com> Co-authored-by: Michele Dolfi <dol@zurich.ibm.com>
This commit is contained in:
committed by
GitHub
parent
3023f18ba0
commit
4116819b51
@@ -6,7 +6,7 @@ from typing import Iterable, List, Optional, Union
|
||||
|
||||
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
|
||||
|
||||
@@ -19,7 +19,7 @@ _log = logging.getLogger(__name__)
|
||||
|
||||
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)
|
||||
@@ -192,7 +192,7 @@ class DoclingParseDocumentBackend(PdfDocumentBackend):
|
||||
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):
|
||||
|
||||
@@ -26,9 +26,9 @@ class DoclingParseV2PageBackend(PdfPageBackend):
|
||||
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}."
|
||||
@@ -223,7 +223,15 @@ class DoclingParseV2DocumentBackend(PdfDocumentBackend):
|
||||
)
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user