DawnC commited on
Commit
5ee548e
·
1 Parent(s): 2865aa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -451,9 +451,6 @@ async def process_single_dog(image):
451
 
452
 
453
 
454
- import gradio as gr
455
- from PIL import Image, ImageDraw, ImageFont
456
-
457
  async def predict(image):
458
  if image is None:
459
  return "Please upload an image to start.", None, gr.update(visible=False, choices=[]), None
@@ -516,24 +513,23 @@ async def predict(image):
516
  {dogs_info}
517
 
518
  <script>
519
- // 這段代碼用來附加每個 Learn More 按鈕的事件監聽器
520
- document.querySelectorAll('button[id^="Dog"]').forEach(button => {{
521
- button.addEventListener('click', () => {{
522
  const button_id = button.id;
 
523
  const radio = document.querySelector('input[type=radio][value="' + button_id + '"]');
524
- console.log('Button clicked: ' + button_id); // 檢查按鈕是否被觸發
525
- if (radio) {{
526
- radio.click(); // 觸發點擊事件
527
- }} else {{
528
- console.error("Radio button not found:", button_id); // 如果找不到相應的 radio button
529
- }}
530
- }});
531
- }});
532
  </script>
533
  """
534
 
535
-
536
-
537
  initial_state = {
538
  "dogs_info": dogs_info,
539
  "buttons": buttons,
 
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
 
513
  {dogs_info}
514
 
515
  <script>
516
+ document.querySelectorAll('button[id^="Dog"]').forEach(button => {
517
+ console.log('Attaching event to button: ' + button.id); // 檢查每個按鈕是否正確被生成
518
+ button.addEventListener('click', () => {
519
  const button_id = button.id;
520
+ console.log('Button clicked: ' + button_id); // 檢查是否觸發了按鈕點擊事件
521
  const radio = document.querySelector('input[type=radio][value="' + button_id + '"]');
522
+ if (radio) {
523
+ radio.click();
524
+ console.log('Radio button clicked for: ' + button_id); // 檢查是否找到相應的 radio button 並點擊
525
+ } else {
526
+ console.error("Radio button not found for: " + button_id); // 如果沒有找到 radio,顯示錯誤
527
+ }
528
+ });
529
+ });
530
  </script>
531
  """
532
 
 
 
533
  initial_state = {
534
  "dogs_info": dogs_info,
535
  "buttons": buttons,