DawnC commited on
Commit
92ffbdb
·
verified ·
1 Parent(s): 59d7ecd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -385,20 +385,25 @@ async def predict(image):
385
  breed = topk_breeds[0]
386
  description = get_dog_description(breed)
387
  dogs_info += format_description_html(description, breed)
 
 
 
 
 
 
388
  elif combined_confidence >= 0.15:
389
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
390
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
391
  prob = float(prob.replace('%', ''))
392
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
393
 
394
- # 生成與每個品種對應的按鈕,這次不使用 Gradio 的按鈕生成方式,而是直接用 HTML 來嵌入按鈕
395
  button_id = f"Dog {i+1}: More about {breed}"
396
  buttons_html += f'<button style="display:inline-block; margin-right:10px;" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
397
 
398
  dogs_info += "</ul>"
399
-
400
- # 將按鈕直接嵌入描述內
401
- dogs_info += buttons_html
402
 
403
  else:
404
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
@@ -417,6 +422,7 @@ async def predict(image):
417
  """
418
 
419
 
 
420
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
421
 
422
  except Exception as e:
 
385
  breed = topk_breeds[0]
386
  description = get_dog_description(breed)
387
  dogs_info += format_description_html(description, breed)
388
+
389
+ # 在 0.45 以上情況下直接插入按鈕
390
+ button_id = f"Dog {i+1}: More about {breed}"
391
+ buttons_html += f'<button style="display:inline-block; margin-right:10px;" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
392
+ dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
393
+
394
  elif combined_confidence >= 0.15:
395
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
396
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
397
  prob = float(prob.replace('%', ''))
398
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
399
 
400
+ # 為每個品種插入按鈕
401
  button_id = f"Dog {i+1}: More about {breed}"
402
  buttons_html += f'<button style="display:inline-block; margin-right:10px;" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
403
 
404
  dogs_info += "</ul>"
405
+ # 插入按鈕
406
+ dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
 
407
 
408
  else:
409
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
 
422
  """
423
 
424
 
425
+
426
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
427
 
428
  except Exception as e: