DawnC commited on
Commit
d749ee0
1 Parent(s): f0780e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -357,10 +357,10 @@ async def process_multiple_dogs_result(dogs, image):
357
  if top1_prob >= 0.5:
358
  breed = topk_breeds[0]
359
  description = get_dog_description(breed)
360
- explanations.append(f"Dog {i}: **{breed}** ({top1_prob*100:.2f}% confidence)\n\n{format_description(description, breed, is_multi_dog=True, dog_number=i)}")
361
- else:
362
  explanation = f"""
363
- Dog {i}: Detected with moderate confidence. Here are the top 3 possible breeds:
364
  1. **{topk_breeds[0]}** ({topk_probs_percent[0]})
365
  2. **{topk_breeds[1]}** ({topk_probs_percent[1]})
366
  3. **{topk_breeds[2]}** ({topk_probs_percent[2]})
@@ -368,13 +368,15 @@ Dog {i}: Detected with moderate confidence. Here are the top 3 possible breeds:
368
  explanations.append(explanation)
369
  for breed in topk_breeds:
370
  buttons.append(f"More about Dog {i}: {breed}")
 
 
371
 
372
  final_explanation = "\n\n---\n\n".join(explanations)
373
 
374
- if buttons:
375
- return final_explanation, annotated_image, gr.update(visible=True, choices=buttons), gr.update(visible=False), gr.update(visible=False)
376
- else:
377
- return final_explanation, annotated_image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
378
 
379
  async def process_single_dog_result(top1_prob, topk_breeds, topk_probs_percent, image, box):
380
  annotated_image = image.copy()
 
357
  if top1_prob >= 0.5:
358
  breed = topk_breeds[0]
359
  description = get_dog_description(breed)
360
+ explanations.append(f"Dog {i}: **{breed}**\n\n{format_description(description, breed, is_multi_dog=True, dog_number=i)}")
361
+ elif top1_prob >= 0.2:
362
  explanation = f"""
363
+ Dog {i}: The model couldn't confidently identify the breed. Here are the top 3 possible breeds:
364
  1. **{topk_breeds[0]}** ({topk_probs_percent[0]})
365
  2. **{topk_breeds[1]}** ({topk_probs_percent[1]})
366
  3. **{topk_breeds[2]}** ({topk_probs_percent[2]})
 
368
  explanations.append(explanation)
369
  for breed in topk_breeds:
370
  buttons.append(f"More about Dog {i}: {breed}")
371
+ else:
372
+ explanations.append(f"Dog {i}: The image is unclear or the breed is not in the dataset. Please upload a clearer image of a dog.")
373
 
374
  final_explanation = "\n\n---\n\n".join(explanations)
375
 
376
+ if not explanations:
377
+ return "No dogs were confidently detected in the image. Please upload a clearer image of a dog.", annotated_image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
378
+
379
+ return final_explanation, annotated_image, gr.update(visible=bool(buttons), choices=buttons), gr.update(visible=False), gr.update(visible=False)
380
 
381
  async def process_single_dog_result(top1_prob, topk_breeds, topk_probs_percent, image, box):
382
  annotated_image = image.copy()