DawnC commited on
Commit
91e3c91
·
1 Parent(s): 21de606

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -318,12 +318,15 @@ async def predict(image):
318
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
319
  dogs_info += "</ul>"
320
 
321
- # 生成與品種對應的按鈕,直接使用 button 標籤
322
- buttons_html = "<div style='margin-top: 10px;'>"
323
  for breed in topk_breeds[:3]:
324
  button_id = f"Dog {i+1}: More about {breed}"
325
- buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button> '
326
- buttons_html += "</div>"
 
 
 
327
 
328
  # 將按鈕插入當前狗的品種描述後
329
  dogs_info += f'{buttons_html}'
@@ -332,11 +335,13 @@ async def predict(image):
332
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
333
 
334
  dogs_info += '</div>' # 結束當前狗的資訊區塊
335
-
336
 
337
-
 
 
338
 
339
-
 
340
  buttons_html = ""
341
 
342
  html_output = f"""
 
318
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
319
  dogs_info += "</ul>"
320
 
321
+ # 生成與品種對應的 Radio 控件,放置在該品種描述區塊內
322
+ radio_options = []
323
  for breed in topk_breeds[:3]:
324
  button_id = f"Dog {i+1}: More about {breed}"
325
+ radio_options.append(button_id)
326
+ buttons.append(button_id)
327
+
328
+ # 更新 Radio 控件
329
+ buttons_html = f'<div class="breed-buttons">{radio_options}</div>'
330
 
331
  # 將按鈕插入當前狗的品種描述後
332
  dogs_info += f'{buttons_html}'
 
335
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
336
 
337
  dogs_info += '</div>' # 結束當前狗的資訊區塊
 
338
 
339
+ # 確保渲染到正確位置,更新 Radio 控件的選項:
340
+ html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
341
+
342
 
343
+
344
+
345
  buttons_html = ""
346
 
347
  html_output = f"""