Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -302,8 +302,9 @@ async def predict(image):
|
|
302 |
# dogs_info += buttons_html
|
303 |
|
304 |
|
305 |
-
dogs_info = ""
|
306 |
-
|
|
|
307 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
308 |
# 每次迭代初始化
|
309 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
@@ -316,11 +317,11 @@ async def predict(image):
|
|
316 |
dogs_info += f'<h2>Dog {i+1}</h2>'
|
317 |
|
318 |
if top1_prob >= 0.45:
|
319 |
-
#
|
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>"
|
@@ -328,22 +329,24 @@ async def predict(image):
|
|
328 |
prob = float(prob.replace('%', '')) # 去掉百分比符號並轉為浮點數
|
329 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
330 |
dogs_info += "</ul>"
|
331 |
-
|
332 |
-
#
|
333 |
-
buttons_html
|
334 |
for breed in topk_breeds[:3]:
|
335 |
button_id = f"Dog {i+1}: More about {breed}"
|
336 |
buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
337 |
buttons.append(button_id)
|
338 |
buttons_html += '</div>'
|
339 |
-
|
340 |
-
# 返回按鈕區塊作為分離的部分
|
341 |
-
dogs_info += buttons_html
|
342 |
-
|
343 |
else:
|
344 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
345 |
|
346 |
dogs_info += '</div>' # 結束該狗的描述區塊
|
|
|
|
|
|
|
|
|
|
|
347 |
|
348 |
|
349 |
html_output = f"""
|
|
|
302 |
# dogs_info += buttons_html
|
303 |
|
304 |
|
305 |
+
dogs_info = "" # 初始化dogs_info
|
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)
|
|
|
317 |
dogs_info += f'<h2>Dog {i+1}</h2>'
|
318 |
|
319 |
if top1_prob >= 0.45:
|
320 |
+
# 當信心 >= 0.45 顯示單一品種
|
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>"
|
|
|
329 |
prob = float(prob.replace('%', '')) # 去掉百分比符號並轉為浮點數
|
330 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
331 |
dogs_info += "</ul>"
|
332 |
+
|
333 |
+
# 單獨生成按鈕區塊
|
334 |
+
buttons_html += '<div class="breed-buttons">'
|
335 |
for breed in topk_breeds[:3]:
|
336 |
button_id = f"Dog {i+1}: More about {breed}"
|
337 |
buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
338 |
buttons.append(button_id)
|
339 |
buttons_html += '</div>'
|
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 |
html_output = f"""
|