DawnC commited on
Commit
bd70504
·
1 Parent(s): 58667b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -449,6 +449,8 @@ async def process_single_dog(image):
449
 
450
 
451
 
 
 
452
  async def predict(image):
453
  if image is None:
454
  return "Please upload an image to start.", None, gr.update(visible=False, choices=[]), None
@@ -460,12 +462,12 @@ async def predict(image):
460
  dogs = await detect_multiple_dogs(image)
461
 
462
  color_list = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#800080', '#FFA500']
463
- buttons = []
464
  annotated_image = image.copy()
465
  draw = ImageDraw.Draw(annotated_image)
466
  font = ImageFont.load_default()
467
 
468
  dogs_info = ""
 
469
 
470
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
471
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
@@ -487,10 +489,11 @@ async def predict(image):
487
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
488
  prob = float(prob.replace('%', ''))
489
 
490
- # 為每個品種生成一個唯一的 button_id,並附加 Learn More 按鈕
491
  button_id = f"Dog {i+1}: More about {breed}"
 
492
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)"
493
- dogs_info += f'<button id="{button_id}" style="background-color: #4CAF50; color: white; border: none; padding: 5px 10px; border-radius: 3px; margin-left: 10px;">Learn More</button></li>'
494
  dogs_info += "</ul>"
495
 
496
  else:
@@ -526,10 +529,6 @@ async def predict(image):
526
  </script>
527
  """
528
 
529
-
530
-
531
-
532
-
533
  initial_state = {
534
  "dogs_info": dogs_info,
535
  "buttons": buttons,
@@ -544,10 +543,6 @@ async def predict(image):
544
  return error_msg, None, gr.update(visible=False, choices=[]), None
545
 
546
 
547
-
548
-
549
-
550
-
551
  def show_details_html(choice, previous_output, initial_state):
552
  if not choice:
553
  return previous_output, gr.update(visible=True), initial_state
 
449
 
450
 
451
 
452
+
453
+
454
  async def predict(image):
455
  if image is None:
456
  return "Please upload an image to start.", None, gr.update(visible=False, choices=[]), None
 
462
  dogs = await detect_multiple_dogs(image)
463
 
464
  color_list = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#800080', '#FFA500']
 
465
  annotated_image = image.copy()
466
  draw = ImageDraw.Draw(annotated_image)
467
  font = ImageFont.load_default()
468
 
469
  dogs_info = ""
470
+ buttons = []
471
 
472
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
473
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
 
489
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
490
  prob = float(prob.replace('%', ''))
491
 
492
+ # 為每個品種生成唯一的 button_id,並附加 Learn More 按鈕
493
  button_id = f"Dog {i+1}: More about {breed}"
494
+ buttons.append(button_id) # 將按鈕 ID 添加到按鈕列表中
495
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)"
496
+ dogs_info += f'<button class="breed-button" id="{button_id}" style="background-color: #4CAF50; color: white; border: none; padding: 5px 10px; border-radius: 3px; margin-left: 10px;">Learn More</button></li>'
497
  dogs_info += "</ul>"
498
 
499
  else:
 
529
  </script>
530
  """
531
 
 
 
 
 
532
  initial_state = {
533
  "dogs_info": dogs_info,
534
  "buttons": buttons,
 
543
  return error_msg, None, gr.update(visible=False, choices=[]), None
544
 
545
 
 
 
 
 
546
  def show_details_html(choice, previous_output, initial_state):
547
  if not choice:
548
  return previous_output, gr.update(visible=True), initial_state