DawnC commited on
Commit
5ed8603
·
1 Parent(s): a2da3d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
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
  buttons_html = ""
310
 
311
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
@@ -325,22 +325,23 @@ async def predict(image):
325
  elif combined_confidence >= 0.15:
326
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
327
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
328
- # 確保這裡只附加列表,不會顯示連在一起的品種名稱
329
  dogs_info += f"<li><strong>{breed}</strong> ({float(prob.replace('%', '')):.2f}% confidence)</li>"
330
- dogs_info += "</ul>"
331
 
332
- # 每隻狗的按鈕生成部分
333
- buttons_html = '<div class="breed-buttons">'
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
  else:
340
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
341
-
342
- dogs_info += buttons_html # 確保按鈕與該狗的資訊一起顯示
343
- dogs_info += '</div>' # 關閉該隻狗的資訊區塊
344
 
345
 
346
  html_output = f"""
 
305
  dogs_info = ""
306
 
307
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
308
+ # 每次迭代前重設 buttons_html 和 dogs_info 以避免累積
309
  buttons_html = ""
310
 
311
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
 
325
  elif combined_confidence >= 0.15:
326
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
327
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
328
+ # 確保這裡只會顯示正確的列表,不附加多餘的品種名稱
329
  dogs_info += f"<li><strong>{breed}</strong> ({float(prob.replace('%', '')):.2f}% confidence)</li>"
330
+ dogs_info += "</ul>"
331
 
332
+ # 每隻狗生成單獨的按鈕
333
+ buttons_html = '<div class="breed-buttons">'
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
  else:
341
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
342
+
343
+ dogs_info += buttons_html # 確保按鈕附加在該狗的結果中
344
+ dogs_info += '</div>' # 關閉該狗的資訊區塊
345
 
346
 
347
  html_output = f"""