Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -306,7 +306,6 @@ async def predict(image):
|
|
306 |
buttons_html = "" # 初始化 buttons_html
|
307 |
|
308 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
309 |
-
# 每次迭代初始化
|
310 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
311 |
color = color_list[i % len(color_list)]
|
312 |
draw.rectangle(box, outline=color, width=3)
|
@@ -321,7 +320,7 @@ async def predict(image):
|
|
321 |
breed = topk_breeds[0]
|
322 |
description = get_dog_description(breed)
|
323 |
dogs_info += format_description_html(description, breed)
|
324 |
-
|
325 |
elif combined_confidence >= 0.15:
|
326 |
# 多品種推測邏輯
|
327 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
@@ -330,24 +329,27 @@ async def predict(image):
|
|
330 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
331 |
dogs_info += "</ul>"
|
332 |
|
333 |
-
#
|
334 |
-
|
335 |
for breed in topk_breeds[:3]:
|
336 |
button_id = f"Dog {i+1}: More about {breed}"
|
337 |
-
|
338 |
buttons.append(button_id)
|
339 |
-
|
340 |
-
|
|
|
|
|
341 |
else:
|
342 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
343 |
|
344 |
dogs_info += '</div>' # 結束該狗的描述區塊
|
345 |
|
346 |
-
#
|
347 |
dogs_info += buttons_html
|
348 |
|
349 |
|
350 |
|
|
|
351 |
|
352 |
|
353 |
html_output = f"""
|
|
|
306 |
buttons_html = "" # 初始化 buttons_html
|
307 |
|
308 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
|
|
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)
|
|
|
320 |
breed = topk_breeds[0]
|
321 |
description = get_dog_description(breed)
|
322 |
dogs_info += format_description_html(description, breed)
|
323 |
+
|
324 |
elif combined_confidence >= 0.15:
|
325 |
# 多品種推測邏輯
|
326 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
|
|
329 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
330 |
dogs_info += "</ul>"
|
331 |
|
332 |
+
# 單獨生成按鈕,按鈕生成邏輯完全獨立
|
333 |
+
temp_buttons = '<div class="breed-buttons">' # 初始化每次生成的按鈕
|
334 |
for breed in topk_breeds[:3]:
|
335 |
button_id = f"Dog {i+1}: More about {breed}"
|
336 |
+
temp_buttons += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
337 |
buttons.append(button_id)
|
338 |
+
temp_buttons += '</div>'
|
339 |
+
|
340 |
+
buttons_html += temp_buttons # 將本次生成的按鈕附加到 buttons_html 中
|
341 |
+
|
342 |
else:
|
343 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
344 |
|
345 |
dogs_info += '</div>' # 結束該狗的描述區塊
|
346 |
|
347 |
+
# 統一將按鈕部分附加到最後輸出,確保不與品種名稱混淆
|
348 |
dogs_info += buttons_html
|
349 |
|
350 |
|
351 |
|
352 |
+
|
353 |
|
354 |
|
355 |
html_output = f"""
|