Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -62,10 +62,7 @@ def process(image_input: Image.Image, box_threshold: float, iou_threshold: float
|
|
62 |
image_save_path = "imgs/saved_image_demo.png"
|
63 |
os.makedirs(os.path.dirname(image_save_path), exist_ok=True)
|
64 |
image_input.save(image_save_path)
|
65 |
-
|
66 |
-
logger.info(f"Saved image for processing: {image_save_path}")
|
67 |
-
|
68 |
-
# Open image and prepare it for further processing
|
69 |
image = Image.open(image_save_path)
|
70 |
box_overlay_ratio = image.size[0] / 3200
|
71 |
draw_bbox_config = {
|
@@ -75,7 +72,6 @@ def process(image_input: Image.Image, box_threshold: float, iou_threshold: float
|
|
75 |
"thickness": max(int(3 * box_overlay_ratio), 1),
|
76 |
}
|
77 |
|
78 |
-
# OCR and YOLO box processing
|
79 |
ocr_bbox_rslt, is_goal_filtered = check_ocr_box(
|
80 |
image_save_path,
|
81 |
display_img=False,
|
@@ -86,29 +82,28 @@ def process(image_input: Image.Image, box_threshold: float, iou_threshold: float
|
|
86 |
)
|
87 |
text, ocr_bbox = ocr_bbox_rslt
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
iou_threshold=iou_threshold,
|
101 |
-
)
|
102 |
-
except Exception as e:
|
103 |
-
logger.error(f"Error during labeling and captioning: {e}")
|
104 |
-
raise
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
# Convert the image to base64 string
|
109 |
image = Image.open(io.BytesIO(base64.b64decode(dino_labled_img)))
|
110 |
-
|
111 |
|
|
|
112 |
buffered = io.BytesIO()
|
113 |
image.save(buffered, format="PNG")
|
114 |
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
@@ -119,6 +114,7 @@ def process(image_input: Image.Image, box_threshold: float, iou_threshold: float
|
|
119 |
label_coordinates=str(label_coordinates),
|
120 |
)
|
121 |
|
|
|
122 |
@app.post("/process_image", response_model=ProcessResponse)
|
123 |
async def process_image(
|
124 |
image_file: UploadFile = File(...),
|
|
|
62 |
image_save_path = "imgs/saved_image_demo.png"
|
63 |
os.makedirs(os.path.dirname(image_save_path), exist_ok=True)
|
64 |
image_input.save(image_save_path)
|
65 |
+
|
|
|
|
|
|
|
66 |
image = Image.open(image_save_path)
|
67 |
box_overlay_ratio = image.size[0] / 3200
|
68 |
draw_bbox_config = {
|
|
|
72 |
"thickness": max(int(3 * box_overlay_ratio), 1),
|
73 |
}
|
74 |
|
|
|
75 |
ocr_bbox_rslt, is_goal_filtered = check_ocr_box(
|
76 |
image_save_path,
|
77 |
display_img=False,
|
|
|
82 |
)
|
83 |
text, ocr_bbox = ocr_bbox_rslt
|
84 |
|
85 |
+
dino_labled_img, label_coordinates, parsed_content_list = get_som_labeled_img(
|
86 |
+
image_save_path,
|
87 |
+
yolo_model,
|
88 |
+
BOX_TRESHOLD=box_threshold,
|
89 |
+
output_coord_in_ratio=True,
|
90 |
+
ocr_bbox=ocr_bbox,
|
91 |
+
draw_bbox_config=draw_bbox_config,
|
92 |
+
caption_model_processor=caption_model_processor,
|
93 |
+
ocr_text=text,
|
94 |
+
iou_threshold=iou_threshold,
|
95 |
+
)
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
+
# Log parsed_content_list to inspect its structure before joining
|
98 |
+
logger.info(f"Parsed content list before join: {parsed_content_list}")
|
99 |
+
|
100 |
+
# Ensure parsed_content_list is a list of strings, not dictionaries
|
101 |
+
parsed_content_list_str = "\n".join([str(item) for item in parsed_content_list])
|
102 |
|
|
|
103 |
image = Image.open(io.BytesIO(base64.b64decode(dino_labled_img)))
|
104 |
+
print("Finish processing")
|
105 |
|
106 |
+
# Convert the image to base64
|
107 |
buffered = io.BytesIO()
|
108 |
image.save(buffered, format="PNG")
|
109 |
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
|
|
114 |
label_coordinates=str(label_coordinates),
|
115 |
)
|
116 |
|
117 |
+
|
118 |
@app.post("/process_image", response_model=ProcessResponse)
|
119 |
async def process_image(
|
120 |
image_file: UploadFile = File(...),
|