Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -261,53 +261,8 @@ async def predict(image):
|
|
261 |
|
262 |
dogs_info = ""
|
263 |
|
264 |
-
# for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
265 |
-
# buttons_html = ""
|
266 |
-
# top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
267 |
-
# color = color_list[i % len(color_list)]
|
268 |
-
# draw.rectangle(box, outline=color, width=3)
|
269 |
-
# draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
|
270 |
-
|
271 |
-
# combined_confidence = detection_confidence * top1_prob
|
272 |
-
# dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
273 |
-
# dogs_info += f'<h2>Dog {i+1}</h2>'
|
274 |
-
|
275 |
-
# if top1_prob >= 0.45:
|
276 |
-
# breed = topk_breeds[0]
|
277 |
-
# description = get_dog_description(breed)
|
278 |
-
# dogs_info += format_description_html(description, breed)
|
279 |
-
|
280 |
-
# elif combined_confidence >= 0.15:
|
281 |
-
# dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
282 |
-
# for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
283 |
-
# prob = float(prob.replace('%', ''))
|
284 |
-
# dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
285 |
-
# dogs_info += "</ul>"
|
286 |
-
|
287 |
-
# for breed in topk_breeds[:3]:
|
288 |
-
# button_id = f"Dog {i+1}: More about {breed}"
|
289 |
-
# buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
290 |
-
# buttons.append(button_id)
|
291 |
-
|
292 |
-
# else:
|
293 |
-
# dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
294 |
-
|
295 |
-
# dogs_info += '</div>'
|
296 |
-
|
297 |
-
# buttons_html = ""
|
298 |
-
|
299 |
-
# html_output = f"""
|
300 |
-
# <style>
|
301 |
-
# .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); }}
|
302 |
-
# .dog-info h2 {{ background-color: #f0f0f0; padding: 10px; margin: -15px -15px 15px -15px; border-radius: 5px 5px 0 0; }}
|
303 |
-
# .breed-buttons {{ margin-top: 10px; }}
|
304 |
-
# .breed-button {{ margin-right: 10px; margin-bottom: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; }}
|
305 |
-
# </style>
|
306 |
-
# {dogs_info}
|
307 |
-
# """
|
308 |
-
|
309 |
-
|
310 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
|
|
311 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
312 |
color = color_list[i % len(color_list)]
|
313 |
draw.rectangle(box, outline=color, width=3)
|
@@ -329,20 +284,18 @@ async def predict(image):
|
|
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 |
-
|
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); }}
|
@@ -352,8 +305,6 @@ async def predict(image):
|
|
352 |
</style>
|
353 |
{dogs_info}
|
354 |
"""
|
355 |
-
|
356 |
-
|
357 |
|
358 |
|
359 |
if buttons:
|
|
|
261 |
|
262 |
dogs_info = ""
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
265 |
+
buttons_html = ""
|
266 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
|
267 |
color = color_list[i % len(color_list)]
|
268 |
draw.rectangle(box, outline=color, width=3)
|
|
|
284 |
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
|
285 |
dogs_info += "</ul>"
|
286 |
|
|
|
|
|
287 |
for breed in topk_breeds[:3]:
|
288 |
button_id = f"Dog {i+1}: More about {breed}"
|
289 |
+
buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
|
290 |
buttons.append(button_id)
|
|
|
291 |
|
292 |
else:
|
293 |
dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
|
294 |
|
295 |
+
dogs_info += '</div>'
|
296 |
+
|
297 |
+
buttons_html = ""
|
298 |
+
|
299 |
html_output = f"""
|
300 |
<style>
|
301 |
.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); }}
|
|
|
305 |
</style>
|
306 |
{dogs_info}
|
307 |
"""
|
|
|
|
|
308 |
|
309 |
|
310 |
if buttons:
|