DawnC commited on
Commit
4ef836e
·
1 Parent(s): 98dff0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -371,7 +371,7 @@ async def predict(image):
371
  dogs_info = ""
372
 
373
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
374
- buttons_html = ""
375
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
376
  color = color_list[i % len(color_list)]
377
  draw.rectangle(box, outline=color, width=3)
@@ -385,27 +385,28 @@ async def predict(image):
385
  breed = topk_breeds[0]
386
  description = get_dog_description(breed)
387
  dogs_info += format_description_html(description, breed)
388
-
389
  elif combined_confidence >= 0.15:
390
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
391
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
392
  prob = float(prob.replace('%', ''))
393
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
394
- dogs_info += "</ul>"
395
-
396
- for breed in topk_breeds[:3]:
397
  button_id = f"Dog {i+1}: More about {breed}"
398
- buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
399
  buttons.append(button_id)
400
-
401
- # 確保按鈕插入在品種列表內部
402
- dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
403
-
 
 
404
  else:
405
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
406
-
407
  dogs_info += '</div>' # 結束當前狗的資訊區塊
408
 
 
409
  # 確保 `html_output` 有賦值
410
  html_output = f"""
411
  <style>
 
371
  dogs_info = ""
372
 
373
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
374
+ buttons_html = "" # 每次迴圈重置按鈕 HTML
375
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
376
  color = color_list[i % len(color_list)]
377
  draw.rectangle(box, outline=color, width=3)
 
385
  breed = topk_breeds[0]
386
  description = get_dog_description(breed)
387
  dogs_info += format_description_html(description, breed)
 
388
  elif combined_confidence >= 0.15:
389
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
390
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
391
  prob = float(prob.replace('%', ''))
392
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
393
+
394
+ # 生成與每個品種對應的按鈕,緊隨其後
 
395
  button_id = f"Dog {i+1}: More about {breed}"
396
+ buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button> '
397
  buttons.append(button_id)
398
+
399
+ dogs_info += "</ul>"
400
+
401
+ # 將每個按鈕嵌入到每個品種描述下方
402
+ dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
403
+
404
  else:
405
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
406
+
407
  dogs_info += '</div>' # 結束當前狗的資訊區塊
408
 
409
+
410
  # 確保 `html_output` 有賦值
411
  html_output = f"""
412
  <style>