mattraj commited on
Commit
b8a30eb
·
verified ·
1 Parent(s): 437ecef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -10,6 +10,7 @@ import re
10
  import numpy as np
11
  import spaces
12
  from PIL import Image, ImageDraw
 
13
 
14
  model_id = "mattraj/curacel-autodamage-1"
15
  COLORS = ['#4285f4', '#db4437', '#f4b400', '#0f9d58', '#e48ef1']
@@ -50,12 +51,25 @@ def infer(
50
  def extract_bounding_boxes(result):
51
  """
52
  Extract bounding boxes and labels from the model result.
53
- Placeholder logic - replace this with actual parsing logic from model output.
54
 
55
  Example return: [((x1, y1, x2, y2), "Label")]
56
  """
57
- # Example static bounding box and label
58
- return [((50, 50, 200, 200), "Damage"), ((300, 300, 400, 400), "Dent")]
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  ######## Demo
61
 
 
10
  import numpy as np
11
  import spaces
12
  from PIL import Image, ImageDraw
13
+ import re
14
 
15
  model_id = "mattraj/curacel-autodamage-1"
16
  COLORS = ['#4285f4', '#db4437', '#f4b400', '#0f9d58', '#e48ef1']
 
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
+ x1, y1 = int(match[0][:2]), int(match[0][2:])
67
+ x2, y2 = int(match[1][:2]), int(match[1][2:])
68
+ label = match[2].strip()
69
+
70
+ bounding_boxes.append(((x1, y1, x2, y2), label))
71
+
72
+ return bounding_boxes
73
 
74
  ######## Demo
75