DawnC commited on
Commit
8748639
·
1 Parent(s): 1101544

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -366,7 +366,8 @@ async def predict(image):
366
  dogs_info = ""
367
 
368
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
369
- buttons_html = "" # 保證每個品種都單獨生成按鈕
 
370
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
371
  color = color_list[i % len(color_list)]
372
  draw.rectangle(box, outline=color, width=3)
@@ -388,21 +389,19 @@ async def predict(image):
388
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
389
  dogs_info += "</ul>"
390
 
391
- # 在該品種下生成按鈕
392
- buttons_html = '<div class="breed-buttons">' # 新增按鈕容器
393
  for breed in topk_breeds[:3]:
394
  button_id = f"Dog {i+1}: More about {breed}"
395
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
396
  buttons.append(button_id)
397
- buttons_html += '</div>' # 結束按鈕容器
398
- dogs_info += buttons_html # 將按鈕添加到品種描述中
 
399
 
400
  else:
401
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
402
 
403
- dogs_info += '</div>' # 結束該品種區塊
404
-
405
- # 不要在此重新加上 buttons_html,確保按鈕在品種下方顯示
406
  html_output = f"""
407
  <style>
408
  .dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
@@ -451,6 +450,7 @@ async def predict(image):
451
  print(error_msg)
452
  return error_msg, None, gr.update(visible=False, choices=[]), None
453
 
 
454
 
455
 
456
  def show_details_html(choice, previous_output, initial_state):
 
366
  dogs_info = ""
367
 
368
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
369
+ # buttons_html 與每個品種的區塊綁定
370
+ buttons_html = ""
371
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
372
  color = color_list[i % len(color_list)]
373
  draw.rectangle(box, outline=color, width=3)
 
389
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
390
  dogs_info += "</ul>"
391
 
 
 
392
  for breed in topk_breeds[:3]:
393
  button_id = f"Dog {i+1}: More about {breed}"
394
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
395
  buttons.append(button_id)
396
+
397
+ # 在該品種區塊中顯示按鈕
398
+ dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
399
 
400
  else:
401
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
402
 
403
+ dogs_info += '</div>'
404
+
 
405
  html_output = f"""
406
  <style>
407
  .dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
 
450
  print(error_msg)
451
  return error_msg, None, gr.update(visible=False, choices=[]), None
452
 
453
+
454
 
455
 
456
  def show_details_html(choice, previous_output, initial_state):