Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -263,45 +263,6 @@ async def predict(image):
|
|
263 |
draw = ImageDraw.Draw(annotated_image)
|
264 |
font = ImageFont.load_default()
|
265 |
|
266 |
-
# dogs_info = ""
|
267 |
-
# buttons_html = ""
|
268 |
-
|
269 |
-
# for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
270 |
-
# top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
271 |
-
# color = color_list[i % len(color_list)]
|
272 |
-
# draw.rectangle(box, outline=color, width=3)
|
273 |
-
# draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
|
274 |
-
|
275 |
-
# combined_confidence = detection_confidence * top1_prob
|
276 |
-
# dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
277 |
-
# dogs_info += f'<h2>Dog {i+1}</h2>'
|
278 |
-
|
279 |
-
# if top1_prob >= 0.45:
|
280 |
-
# breed = topk_breeds[0]
|
281 |
-
# description = get_dog_description(breed)
|
282 |
-
# dogs_info += format_description_html(description, breed)
|
283 |
-
|
284 |
-
# elif combined_confidence >= 0.15:
|
285 |
-
# dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
286 |
-
# for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
287 |
-
# #dogs_info += f"<li><strong>{breed}</strong> ({prob} confidence)</li>"
|
288 |
-
# prob = float(prob.replace('%', '')) # new
|
289 |
-
# dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>" # new
|
290 |
-
# dogs_info += "</ul>"
|
291 |
-
|
292 |
-
# for breed in topk_breeds[:3]:
|
293 |
-
# button_id = f"Dog {i+1}: More about {breed}"
|
294 |
-
# buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
295 |
-
# buttons.append(button_id)
|
296 |
-
# buttons_html += '</div>'
|
297 |
-
# else:
|
298 |
-
# dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
299 |
-
|
300 |
-
# dogs_info += '</div>'
|
301 |
-
|
302 |
-
# dogs_info += buttons_html
|
303 |
-
|
304 |
-
|
305 |
dogs_info = ""
|
306 |
|
307 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
@@ -338,8 +299,6 @@ async def predict(image):
|
|
338 |
|
339 |
dogs_info += '</div>' # 關閉這個狗的div
|
340 |
|
341 |
-
#dogs_info += buttons_html # 加入本次的buttons_html
|
342 |
-
|
343 |
# 確保在每次處理一隻狗後重置,防止累積
|
344 |
buttons_html = ""
|
345 |
|
@@ -355,8 +314,6 @@ async def predict(image):
|
|
355 |
.breed-button {{ margin-right: 10px; margin-bottom: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; }}
|
356 |
</style>
|
357 |
{dogs_info}
|
358 |
-
|
359 |
-
|
360 |
"""
|
361 |
|
362 |
if buttons:
|
|
|
263 |
draw = ImageDraw.Draw(annotated_image)
|
264 |
font = ImageFont.load_default()
|
265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
dogs_info = ""
|
267 |
|
268 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
|
|
299 |
|
300 |
dogs_info += '</div>' # 關閉這個狗的div
|
301 |
|
|
|
|
|
302 |
# 確保在每次處理一隻狗後重置,防止累積
|
303 |
buttons_html = ""
|
304 |
|
|
|
314 |
.breed-button {{ margin-right: 10px; margin-bottom: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; }}
|
315 |
</style>
|
316 |
{dogs_info}
|
|
|
|
|
317 |
"""
|
318 |
|
319 |
if buttons:
|