DawnC commited on
Commit
0c6ed24
·
1 Parent(s): f37431f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -311,7 +311,7 @@ async def predict(image):
311
  # 偵測圖片中的多個狗
312
  dogs = await detect_multiple_dogs(image)
313
 
314
- # 單一狗情況處理
315
  if len(dogs) == 0:
316
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(image)
317
  if top1_prob < 0.2:
@@ -364,15 +364,15 @@ Dog {i+1}: Detected with moderate confidence. Here are the top 3 possible breeds
364
  3. **{topk_breeds[2]}** ({topk_probs_percent[2]})
365
  """
366
  explanations.append(explanation)
367
- visible_buttons.append(gr.update(visible=True, value=f"More about Dog {i+1}: {topk_breeds[0]}"))
368
- visible_buttons.append(gr.update(visible=True, value=f"More about Dog {i+1}: {topk_breeds[1]}"))
369
- visible_buttons.append(gr.update(visible=True, value=f"More about Dog {i+1}: {topk_breeds[2]}"))
370
  else:
371
  explanations.append(f"Dog {i+1}: The image is unclear or the breed is not in the dataset.")
372
 
373
  final_explanation = "\n\n".join(explanations)
374
 
375
- return final_explanation, annotated_image, visible_buttons
376
 
377
  except Exception as e:
378
  return f"An error occurred: {e}", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
 
311
  # 偵測圖片中的多個狗
312
  dogs = await detect_multiple_dogs(image)
313
 
314
+ # 處理單一狗情況 (如果 YOLO 沒有檢測到多隻狗)
315
  if len(dogs) == 0:
316
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(image)
317
  if top1_prob < 0.2:
 
364
  3. **{topk_breeds[2]}** ({topk_probs_percent[2]})
365
  """
366
  explanations.append(explanation)
367
+ visible_buttons.extend([gr.update(visible=True, value=f"More about Dog {i+1}: {topk_breeds[0]}"),
368
+ gr.update(visible=True, value=f"More about Dog {i+1}: {topk_breeds[1]}"),
369
+ gr.update(visible=True, value=f"More about Dog {i+1}: {topk_breeds[2]}")])
370
  else:
371
  explanations.append(f"Dog {i+1}: The image is unclear or the breed is not in the dataset.")
372
 
373
  final_explanation = "\n\n".join(explanations)
374
 
375
+ return final_explanation, annotated_image, gr.update(visible=True, choices=visible_buttons)
376
 
377
  except Exception as e:
378
  return f"An error occurred: {e}", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)