geekyrakshit commited on
Commit
76f0b82
·
1 Parent(s): fd0aa67

update: FigureAnnotatorFromPageImage

Browse files
medrag_multi_modal/assistant/figure_annotation.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  from typing import Union
3
 
4
  import cv2
@@ -69,12 +70,22 @@ Here are some clues you need to follow:
69
  annotations = []
70
  for item in track(metadata, description="Annotating images:"):
71
  page_image_file = os.path.join(artifact_dir, f"page{item['page_idx']}.png")
72
- page_image = cv2.imread(page_image_file)
73
- page_image = cv2.cvtColor(page_image, cv2.COLOR_BGR2RGB)
74
- page_image = Image.fromarray(page_image)
75
- figure_extracted_annotations = self.annotate_figures(page_image=page_image)
76
- figure_extracted_annotations["annotations"] = self.extract_structured_output(
77
- figure_extracted_annotations["annotations"]
78
- ).model_dump()
79
- annotations.append(figure_extracted_annotations)
 
 
 
 
 
 
 
 
 
 
80
  return annotations
 
1
  import os
2
+ from glob import glob
3
  from typing import Union
4
 
5
  import cv2
 
70
  annotations = []
71
  for item in track(metadata, description="Annotating images:"):
72
  page_image_file = os.path.join(artifact_dir, f"page{item['page_idx']}.png")
73
+ figure_image_files = glob(
74
+ os.path.join(artifact_dir, f"page{item['page_idx']}_fig*.png")
75
+ )
76
+ if len(figure_image_files) > 0:
77
+ page_image = cv2.imread(page_image_file)
78
+ page_image = cv2.cvtColor(page_image, cv2.COLOR_BGR2RGB)
79
+ page_image = Image.fromarray(page_image)
80
+ figure_extracted_annotations = self.annotate_figures(
81
+ page_image=page_image
82
+ )
83
+ annotations.append(
84
+ {
85
+ "page_idx": item["page_idx"],
86
+ "annotations": self.extract_structured_output(
87
+ figure_extracted_annotations["annotations"]
88
+ ).model_dump(),
89
+ }
90
+ )
91
  return annotations