Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,22 @@ def draw_bounding_boxes(image, bounding_boxes, outline_color="red", line_width=2
|
|
| 35 |
return image
|
| 36 |
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
@spaces.GPU
|
| 39 |
def run_example(image, text_input, model_id="Qwen/Qwen2-VL-7B-Instruct"):
|
| 40 |
model = models[model_id].eval()
|
|
@@ -75,7 +91,8 @@ def run_example(image, text_input, model_id="Qwen/Qwen2-VL-7B-Instruct"):
|
|
| 75 |
pattern = r'\[\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\]'
|
| 76 |
matches = re.findall(pattern, str(output_text))
|
| 77 |
parsed_boxes = [[int(num) for num in match] for match in matches]
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
css = """
|
| 81 |
#output {
|
|
|
|
| 35 |
return image
|
| 36 |
|
| 37 |
|
| 38 |
+
def rescale_bounding_boxes(bounding_boxes, original_width, original_height, scaled_width=1000, scaled_height=1000):
|
| 39 |
+
x_scale = original_width / scaled_width
|
| 40 |
+
y_scale = original_height / scaled_height
|
| 41 |
+
rescaled_boxes = []
|
| 42 |
+
for box in bounding_boxes:
|
| 43 |
+
xmin, xmax, ymin, ymax = box
|
| 44 |
+
rescaled_box = [
|
| 45 |
+
xmin * x_scale,
|
| 46 |
+
xmax * x_scale,
|
| 47 |
+
ymin * y_scale,
|
| 48 |
+
ymax * y_scale
|
| 49 |
+
]
|
| 50 |
+
rescaled_boxes.append(rescaled_box)
|
| 51 |
+
return rescaled_boxes
|
| 52 |
+
|
| 53 |
+
|
| 54 |
@spaces.GPU
|
| 55 |
def run_example(image, text_input, model_id="Qwen/Qwen2-VL-7B-Instruct"):
|
| 56 |
model = models[model_id].eval()
|
|
|
|
| 91 |
pattern = r'\[\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\]'
|
| 92 |
matches = re.findall(pattern, str(output_text))
|
| 93 |
parsed_boxes = [[int(num) for num in match] for match in matches]
|
| 94 |
+
scaled_boxes = rescale_bounding_boxes(parsed_boxes)
|
| 95 |
+
return output_text, parsed_boxes, draw_bounding_boxes(image, scaled_boxes)
|
| 96 |
|
| 97 |
css = """
|
| 98 |
#output {
|