Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,32 +51,30 @@ def infer(
|
|
51 |
def extract_bounding_boxes(result):
|
52 |
"""
|
53 |
Extract bounding boxes and labels from the model result.
|
54 |
-
|
|
|
55 |
|
56 |
Example return: [((x1, y1, x2, y2), "Label")]
|
57 |
"""
|
58 |
-
|
|
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
|
63 |
-
|
64 |
|
65 |
for match in matches:
|
66 |
-
|
67 |
-
x1, y1 = int(match[0][:2]), int(match[0][2:])
|
68 |
|
69 |
-
#
|
70 |
-
x2, y2 = int(
|
71 |
|
72 |
-
#
|
73 |
-
label = match[2].strip()
|
74 |
-
|
75 |
-
# Append the bounding box with the label
|
76 |
bounding_boxes.append(((x1, y1, x2, y2), label))
|
77 |
|
78 |
return bounding_boxes
|
79 |
-
|
80 |
######## Demo
|
81 |
|
82 |
INTRO_TEXT = """## Curacel Auto Damage demo\n\n
|
|
|
51 |
def extract_bounding_boxes(result):
|
52 |
"""
|
53 |
Extract bounding boxes and labels from the model result.
|
54 |
+
|
55 |
+
Extracts two x,y coordinate pairs from <loc> tags and associates them with the corresponding labels.
|
56 |
|
57 |
Example return: [((x1, y1, x2, y2), "Label")]
|
58 |
"""
|
59 |
+
# Regular expression to capture the <loc> tags and their associated labels
|
60 |
+
loc_pattern = re.compile(r"<loc(\d{4})><loc(\d{4})><loc(\d{4})><loc(\d{4})>\s*([a-zA-Z\-]+)")
|
61 |
|
62 |
+
# Find all matches of bounding box coordinates and labels in the result string
|
63 |
+
matches = loc_pattern.findall(result)
|
64 |
|
65 |
+
bounding_boxes = []
|
66 |
|
67 |
for match in matches:
|
68 |
+
x1, y1, x2, y2, label = match
|
|
|
69 |
|
70 |
+
# Convert coordinates from string to integer
|
71 |
+
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
|
72 |
|
73 |
+
# Append the bounding box and label as a tuple
|
|
|
|
|
|
|
74 |
bounding_boxes.append(((x1, y1, x2, y2), label))
|
75 |
|
76 |
return bounding_boxes
|
77 |
+
|
78 |
######## Demo
|
79 |
|
80 |
INTRO_TEXT = """## Curacel Auto Damage demo\n\n
|