mattraj commited on
Commit
b103f0e
1 Parent(s): fe44ad8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
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
- Each bounding box is represented by two locXXXX tags and a label.
 
55
 
56
  Example return: [((x1, y1, x2, y2), "Label")]
57
  """
58
- bounding_boxes = []
 
59
 
60
- # Regular expression to find <locXXXX> tags and labels
61
- pattern = re.compile(r'<loc(\d{4})><loc(\d{4})>\s*(\S.+?)\s*(?=<loc|\Z)')
62
 
63
- matches = pattern.findall(result)
64
 
65
  for match in matches:
66
- # Extract x1, y1 from the first loc tag
67
- x1, y1 = int(match[0][:2]), int(match[0][2:])
68
 
69
- # Extract x2, y2 from the second loc tag
70
- x2, y2 = int(match[1][:2]), int(match[1][2:])
71
 
72
- # Get the label
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