Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -289,7 +289,7 @@ async def detect_multiple_dogs(image):
|
|
289 |
img = image.copy()
|
290 |
img.thumbnail((640, 640))
|
291 |
|
292 |
-
results = model_yolo(img, conf=0.
|
293 |
dogs = []
|
294 |
for result in results:
|
295 |
for box in result.boxes:
|
@@ -342,7 +342,7 @@ async def predict(image):
|
|
342 |
async def process_multiple_dogs_result(dogs, image):
|
343 |
annotated_image = image.copy()
|
344 |
draw = ImageDraw.Draw(annotated_image)
|
345 |
-
font = ImageFont.
|
346 |
|
347 |
explanations = []
|
348 |
buttons = []
|
@@ -352,24 +352,22 @@ async def process_multiple_dogs_result(dogs, image):
|
|
352 |
|
353 |
optimized_box = optimize_box(box, image.size)
|
354 |
draw.rectangle(optimized_box, outline="red", width=3)
|
355 |
-
draw.text((optimized_box[0], optimized_box[1]), f"Dog {i}", fill="yellow", font=font)
|
356 |
|
357 |
-
if top1_prob >= 0.
|
358 |
breed = topk_breeds[0]
|
359 |
description = get_dog_description(breed)
|
360 |
-
|
361 |
-
|
362 |
-
explanation
|
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]})
|
367 |
-
"""
|
368 |
explanations.append(explanation)
|
369 |
-
|
|
|
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
|
373 |
|
374 |
final_explanation = "\n\n---\n\n".join(explanations)
|
375 |
|
|
|
289 |
img = image.copy()
|
290 |
img.thumbnail((640, 640))
|
291 |
|
292 |
+
results = model_yolo(img, conf=0.1) # 降低閾值以檢測更多狗
|
293 |
dogs = []
|
294 |
for result in results:
|
295 |
for box in result.boxes:
|
|
|
342 |
async def process_multiple_dogs_result(dogs, image):
|
343 |
annotated_image = image.copy()
|
344 |
draw = ImageDraw.Draw(annotated_image)
|
345 |
+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 20)
|
346 |
|
347 |
explanations = []
|
348 |
buttons = []
|
|
|
352 |
|
353 |
optimized_box = optimize_box(box, image.size)
|
354 |
draw.rectangle(optimized_box, outline="red", width=3)
|
355 |
+
draw.text((optimized_box[0], optimized_box[1]), f"Dog {i}", fill="yellow", font=font, stroke_width=2, stroke_fill="black")
|
356 |
|
357 |
+
if top1_prob >= 0.2:
|
358 |
breed = topk_breeds[0]
|
359 |
description = get_dog_description(breed)
|
360 |
+
explanation = f"Dog {i}: **{breed}**\n\n"
|
361 |
+
explanation += "\n".join([f"**{key}**: {value}" for key, value in description.items() if key != "Breed"])
|
362 |
+
explanation += f"\n\n**Want to learn more about dog breeds?** [Visit the AKC dog breeds page]({get_akc_breeds_link()}) and search for {breed} to find detailed information."
|
|
|
|
|
|
|
|
|
|
|
363 |
explanations.append(explanation)
|
364 |
+
|
365 |
+
if top1_prob < 0.5:
|
366 |
buttons.append(f"More about Dog {i}: {breed}")
|
367 |
+
buttons.append(f"More about Dog {i}: {topk_breeds[1]}")
|
368 |
+
buttons.append(f"More about Dog {i}: {topk_breeds[2]}")
|
369 |
else:
|
370 |
+
explanations.append(f"Dog {i}: The image is unclear or the breed is not in the dataset. Please upload a clearer image of this dog.")
|
371 |
|
372 |
final_explanation = "\n\n---\n\n".join(explanations)
|
373 |
|