DawnC commited on
Commit
a252791
1 Parent(s): 3b33804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -325,6 +325,7 @@ async def predict(image):
325
  if top1_prob >= 0.5:
326
  return formatted_description, image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
327
  else:
 
328
  explanation = (
329
  f"The model couldn't confidently identify the breed. Here are the top 3 possible breeds:\n\n"
330
  f"1. **{topk_breeds[0]}** ({topk_probs_percent[0]} confidence)\n"
@@ -332,9 +333,10 @@ async def predict(image):
332
  f"3. **{topk_breeds[2]}** ({topk_probs_percent[2]} confidence)\n\n"
333
  "Click on a button to view more information about the breed."
334
  )
 
335
  return explanation, gr.update(visible=True, value=f"More about {topk_breeds[0]}"), gr.update(visible=True, value=f"More about {topk_breeds[1]}"), gr.update(visible=True, value=f"More about {topk_breeds[2]}")
336
 
337
- # 多狗情境 - 使用 YOLO 檢測並處理多狗
338
  color_list = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#800080', '#FFA500']
339
  explanations = []
340
  visible_buttons = []
@@ -359,7 +361,7 @@ async def predict(image):
359
  return final_explanation, annotated_image, gr.update(visible=True, choices=visible_buttons), gr.update(visible=False), gr.update(visible=False)
360
 
361
  except Exception as e:
362
- return f"An error occurred: {str(e)}", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
363
 
364
 
365
  async def show_details(choice):
@@ -367,6 +369,7 @@ async def show_details(choice):
367
  return "Please select a breed to view details."
368
 
369
  try:
 
370
  if "Dog" in choice:
371
  _, breed = choice.split(": ", 1)
372
  else:
@@ -378,6 +381,7 @@ async def show_details(choice):
378
 
379
 
380
 
 
381
  with gr.Blocks(css="""
382
  .container { max-width: 900px; margin: auto; padding: 20px; }
383
  .gr-box { border-radius: 15px; }
 
325
  if top1_prob >= 0.5:
326
  return formatted_description, image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
327
  else:
328
+ # 如果置信度不足,顯示前三個可能的品種
329
  explanation = (
330
  f"The model couldn't confidently identify the breed. Here are the top 3 possible breeds:\n\n"
331
  f"1. **{topk_breeds[0]}** ({topk_probs_percent[0]} confidence)\n"
 
333
  f"3. **{topk_breeds[2]}** ({topk_probs_percent[2]} confidence)\n\n"
334
  "Click on a button to view more information about the breed."
335
  )
336
+ # 返回可選擇的按鈕以顯示詳細資訊
337
  return explanation, gr.update(visible=True, value=f"More about {topk_breeds[0]}"), gr.update(visible=True, value=f"More about {topk_breeds[1]}"), gr.update(visible=True, value=f"More about {topk_breeds[2]}")
338
 
339
+ # 多狗情境 - 使用 YOLO 偵測並處理多狗
340
  color_list = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#800080', '#FFA500']
341
  explanations = []
342
  visible_buttons = []
 
361
  return final_explanation, annotated_image, gr.update(visible=True, choices=visible_buttons), gr.update(visible=False), gr.update(visible=False)
362
 
363
  except Exception as e:
364
+ return f"An error occurred: {str(e)}", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible(False))
365
 
366
 
367
  async def show_details(choice):
 
369
  return "Please select a breed to view details."
370
 
371
  try:
372
+ # 解析出用戶選擇的品種
373
  if "Dog" in choice:
374
  _, breed = choice.split(": ", 1)
375
  else:
 
381
 
382
 
383
 
384
+
385
  with gr.Blocks(css="""
386
  .container { max-width: 900px; margin: auto; padding: 20px; }
387
  .gr-box { border-radius: 15px; }