DawnC commited on
Commit
3df6c8e
โ€ข
1 Parent(s): 0b37af8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -250,7 +250,6 @@ def get_akc_breeds_link():
250
  # iface.launch()
251
 
252
 
253
-
254
  # Update the format_description to handle descriptions more cleanly
255
  def format_description(description, breed):
256
  if isinstance(description, dict):
@@ -314,22 +313,28 @@ async def predict(image):
314
  # ๅตๆธฌๅœ–็‰‡ไธญ็š„ๅคšๅ€‹็‹—
315
  dogs = await detect_multiple_dogs(image)
316
 
 
317
  if len(dogs) == 0:
318
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(image)
319
  if top1_prob < 0.2:
320
  return "The image is unclear or the breed is not in the dataset. Please upload a clearer image of a dog.", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
321
- breed = topk_breeds[0]
322
- description = get_dog_description(breed)
323
- formatted_description = format_description(description, breed)
324
- return formatted_description, image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
325
 
326
- # ่™•็†ๅ–ฎไธ€็‹—ๆƒ…ๆณ
327
- if len(dogs) == 1:
328
- top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(image)
329
  breed = topk_breeds[0]
330
  description = get_dog_description(breed)
331
  formatted_description = format_description(description, breed)
332
- return formatted_description, image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
  # ๅคš็‹—่™•็†
335
  color_list = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#800080', '#FFA500']
@@ -387,8 +392,6 @@ async def show_details(choice):
387
  return f"An error occurred while showing details: {e}"
388
 
389
 
390
-
391
-
392
  with gr.Blocks(css="""
393
  .container { max-width: 900px; margin: auto; padding: 20px; }
394
  .gr-box { border-radius: 15px; }
 
250
  # iface.launch()
251
 
252
 
 
253
  # Update the format_description to handle descriptions more cleanly
254
  def format_description(description, breed):
255
  if isinstance(description, dict):
 
313
  # ๅตๆธฌๅœ–็‰‡ไธญ็š„ๅคšๅ€‹็‹—
314
  dogs = await detect_multiple_dogs(image)
315
 
316
+ # ๅ–ฎไธ€็‹—ๆƒ…ๆณ่™•็†
317
  if len(dogs) == 0:
318
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(image)
319
  if top1_prob < 0.2:
320
  return "The image is unclear or the breed is not in the dataset. Please upload a clearer image of a dog.", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
 
 
 
 
321
 
 
 
 
322
  breed = topk_breeds[0]
323
  description = get_dog_description(breed)
324
  formatted_description = format_description(description, breed)
325
+
326
+ # ่™•็†้ซ˜็ฝฎไฟกๅบฆ่ˆ‡ไฝŽ็ฝฎไฟกๅบฆๆƒ…ๆณ
327
+ if top1_prob >= 0.5:
328
+ return formatted_description, image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
329
+ else:
330
+ explanation = (
331
+ f"The model couldn't confidently identify the breed. Here are the top 3 possible breeds:\n\n"
332
+ f"1. **{topk_breeds[0]}** ({topk_probs_percent[0]} confidence)\n"
333
+ f"2. **{topk_breeds[1]}** ({topk_probs_percent[1]} confidence)\n"
334
+ f"3. **{topk_breeds[2]}** ({topk_probs_percent[2]} confidence)\n\n"
335
+ "Click on a button to view more information about the breed."
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
  # ๅคš็‹—่™•็†
340
  color_list = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#800080', '#FFA500']
 
392
  return f"An error occurred while showing details: {e}"
393
 
394
 
 
 
395
  with gr.Blocks(css="""
396
  .container { max-width: 900px; margin: auto; padding: 20px; }
397
  .gr-box { border-radius: 15px; }