Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -312,37 +312,37 @@ async def predict(image):
|
|
312 |
color = color_list[i % len(color_list)]
|
313 |
draw.rectangle(box, outline=color, width=3)
|
314 |
draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
|
315 |
-
|
316 |
combined_confidence = detection_confidence * top1_prob
|
317 |
dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
318 |
dogs_info += f'<h2>Dog {i+1}</h2>'
|
319 |
-
|
320 |
if top1_prob >= 0.45:
|
321 |
breed = topk_breeds[0]
|
322 |
description = get_dog_description(breed)
|
323 |
dogs_info += format_description_html(description, breed)
|
324 |
-
|
325 |
elif combined_confidence >= 0.15:
|
326 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
327 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
328 |
prob = float(prob.replace('%', ''))
|
329 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
330 |
dogs_info += "</ul>"
|
331 |
-
|
332 |
-
#
|
333 |
dogs_info += '<div class="breed-buttons">'
|
334 |
for breed in topk_breeds[:3]:
|
335 |
button_id = f"Dog {i+1}: More about {breed}"
|
336 |
dogs_info += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
337 |
buttons.append(button_id)
|
338 |
dogs_info += '</div>' # ็ตๆๆ้้จๅ
|
339 |
-
|
340 |
else:
|
341 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
342 |
-
|
343 |
dogs_info += '</div>' # ็ตๆ็็ไฟกๆฏๆก
|
344 |
-
|
345 |
-
|
346 |
html_output = f"""
|
347 |
<style>
|
348 |
.dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
|
@@ -353,6 +353,7 @@ async def predict(image):
|
|
353 |
{dogs_info}
|
354 |
"""
|
355 |
|
|
|
356 |
|
357 |
|
358 |
if buttons:
|
|
|
312 |
color = color_list[i % len(color_list)]
|
313 |
draw.rectangle(box, outline=color, width=3)
|
314 |
draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
|
315 |
+
|
316 |
combined_confidence = detection_confidence * top1_prob
|
317 |
dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
318 |
dogs_info += f'<h2>Dog {i+1}</h2>'
|
319 |
+
|
320 |
if top1_prob >= 0.45:
|
321 |
breed = topk_breeds[0]
|
322 |
description = get_dog_description(breed)
|
323 |
dogs_info += format_description_html(description, breed)
|
324 |
+
|
325 |
elif combined_confidence >= 0.15:
|
326 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
327 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
328 |
prob = float(prob.replace('%', ''))
|
329 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
330 |
dogs_info += "</ul>"
|
331 |
+
|
332 |
+
# ๆๆ้ๆพๅจๆฏๅๅ็จฎๅ
ง็ div ๅ
ง
|
333 |
dogs_info += '<div class="breed-buttons">'
|
334 |
for breed in topk_breeds[:3]:
|
335 |
button_id = f"Dog {i+1}: More about {breed}"
|
336 |
dogs_info += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
337 |
buttons.append(button_id)
|
338 |
dogs_info += '</div>' # ็ตๆๆ้้จๅ
|
339 |
+
|
340 |
else:
|
341 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
342 |
+
|
343 |
dogs_info += '</div>' # ็ตๆ็็ไฟกๆฏๆก
|
344 |
+
|
345 |
+
# ็ขบไฟไธๅ็ดฏ็ฉๅค้จ็ buttons_html
|
346 |
html_output = f"""
|
347 |
<style>
|
348 |
.dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
|
|
|
353 |
{dogs_info}
|
354 |
"""
|
355 |
|
356 |
+
|
357 |
|
358 |
|
359 |
if buttons:
|