Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -261,6 +261,41 @@ async def predict(image):
|
|
261 |
|
262 |
dogs_info = ""
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
265 |
buttons_html = ""
|
266 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
@@ -276,7 +311,6 @@ async def predict(image):
|
|
276 |
breed = topk_breeds[0]
|
277 |
description = get_dog_description(breed)
|
278 |
dogs_info += format_description_html(description, breed)
|
279 |
-
|
280 |
elif combined_confidence >= 0.15:
|
281 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
282 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
@@ -292,7 +326,9 @@ async def predict(image):
|
|
292 |
else:
|
293 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
294 |
|
|
|
295 |
dogs_info += '</div>'
|
|
|
296 |
|
297 |
buttons_html = ""
|
298 |
|
|
|
261 |
|
262 |
dogs_info = ""
|
263 |
|
264 |
+
# for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
265 |
+
# buttons_html = ""
|
266 |
+
# top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
267 |
+
# color = color_list[i % len(color_list)]
|
268 |
+
# draw.rectangle(box, outline=color, width=3)
|
269 |
+
# draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
|
270 |
+
|
271 |
+
# combined_confidence = detection_confidence * top1_prob
|
272 |
+
# dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
273 |
+
# dogs_info += f'<h2>Dog {i+1}</h2>'
|
274 |
+
|
275 |
+
# if top1_prob >= 0.45:
|
276 |
+
# breed = topk_breeds[0]
|
277 |
+
# description = get_dog_description(breed)
|
278 |
+
# dogs_info += format_description_html(description, breed)
|
279 |
+
|
280 |
+
# elif combined_confidence >= 0.15:
|
281 |
+
# dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
282 |
+
# for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
283 |
+
# prob = float(prob.replace('%', ''))
|
284 |
+
# dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
285 |
+
# dogs_info += "</ul>"
|
286 |
+
|
287 |
+
# for breed in topk_breeds[:3]:
|
288 |
+
# button_id = f"Dog {i+1}: More about {breed}"
|
289 |
+
# buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
290 |
+
# buttons.append(button_id)
|
291 |
+
|
292 |
+
# else:
|
293 |
+
# dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
294 |
+
|
295 |
+
# dogs_info += '</div>'
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
300 |
buttons_html = ""
|
301 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
|
|
311 |
breed = topk_breeds[0]
|
312 |
description = get_dog_description(breed)
|
313 |
dogs_info += format_description_html(description, breed)
|
|
|
314 |
elif combined_confidence >= 0.15:
|
315 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
316 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
|
|
326 |
else:
|
327 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
328 |
|
329 |
+
dogs_info += f'<div class="breed-buttons">{buttons_html}</div>' # 在每個dog-info內插入buttons_html
|
330 |
dogs_info += '</div>'
|
331 |
+
|
332 |
|
333 |
buttons_html = ""
|
334 |
|