Spaces:
Sleeping
Sleeping
perlarsson
commited on
Commit
•
54a5940
1
Parent(s):
6c46d60
Upload folder using huggingface_hub
Browse files
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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
cv2.rectangle(img_cv,
|
99 |
(padding, padding),
|
100 |
(padding + rect_width, padding + rect_height),
|
101 |
-
|
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}"
|