Fix force_backend_text

Signed-off-by: Krishnan Raghavan <krishnanraghavan@Krishnans-MacBook-Air.local>
This commit is contained in:
Krishnan Raghavan 2025-04-13 23:05:10 +05:30
parent 415b877984
commit 592037324b

View File

@ -139,25 +139,23 @@ class VlmPipeline(PaginatedPipeline):
conv_res.document.load_from_doctags(doctags_doc) conv_res.document.load_from_doctags(doctags_doc)
# If forced backend text, replace model predicted text with backend one # If forced backend text, replace model predicted text with backend one
if page.size: if self.force_backend_text:
if self.force_backend_text: scale = self.pipeline_options.images_scale
scale = self.pipeline_options.images_scale for element, _level in conv_res.document.iterate_items():
for element, _level in conv_res.document.iterate_items(): if not isinstance(element, TextItem) or len(element.prov) == 0:
if ( continue
not isinstance(element, TextItem) page_ix = element.prov[0].page_no - 1
or len(element.prov) == 0 page = conv_res.pages[page_ix]
): if not page.size:
continue continue
crop_bbox = ( crop_bbox = (
element.prov[0] element.prov[0]
.bbox.scaled(scale=scale) .bbox.scaled(scale=scale)
.to_top_left_origin( .to_top_left_origin(page_height=page.size.height * scale)
page_height=page.size.height * scale )
) txt = self.extract_text_from_backend(page, crop_bbox)
) element.text = txt
txt = self.extract_text_from_backend(page, crop_bbox) element.orig = txt
element.text = txt
element.orig = txt
elif ( elif (
self.pipeline_options.vlm_options.response_format self.pipeline_options.vlm_options.response_format
== ResponseFormat.MARKDOWN == ResponseFormat.MARKDOWN