Update app.py
Browse files
app.py
CHANGED
@@ -71,16 +71,16 @@ st.markdown("""
|
|
71 |
|
72 |
.stButton > button {
|
73 |
width: 200px;
|
74 |
-
background-color: #
|
75 |
-
color:
|
76 |
-
border:
|
77 |
padding: 0.5rem 1rem !important;
|
78 |
border-radius: 5px !important;
|
79 |
transition: all 0.3s ease !important;
|
80 |
}
|
81 |
|
82 |
.stButton > button:hover {
|
83 |
-
background-color: #
|
84 |
transform: translateY(-1px);
|
85 |
}
|
86 |
|
@@ -119,79 +119,53 @@ def create_heatmap_overlay(image, box, score):
|
|
119 |
overlay = Image.new('RGBA', image.size, (0, 0, 0, 0))
|
120 |
draw = ImageDraw.Draw(overlay)
|
121 |
|
122 |
-
def get_temp_color(value):
|
123 |
-
if value > 0.8:
|
124 |
-
return (255, 0, 0) # Rouge vif
|
125 |
-
elif value > 0.6:
|
126 |
-
return (255, 69, 0) # Rouge-orange
|
127 |
-
elif value > 0.4:
|
128 |
-
return (255, 165, 0) # Orange
|
129 |
-
else:
|
130 |
-
return (255, 255, 0) # Jaune
|
131 |
-
|
132 |
x1, y1 = box['xmin'], box['ymin']
|
133 |
x2, y2 = box['xmax'], box['ymax']
|
134 |
-
width = x2 - x1
|
135 |
-
height = y2 - y1
|
136 |
|
137 |
-
#
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
outline=None
|
151 |
-
)
|
152 |
|
153 |
-
# Bordure
|
154 |
-
|
155 |
-
draw.rectangle([x1, y1, x2, y2], outline=border_color, width=3)
|
156 |
|
157 |
return overlay
|
158 |
|
159 |
def draw_boxes(image, predictions):
|
160 |
result_image = image.copy().convert('RGBA')
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
for pred in sorted_predictions:
|
165 |
box = pred['box']
|
166 |
score = pred['score']
|
167 |
|
168 |
-
#
|
169 |
-
|
170 |
-
result_image = Image.alpha_composite(result_image,
|
171 |
|
172 |
# Ajout du texte
|
173 |
draw = ImageDraw.Draw(result_image)
|
174 |
-
temp = 36.5 + (score * 2.5)
|
175 |
-
label = f"{translate_label(pred['label'])} ({score:.1%}
|
176 |
|
177 |
-
# Fond noir
|
178 |
-
text_bbox = draw.textbbox((box['xmin'], box['ymin']-
|
179 |
-
|
180 |
-
text_bbox = (
|
181 |
-
text_bbox[0]-padding,
|
182 |
-
text_bbox[1]-padding,
|
183 |
-
text_bbox[2]+padding,
|
184 |
-
text_bbox[3]+padding
|
185 |
-
)
|
186 |
-
draw.rectangle(text_bbox, fill="#000000CC")
|
187 |
|
188 |
-
# Texte en blanc
|
189 |
draw.text(
|
190 |
-
(box['xmin'], box['ymin']-
|
191 |
label,
|
192 |
-
fill=
|
193 |
-
stroke_width=1,
|
194 |
-
stroke_fill="#000000"
|
195 |
)
|
196 |
|
197 |
return result_image
|
|
|
71 |
|
72 |
.stButton > button {
|
73 |
width: 200px;
|
74 |
+
background-color: #f8f9fa !important;
|
75 |
+
color: #1a1a1a !important;
|
76 |
+
border: 1px solid #e9ecef !important;
|
77 |
padding: 0.5rem 1rem !important;
|
78 |
border-radius: 5px !important;
|
79 |
transition: all 0.3s ease !important;
|
80 |
}
|
81 |
|
82 |
.stButton > button:hover {
|
83 |
+
background-color: #e9ecef !important;
|
84 |
transform: translateY(-1px);
|
85 |
}
|
86 |
|
|
|
119 |
overlay = Image.new('RGBA', image.size, (0, 0, 0, 0))
|
120 |
draw = ImageDraw.Draw(overlay)
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
x1, y1 = box['xmin'], box['ymin']
|
123 |
x2, y2 = box['xmax'], box['ymax']
|
|
|
|
|
124 |
|
125 |
+
# Couleur basée sur le score
|
126 |
+
if score > 0.8:
|
127 |
+
fill_color = (255, 0, 0, 100) # Rouge
|
128 |
+
border_color = (255, 0, 0, 255)
|
129 |
+
elif score > 0.6:
|
130 |
+
fill_color = (255, 165, 0, 100) # Orange
|
131 |
+
border_color = (255, 165, 0, 255)
|
132 |
+
else:
|
133 |
+
fill_color = (255, 255, 0, 100) # Jaune
|
134 |
+
border_color = (255, 255, 0, 255)
|
135 |
+
|
136 |
+
# Rectangle semi-transparent
|
137 |
+
draw.rectangle([x1, y1, x2, y2], fill=fill_color)
|
|
|
|
|
138 |
|
139 |
+
# Bordure
|
140 |
+
draw.rectangle([x1, y1, x2, y2], outline=border_color, width=2)
|
|
|
141 |
|
142 |
return overlay
|
143 |
|
144 |
def draw_boxes(image, predictions):
|
145 |
result_image = image.copy().convert('RGBA')
|
146 |
|
147 |
+
for pred in predictions:
|
|
|
|
|
148 |
box = pred['box']
|
149 |
score = pred['score']
|
150 |
|
151 |
+
# Création de l'overlay
|
152 |
+
overlay = create_heatmap_overlay(image, box, score)
|
153 |
+
result_image = Image.alpha_composite(result_image, overlay)
|
154 |
|
155 |
# Ajout du texte
|
156 |
draw = ImageDraw.Draw(result_image)
|
157 |
+
temp = 36.5 + (score * 2.5)
|
158 |
+
label = f"{translate_label(pred['label'])} ({score:.1%} • {temp:.1f}°C)"
|
159 |
|
160 |
+
# Fond noir pour le texte
|
161 |
+
text_bbox = draw.textbbox((box['xmin'], box['ymin']-20), label)
|
162 |
+
draw.rectangle(text_bbox, fill=(0, 0, 0, 180))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
+
# Texte en blanc
|
165 |
draw.text(
|
166 |
+
(box['xmin'], box['ymin']-20),
|
167 |
label,
|
168 |
+
fill=(255, 255, 255, 255)
|
|
|
|
|
169 |
)
|
170 |
|
171 |
return result_image
|