MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / __call__

Method __call__

docling/models/ds_glm_model.py:316–386  ·  view source on GitHub ↗
(self, conv_res: ConversionResult)

Source from the content-addressed store, hash-verified

314 return ds_doc
315
316 def __call__(self, conv_res: ConversionResult) -> DoclingDocument:
317 with TimeRecorder(conv_res, "glm", scope=ProfilingScope.DOCUMENT):
318 ds_doc = self._to_legacy_document(conv_res)
319 ds_doc_dict = ds_doc.model_dump(by_alias=True, exclude_none=True)
320
321 glm_doc = self.model.apply_on_doc(ds_doc_dict)
322
323 docling_doc: DoclingDocument = to_docling_document(glm_doc) # Experimental
324 1 == 1
325
326 # DEBUG code:
327 def draw_clusters_and_cells(ds_document, page_no, show: bool = False):
328 clusters_to_draw = []
329 image = copy.deepcopy(conv_res.pages[page_no].image)
330 for ix, elem in enumerate(ds_document.main_text):
331 if isinstance(elem, BaseText):
332 prov = elem.prov[0] # type: ignore
333 elif isinstance(elem, Ref):
334 _, arr, index = elem.ref.split("/")
335 index = int(index) # type: ignore
336 if arr == "tables":
337 prov = ds_document.tables[index].prov[0]
338 elif arr == "figures":
339 prov = ds_document.pictures[index].prov[0]
340 else:
341 prov = None
342
343 if prov and prov.page == page_no:
344 clusters_to_draw.append(
345 Cluster(
346 id=ix,
347 label=elem.name,
348 bbox=BoundingBox.from_tuple(
349 coord=prov.bbox, # type: ignore
350 origin=CoordOrigin.BOTTOMLEFT,
351 ).to_top_left_origin(conv_res.pages[page_no].size.height),
352 )
353 )
354
355 draw = ImageDraw.Draw(image)
356 for c in clusters_to_draw:
357 x0, y0, x1, y1 = c.bbox.as_tuple()
358 draw.rectangle([(x0, y0), (x1, y1)], outline="red")
359 draw.text((x0 + 2, y0 + 2), f"{c.id}:{c.label}", fill=(255, 0, 0, 255))
360
361 cell_color = (
362 random.randint(30, 140),
363 random.randint(30, 140),
364 random.randint(30, 140),
365 )
366 for tc in c.cells: # [:1]:
367 x0, y0, x1, y1 = tc.bbox.as_tuple()
368 draw.rectangle([(x0, y0), (x1, y1)], outline=cell_color)
369
370 if show:
371 image.show()
372 else:
373 out_path: Path = (

Callers

nothing calls this directly

Calls 4

_to_legacy_documentMethod · 0.95
TimeRecorderClass · 0.90
to_docling_documentFunction · 0.90
model_dumpMethod · 0.45

Tested by

no test coverage detected