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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -504,6 +504,7 @@ async def predict(image):
504
  dogs_info += '</div>'
505
 
506
  # 在生成後附加 JavaScript 處理按鈕點擊事件
 
507
  html_output = f"""
508
  <style>
509
  .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); }}
@@ -515,15 +516,24 @@ async def predict(image):
515
  {dogs_info}
516
 
517
  <script>
518
- document.querySelectorAll('.breed-button').forEach(button => {{
519
- button.addEventListener('click', (event) => {{
520
- console.log('Button clicked:', event.target.innerText);
 
 
 
 
 
 
 
 
521
  }});
522
  }});
523
  </script>
524
  """
525
 
526
 
 
527
  initial_state = {
528
  "dogs_info": dogs_info,
529
  "buttons": buttons,
 
504
  dogs_info += '</div>'
505
 
506
  # 在生成後附加 JavaScript 處理按鈕點擊事件
507
+ # 生成 JavaScript 處理按鈕點擊事件
508
  html_output = f"""
509
  <style>
510
  .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); }}
 
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,