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)
|
@@ -323,22 +323,24 @@ async def predict(image):
|
|
323 |
elif combined_confidence >= 0.15:
|
324 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
325 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
326 |
-
prob = float(prob.replace('%', ''))
|
327 |
-
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
328 |
-
dogs_info += "</ul>"
|
329 |
|
|
|
330 |
for breed in topk_breeds[:3]:
|
331 |
button_id = f"Dog {i+1}: More about {breed}"
|
332 |
buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
333 |
buttons.append(button_id)
|
334 |
-
|
335 |
else:
|
336 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
337 |
-
|
338 |
-
dogs_info += '</div>'
|
339 |
-
|
340 |
-
#
|
341 |
-
dogs_info += buttons_html
|
|
|
342 |
|
343 |
|
344 |
|
|
|
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)
|
|
|
323 |
elif combined_confidence >= 0.15:
|
324 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
325 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
326 |
+
prob = float(prob.replace('%', ''))
|
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>'
|
334 |
buttons.append(button_id)
|
335 |
+
|
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>' # 關閉這個dog的div
|
340 |
+
|
341 |
+
# 確保每次只附加該dog的按鈕
|
342 |
+
dogs_info += buttons_html # 將 buttons_html 合併到每個狗的內容後
|
343 |
+
|
344 |
|
345 |
|
346 |
|