perlarsson commited on
Commit
54a5940
1 Parent(s): 6c46d60

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -94,11 +94,17 @@ def add_label_to_image(image, prediction, confidence):
94
  rect_height = int(img_height * 0.15)
95
  rect_width = img_width - (padding * 2)
96
 
97
- # Draw red rectangle
 
 
 
 
 
 
98
  cv2.rectangle(img_cv,
99
  (padding, padding),
100
  (padding + rect_width, padding + rect_height),
101
- (0, 0, 255),
102
  -1)
103
 
104
  text = f"{prediction}: {confidence}"
 
94
  rect_height = int(img_height * 0.15)
95
  rect_width = img_width - (padding * 2)
96
 
97
+ # Convert confidence percentage string to float
98
+ confidence_value = float(confidence.strip('%'))
99
+
100
+ # Set color based on confidence (BGR format)
101
+ rect_color = (0, 255, 0) if confidence_value >= 80 else (0, 0, 255) # Green if >=80%, Red otherwise
102
+
103
+ # Draw colored rectangle
104
  cv2.rectangle(img_cv,
105
  (padding, padding),
106
  (padding + rect_width, padding + rect_height),
107
+ rect_color,
108
  -1)
109
 
110
  text = f"{prediction}: {confidence}"