Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -348,10 +348,11 @@ async def predict(image):
|
|
348 |
draw.rectangle(box, outline=color, width=3)
|
349 |
draw.text((box[0], box[1]), f"Dog {i+1}", fill=color, font=font)
|
350 |
|
|
|
351 |
if top1_prob >= 0.5:
|
352 |
-
|
353 |
-
|
354 |
-
explanations.append(f"Dog {i+1}:
|
355 |
elif top1_prob >= 0.2:
|
356 |
explanations.append(f"Dog {i+1}: Top 3 possible breeds:\n"
|
357 |
f"1. **{topk_breeds[0]}** ({topk_probs_percent[0]} confidence)\n"
|
@@ -362,7 +363,7 @@ async def predict(image):
|
|
362 |
explanations.append(f"Dog {i+1}: The image is unclear or the breed is not in the dataset.")
|
363 |
|
364 |
final_explanation = "\n\n".join(explanations)
|
365 |
-
return final_explanation, annotated_image, gr.update(visible=
|
366 |
|
367 |
except Exception as e:
|
368 |
return f"An error occurred: {str(e)}", None, gr.update(visible=False), gr.update(visible=False)
|
|
|
348 |
draw.rectangle(box, outline=color, width=3)
|
349 |
draw.text((box[0], box[1]), f"Dog {i+1}", fill=color, font=font)
|
350 |
|
351 |
+
breed = topk_breeds[0]
|
352 |
if top1_prob >= 0.5:
|
353 |
+
description = get_dog_description(breed)
|
354 |
+
formatted_description = format_description(description, breed)
|
355 |
+
explanations.append(f"Dog {i+1}: {formatted_description}")
|
356 |
elif top1_prob >= 0.2:
|
357 |
explanations.append(f"Dog {i+1}: Top 3 possible breeds:\n"
|
358 |
f"1. **{topk_breeds[0]}** ({topk_probs_percent[0]} confidence)\n"
|
|
|
363 |
explanations.append(f"Dog {i+1}: The image is unclear or the breed is not in the dataset.")
|
364 |
|
365 |
final_explanation = "\n\n".join(explanations)
|
366 |
+
return final_explanation, annotated_image, gr.update(visible=len(choices) > 0, choices=choices), gr.update(visible=False)
|
367 |
|
368 |
except Exception as e:
|
369 |
return f"An error occurred: {str(e)}", None, gr.update(visible=False), gr.update(visible=False)
|