DawnC commited on
Commit
7837f49
·
1 Parent(s): 488ebbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -443,8 +443,9 @@ async def predict(image):
443
  breed = topk_breeds[0]
444
  description = get_dog_description(breed)
445
  html_output += format_description_html(description, breed)
446
- html_output += f'<div class="breed-buttons"><button class="breed-button" onclick="handle_button_click(\'Dog {i+1}: More about {breed}\')">More about {breed}</button></div>'
447
- buttons.append(f"Dog {i+1}: More about {breed}")
 
448
  elif combined_confidence >= 0.15:
449
  html_output += f"<p>Top 3 possible breeds:</p><ul>"
450
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
@@ -465,7 +466,12 @@ async def predict(image):
465
  html_output += """
466
  <script>
467
  function handle_button_click(button_id) {
468
- document.querySelector('input[type=radio][value="' + button_id + '"]').click();
 
 
 
 
 
469
  }
470
  </script>
471
  """
@@ -554,7 +560,7 @@ with gr.Blocks() as iface:
554
  input_image = gr.Image(label="Upload a dog image", type="pil")
555
  output_image = gr.Image(label="Annotated Image")
556
 
557
- output = gr.HTML(label="Prediction Results") # 改為 HTML 輸出
558
 
559
  breed_buttons = gr.Radio(choices=[], label="More Information", visible=False)
560
 
@@ -569,7 +575,7 @@ with gr.Blocks() as iface:
569
  )
570
 
571
  breed_buttons.change(
572
- show_details_html,
573
  inputs=[breed_buttons, output, initial_state],
574
  outputs=[output, back_button, initial_state]
575
  )
@@ -580,11 +586,6 @@ with gr.Blocks() as iface:
580
  outputs=[output, output_image, breed_buttons, back_button, initial_state]
581
  )
582
 
583
- gr.Examples(
584
- examples=['Border_Collie.jpg', 'Golden_Retriever.jpeg', 'Saint_Bernard.jpeg', 'French_Bulldog.jpeg', 'Samoyed.jpg'],
585
- inputs=input_image
586
- )
587
-
588
  gr.HTML('For more details on this project and other work, feel free to visit my GitHub <a href="https://github.com/Eric-Chung-0511/Learning-Record/tree/main/Data%20Science%20Projects/Dog_Breed_Classifier">Dog Breed Classifier</a>')
589
 
590
 
 
443
  breed = topk_breeds[0]
444
  description = get_dog_description(breed)
445
  html_output += format_description_html(description, breed)
446
+ button_id = f"Dog {i+1}: More about {breed}"
447
+ html_output += f'<div class="breed-buttons"><button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button></div>'
448
+ buttons.append(button_id)
449
  elif combined_confidence >= 0.15:
450
  html_output += f"<p>Top 3 possible breeds:</p><ul>"
451
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
 
466
  html_output += """
467
  <script>
468
  function handle_button_click(button_id) {
469
+ const radio = document.querySelector('input[type=radio][value="' + button_id + '"]');
470
+ if (radio) {
471
+ radio.click();
472
+ } else {
473
+ console.error("Radio button not found:", button_id);
474
+ }
475
  }
476
  </script>
477
  """
 
560
  input_image = gr.Image(label="Upload a dog image", type="pil")
561
  output_image = gr.Image(label="Annotated Image")
562
 
563
+ output = gr.HTML(label="Prediction Results") # 使用 HTML 而不是 Markdown
564
 
565
  breed_buttons = gr.Radio(choices=[], label="More Information", visible=False)
566
 
 
575
  )
576
 
577
  breed_buttons.change(
578
+ show_details,
579
  inputs=[breed_buttons, output, initial_state],
580
  outputs=[output, back_button, initial_state]
581
  )
 
586
  outputs=[output, output_image, breed_buttons, back_button, initial_state]
587
  )
588
 
 
 
 
 
 
589
  gr.HTML('For more details on this project and other work, feel free to visit my GitHub <a href="https://github.com/Eric-Chung-0511/Learning-Record/tree/main/Data%20Science%20Projects/Dog_Breed_Classifier">Dog Breed Classifier</a>')
590
 
591