mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-30 14:04:27 +00:00
Update imports for docling_parse.pdf_parser_v1
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
This commit is contained in:
parent
b8796e6705
commit
9204d5e79f
@ -6,7 +6,7 @@ from typing import Iterable, List, Optional, Union
|
|||||||
|
|
||||||
import pypdfium2 as pdfium
|
import pypdfium2 as pdfium
|
||||||
from docling_core.types.doc import BoundingBox, CoordOrigin, Size
|
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 PIL import Image, ImageDraw
|
||||||
from pypdfium2 import PdfPage
|
from pypdfium2 import PdfPage
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ _log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class DoclingParsePageBackend(PdfPageBackend):
|
class DoclingParsePageBackend(PdfPageBackend):
|
||||||
def __init__(
|
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
|
self._ppage = page_obj
|
||||||
parsed_page = parser.parse_pdf_from_key_on_page(document_hash, page_no)
|
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)
|
super().__init__(in_doc, path_or_stream)
|
||||||
|
|
||||||
self._pdoc = pdfium.PdfDocument(self.path_or_stream)
|
self._pdoc = pdfium.PdfDocument(self.path_or_stream)
|
||||||
self.parser = pdf_parser()
|
self.parser = pdf_parser_v1()
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
if isinstance(self.path_or_stream, BytesIO):
|
if isinstance(self.path_or_stream, BytesIO):
|
||||||
|
@ -26,7 +26,7 @@ class DoclingParseV2PageBackend(PdfPageBackend):
|
|||||||
self._ppage = page_obj
|
self._ppage = page_obj
|
||||||
parsed_page = parser.parse_pdf_from_key_on_page(document_hash, page_no)
|
parsed_page = parser.parse_pdf_from_key_on_page(document_hash, page_no)
|
||||||
|
|
||||||
self.valid = "pages" in parsed_page and len(parsed_page["pages"])==1
|
self.valid = "pages" in parsed_page and len(parsed_page["pages"]) == 1
|
||||||
if self.valid:
|
if self.valid:
|
||||||
self._dpage = parsed_page["pages"][0]
|
self._dpage = parsed_page["pages"][0]
|
||||||
else:
|
else:
|
||||||
@ -223,16 +223,16 @@ class DoclingParseV2DocumentBackend(PdfDocumentBackend):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def page_count(self) -> int:
|
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_1 = len(self._pdoc)
|
||||||
len_2 = self.parser.number_of_pages(self.document_hash)
|
len_2 = self.parser.number_of_pages(self.document_hash)
|
||||||
|
|
||||||
if len_1!=len_2:
|
if len_1 != len_2:
|
||||||
_log.error(f"Inconsistent number of pages: {len_1}!={len_2}")
|
_log.error(f"Inconsistent number of pages: {len_1}!={len_2}")
|
||||||
|
|
||||||
return len_2
|
return len_2
|
||||||
|
|
||||||
def load_page(self, page_no: int) -> DoclingParseV2PageBackend:
|
def load_page(self, page_no: int) -> DoclingParseV2PageBackend:
|
||||||
return DoclingParseV2PageBackend(
|
return DoclingParseV2PageBackend(
|
||||||
self.parser, self.document_hash, page_no, self._pdoc[page_no]
|
self.parser, self.document_hash, page_no, self._pdoc[page_no]
|
||||||
|
Loading…
Reference in New Issue
Block a user