Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -556,7 +556,8 @@ async def predict(image):
|
|
556 |
|
557 |
|
558 |
dogs_info = ""
|
559 |
-
|
|
|
560 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
561 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
562 |
color = color_list[i % len(color_list)]
|
@@ -564,33 +565,34 @@ async def predict(image):
|
|
564 |
draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
|
565 |
|
566 |
combined_confidence = detection_confidence * top1_prob
|
567 |
-
|
568 |
-
|
569 |
|
570 |
if top1_prob >= 0.45:
|
571 |
breed = topk_breeds[0]
|
572 |
description = get_dog_description(breed)
|
573 |
-
|
574 |
|
575 |
elif combined_confidence >= 0.15:
|
576 |
-
|
577 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
578 |
-
|
579 |
-
|
580 |
|
581 |
# ηζζι HTML
|
582 |
-
|
583 |
for breed in topk_breeds[:3]:
|
584 |
button_id = f"Dog {i+1}: More about {breed}"
|
585 |
-
|
586 |
buttons.append(button_id)
|
587 |
-
|
588 |
-
dogs_info += buttons_html # ε°ζιη΄ζ₯ε ε
₯ε°θ©²ι»ηηθ³θ¨δΈ
|
589 |
|
590 |
else:
|
591 |
-
|
|
|
|
|
592 |
|
593 |
-
dogs_info +=
|
594 |
|
595 |
|
596 |
|
|
|
556 |
|
557 |
|
558 |
dogs_info = ""
|
559 |
+
buttons = [] # ε° buttons η§»ε°εΎͺη°ε€ι¨εε§ε
|
560 |
+
|
561 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
562 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
563 |
color = color_list[i % len(color_list)]
|
|
|
565 |
draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
|
566 |
|
567 |
combined_confidence = detection_confidence * top1_prob
|
568 |
+
dog_info = f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
569 |
+
dog_info += f'<h2>Dog {i+1}</h2>'
|
570 |
|
571 |
if top1_prob >= 0.45:
|
572 |
breed = topk_breeds[0]
|
573 |
description = get_dog_description(breed)
|
574 |
+
dog_info += format_description_html(description, breed)
|
575 |
|
576 |
elif combined_confidence >= 0.15:
|
577 |
+
dog_info += f"<p>Top 3 possible breeds:</p><ul>"
|
578 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
579 |
+
dog_info += f"<li><strong>{breed}</strong> ({prob} confidence)</li>"
|
580 |
+
dog_info += "</ul>"
|
581 |
|
582 |
# ηζζι HTML
|
583 |
+
dog_info += '<div class="breed-buttons">'
|
584 |
for breed in topk_breeds[:3]:
|
585 |
button_id = f"Dog {i+1}: More about {breed}"
|
586 |
+
dog_info += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
587 |
buttons.append(button_id)
|
588 |
+
dog_info += '</div>'
|
|
|
589 |
|
590 |
else:
|
591 |
+
dog_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
592 |
+
|
593 |
+
dog_info += '</div>' # ιιθ©²ι»ηηθ³θ¨εε‘
|
594 |
|
595 |
+
dogs_info += dog_info # ε°ιι»ηηδΏ‘ζ―ζ·»ε ε°ηΈ½η dogs_info δΈ
|
596 |
|
597 |
|
598 |
|