Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -347,6 +347,7 @@ async def process_single_dog(image):
|
|
347 |
# return error_msg, None, gr.update(visible=False, choices=[]), None
|
348 |
|
349 |
|
|
|
350 |
async def predict(image):
|
351 |
if image is None:
|
352 |
return "Please upload an image to start.", None, gr.update(visible=False, choices=[]), None
|
@@ -373,7 +374,7 @@ async def predict(image):
|
|
373 |
|
374 |
combined_confidence = detection_confidence * top1_prob
|
375 |
dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
376 |
-
dogs_info += f'<h2
|
377 |
|
378 |
if top1_prob >= 0.45:
|
379 |
breed = topk_breeds[0]
|
@@ -381,12 +382,12 @@ async def predict(image):
|
|
381 |
dogs_info += format_description_html(description, breed)
|
382 |
|
383 |
elif combined_confidence >= 0.15:
|
384 |
-
dogs_info += f"<p
|
385 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
386 |
prob = float(prob.replace('%', ''))
|
387 |
-
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}%
|
388 |
-
button_id = f"
|
389 |
-
dogs_info += f'
|
390 |
buttons.append(button_id)
|
391 |
dogs_info += "</ul>"
|
392 |
|
@@ -399,7 +400,7 @@ async def predict(image):
|
|
399 |
<style>
|
400 |
.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); }}
|
401 |
.dog-info h2 {{ background-color: #f0f0f0; padding: 10px; margin: -15px -15px 15px -15px; border-radius: 5px 5px 0 0; }}
|
402 |
-
.breed-button {{ margin-
|
403 |
</style>
|
404 |
{dogs_info}
|
405 |
<script>
|
@@ -422,7 +423,7 @@ async def predict(image):
|
|
422 |
"is_multi_dog": len(dogs) > 1,
|
423 |
"html_output": html_output
|
424 |
}
|
425 |
-
return html_output, annotated_image, gr.update(visible=
|
426 |
|
427 |
except Exception as e:
|
428 |
error_msg = f"An error occurred: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
|
|
347 |
# return error_msg, None, gr.update(visible=False, choices=[]), None
|
348 |
|
349 |
|
350 |
+
|
351 |
async def predict(image):
|
352 |
if image is None:
|
353 |
return "Please upload an image to start.", None, gr.update(visible=False, choices=[]), None
|
|
|
374 |
|
375 |
combined_confidence = detection_confidence * top1_prob
|
376 |
dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
|
377 |
+
dogs_info += f'<h2>Dog {i+1}</h2>'
|
378 |
|
379 |
if top1_prob >= 0.45:
|
380 |
breed = topk_breeds[0]
|
|
|
382 |
dogs_info += format_description_html(description, breed)
|
383 |
|
384 |
elif combined_confidence >= 0.15:
|
385 |
+
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
386 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
387 |
prob = float(prob.replace('%', ''))
|
388 |
+
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)"
|
389 |
+
button_id = f"Dog {i+1}: More about {breed}"
|
390 |
+
dogs_info += f'</li><li><button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button></li>'
|
391 |
buttons.append(button_id)
|
392 |
dogs_info += "</ul>"
|
393 |
|
|
|
400 |
<style>
|
401 |
.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); }}
|
402 |
.dog-info h2 {{ background-color: #f0f0f0; padding: 10px; margin: -15px -15px 15px -15px; border-radius: 5px 5px 0 0; }}
|
403 |
+
.breed-button {{ margin-top: 5px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; display: inline-block; }}
|
404 |
</style>
|
405 |
{dogs_info}
|
406 |
<script>
|
|
|
423 |
"is_multi_dog": len(dogs) > 1,
|
424 |
"html_output": html_output
|
425 |
}
|
426 |
+
return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
|
427 |
|
428 |
except Exception as e:
|
429 |
error_msg = f"An error occurred: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|