DawnC commited on
Commit
b9dd119
·
1 Parent(s): 1048894

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -297,7 +297,7 @@ async def predict(image):
297
 
298
 
299
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
300
- buttons_html = ""
301
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
302
  color = color_list[i % len(color_list)]
303
  draw.rectangle(box, outline=color, width=3)
@@ -318,16 +318,19 @@ async def predict(image):
318
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
319
  dogs_info += "</ul>"
320
 
 
321
  for breed in topk_breeds[:3]:
322
  button_id = f"Dog {i+1}: More about {breed}"
323
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
324
  buttons.append(button_id)
325
 
 
 
 
326
  else:
327
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
328
 
329
- dogs_info += f'<div class="breed-buttons">{buttons_html}</div>' # 在每個dog-info內插入buttons_html
330
- dogs_info += '</div>'
331
 
332
 
333
  buttons_html = ""
 
297
 
298
 
299
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
300
+ buttons_html = "" # 清空按鈕 HTML 變數
301
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
302
  color = color_list[i % len(color_list)]
303
  draw.rectangle(box, outline=color, width=3)
 
318
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
319
  dogs_info += "</ul>"
320
 
321
+ # 生成與品種對應的按鈕,並插入到描述後
322
  for breed in topk_breeds[:3]:
323
  button_id = f"Dog {i+1}: More about {breed}"
324
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
325
  buttons.append(button_id)
326
 
327
+ # 將按鈕放在該狗的描述之後
328
+ dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
329
+
330
  else:
331
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
332
 
333
+ dogs_info += '</div>' # 結束每個狗的資訊區塊
 
334
 
335
 
336
  buttons_html = ""