Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -305,7 +305,7 @@ async def predict(image):
|
|
305 |
dogs_info = ""
|
306 |
|
307 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
308 |
-
buttons_html = "" #
|
309 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
310 |
color = color_list[i % len(color_list)]
|
311 |
draw.rectangle(box, outline=color, width=3)
|
@@ -327,7 +327,7 @@ async def predict(image):
|
|
327 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
328 |
dogs_info += "</ul>"
|
329 |
|
330 |
-
#
|
331 |
for breed in topk_breeds[:3]:
|
332 |
button_id = f"Dog {i+1}: More about {breed}"
|
333 |
buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
@@ -336,10 +336,13 @@ async def predict(image):
|
|
336 |
else:
|
337 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
338 |
|
339 |
-
dogs_info += '</div>' #
|
340 |
|
341 |
-
#
|
342 |
-
|
|
|
|
|
|
|
343 |
|
344 |
|
345 |
|
|
|
305 |
dogs_info = ""
|
306 |
|
307 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
308 |
+
buttons_html = "" # 初始化buttons_html,防止累積
|
309 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
310 |
color = color_list[i % len(color_list)]
|
311 |
draw.rectangle(box, outline=color, width=3)
|
|
|
327 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
328 |
dogs_info += "</ul>"
|
329 |
|
330 |
+
# 清空 buttons_html 以防累積
|
331 |
for breed in topk_breeds[:3]:
|
332 |
button_id = f"Dog {i+1}: More about {breed}"
|
333 |
buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
|
|
336 |
else:
|
337 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
338 |
|
339 |
+
dogs_info += '</div>' # 關閉這個狗的div
|
340 |
|
341 |
+
dogs_info += buttons_html # 加入本次的buttons_html
|
342 |
+
|
343 |
+
# 確保在每次處理一隻狗後重置,防止累積
|
344 |
+
buttons_html = ""
|
345 |
+
|
346 |
|
347 |
|
348 |
|