mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-27 04:24:45 +00:00
Enabled figure support in vlm_pipeline
Signed-off-by: Maksym Lysak <mly@zurich.ibm.com>
This commit is contained in:
parent
1b968e4984
commit
ef079e4e78
@ -155,7 +155,7 @@ class VlmPipeline(PaginatedPipeline):
|
|||||||
|
|
||||||
# def _turn_tags_into_doc(self, xml_content: str, image_bytes: bytes) -> (DoclingDocument, list):
|
# def _turn_tags_into_doc(self, xml_content: str, image_bytes: bytes) -> (DoclingDocument, list):
|
||||||
def _turn_tags_into_doc(
|
def _turn_tags_into_doc(
|
||||||
self, xml_content: str, input_image: Optional[Image] = None
|
self, xml_content: str, pil_image: Optional[Image] = None
|
||||||
) -> DoclingDocument:
|
) -> DoclingDocument:
|
||||||
def extract_text(tag_content: str) -> str:
|
def extract_text(tag_content: str) -> str:
|
||||||
return re.sub(r"<.*?>", "", tag_content).strip()
|
return re.sub(r"<.*?>", "", tag_content).strip()
|
||||||
@ -457,23 +457,27 @@ class VlmPipeline(PaginatedPipeline):
|
|||||||
bbox = extract_bounding_box(line)
|
bbox = extract_bounding_box(line)
|
||||||
if bbox:
|
if bbox:
|
||||||
bounding_boxes.append((bbox, "yellow"))
|
bounding_boxes.append((bbox, "yellow"))
|
||||||
# Convert bounding box normalized to 0-100 into pixel coordinates for cropping
|
if pil_image:
|
||||||
"""
|
# Convert bounding box normalized to 0-100 into pixel coordinates for cropping
|
||||||
width, height = pil_image.size
|
width, height = pil_image.size
|
||||||
crop_box = (
|
crop_box = (
|
||||||
int(bbox.l * width),
|
int(bbox.l * width),
|
||||||
int(bbox.t * height),
|
int(bbox.t * height),
|
||||||
int(bbox.r * width),
|
int(bbox.r * width),
|
||||||
int(bbox.b * height),
|
int(bbox.b * height),
|
||||||
)
|
)
|
||||||
|
|
||||||
cropped_image = pil_image.crop(crop_box)
|
cropped_image = pil_image.crop(crop_box)
|
||||||
doc.add_picture(
|
doc.add_picture(
|
||||||
parent=current_group,
|
parent=current_group,
|
||||||
image=ImageRef.from_pil(image=cropped_image, dpi=300),
|
image=ImageRef.from_pil(image=cropped_image, dpi=300),
|
||||||
prov=ProvenanceItem(bbox=bbox, charspan=(0, 0), page_no=1),
|
prov=ProvenanceItem(bbox=bbox, charspan=(0, 0), page_no=1),
|
||||||
)
|
)
|
||||||
"""
|
else:
|
||||||
|
doc.add_picture(
|
||||||
|
parent=current_group,
|
||||||
|
prov=ProvenanceItem(bbox=bbox, charspan=(0, 0), page_no=1),
|
||||||
|
)
|
||||||
elif line.startswith("<list>"):
|
elif line.startswith("<list>"):
|
||||||
content = extract_text(line)
|
content = extract_text(line)
|
||||||
prov_item_inst = None
|
prov_item_inst = None
|
||||||
|
Loading…
Reference in New Issue
Block a user