DawnC commited on
Commit
6924371
·
1 Parent(s): 0779590

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -531,7 +531,7 @@ async def predict(image):
531
  color = color_list[i % len(color_list)]
532
  draw.rectangle(box, outline=color, width=3)
533
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
534
-
535
  combined_confidence = detection_confidence * top1_prob
536
  html_output += f'<div class="dog-info" style="border-left: 5px solid {color};">'
537
  html_output += f'<h2>Dog {i+1}</h2>'
@@ -539,13 +539,14 @@ async def predict(image):
539
  if top1_prob >= 0.45:
540
  breed = topk_breeds[0]
541
  description = get_dog_description(breed)
542
- html_output += f"<p><strong>{breed}</strong> ({top1_prob:.2%} confidence)</p>"
543
  html_output += format_description_html(description, breed)
544
-
 
 
545
  elif combined_confidence >= 0.15:
546
- html_output += "<p>Top 3 possible breeds:</p><ul>"
547
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
548
- html_output += f"<li><strong>{breed}</strong> ({prob})</li>"
549
  html_output += "</ul>"
550
  html_output += '<div class="breed-buttons">'
551
  for breed in topk_breeds[:3]:
@@ -558,7 +559,6 @@ async def predict(image):
558
 
559
  html_output += '</div>'
560
 
561
-
562
  if buttons:
563
  html_output += """
564
  <script>
@@ -674,7 +674,7 @@ with gr.Blocks() as iface:
674
  )
675
 
676
  breed_buttons.change(
677
- show_details_html, # 確保這裡使用 show_details_html
678
  inputs=[breed_buttons, output, initial_state],
679
  outputs=[output, back_button, initial_state]
680
  )
 
531
  color = color_list[i % len(color_list)]
532
  draw.rectangle(box, outline=color, width=3)
533
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
534
+
535
  combined_confidence = detection_confidence * top1_prob
536
  html_output += f'<div class="dog-info" style="border-left: 5px solid {color};">'
537
  html_output += f'<h2>Dog {i+1}</h2>'
 
539
  if top1_prob >= 0.45:
540
  breed = topk_breeds[0]
541
  description = get_dog_description(breed)
 
542
  html_output += format_description_html(description, breed)
543
+ button_id = f"Dog {i+1}: More about {breed}"
544
+ html_output += f'<div class="breed-buttons"><button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button></div>'
545
+ buttons.append(button_id)
546
  elif combined_confidence >= 0.15:
547
+ html_output += f"<p>Top 3 possible breeds:</p><ul>"
548
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
549
+ html_output += f"<li><strong>{breed}</strong> ({prob} confidence)</li>"
550
  html_output += "</ul>"
551
  html_output += '<div class="breed-buttons">'
552
  for breed in topk_breeds[:3]:
 
559
 
560
  html_output += '</div>'
561
 
 
562
  if buttons:
563
  html_output += """
564
  <script>
 
674
  )
675
 
676
  breed_buttons.change(
677
+ show_details_html,
678
  inputs=[breed_buttons, output, initial_state],
679
  outputs=[output, back_button, initial_state]
680
  )