Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -486,10 +486,11 @@ async def predict(image):
|
|
486 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
487 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
488 |
prob = float(prob.replace('%', ''))
|
489 |
-
# ๅ ๅ
ฅๆฏๅๅ็จฎ็ Radio ๆ้
|
490 |
button_id = f"Dog {i+1}: More about {breed}"
|
491 |
buttons.append(button_id) # ็บๆฏๅๅ็จฎๅ ๅ
ฅๆ้
|
492 |
-
|
|
|
|
|
493 |
dogs_info += "</ul>"
|
494 |
|
495 |
else:
|
@@ -497,12 +498,23 @@ async def predict(image):
|
|
497 |
|
498 |
dogs_info += '</div>'
|
499 |
|
|
|
500 |
html_output = f"""
|
501 |
<style>
|
502 |
.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); }}
|
503 |
.dog-info h2 {{ background-color: #f0f0f0; padding: 10px; margin: -15px -15px 15px -15px; border-radius: 5px 5px 0 0; }}
|
504 |
</style>
|
505 |
{dogs_info}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
"""
|
507 |
|
508 |
initial_state = {
|
@@ -519,6 +531,8 @@ async def predict(image):
|
|
519 |
return error_msg, None, gr.update(visible=False, choices=[]), None
|
520 |
|
521 |
|
|
|
|
|
522 |
def show_details_html(choice, previous_output, initial_state):
|
523 |
if not choice:
|
524 |
return previous_output, gr.update(visible=True), initial_state
|
|
|
486 |
dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
|
487 |
for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
|
488 |
prob = float(prob.replace('%', ''))
|
|
|
489 |
button_id = f"Dog {i+1}: More about {breed}"
|
490 |
buttons.append(button_id) # ็บๆฏๅๅ็จฎๅ ๅ
ฅๆ้
|
491 |
+
# ๅ ๅ
ฅ Learn More ๆ้
|
492 |
+
dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)"
|
493 |
+
dogs_info += f'<button style="background-color: #4CAF50; color: white; border: none; padding: 5px 10px; border-radius: 3px; margin-left: 10px;" onclick="handle_button_click(\'{button_id}\')">Learn More</button></li>'
|
494 |
dogs_info += "</ul>"
|
495 |
|
496 |
else:
|
|
|
498 |
|
499 |
dogs_info += '</div>'
|
500 |
|
501 |
+
# ็ๆ Javascript ไพ่็ๆ้้ปๆไบไปถ
|
502 |
html_output = f"""
|
503 |
<style>
|
504 |
.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); }}
|
505 |
.dog-info h2 {{ background-color: #f0f0f0; padding: 10px; margin: -15px -15px 15px -15px; border-radius: 5px 5px 0 0; }}
|
506 |
</style>
|
507 |
{dogs_info}
|
508 |
+
<script>
|
509 |
+
function handle_button_click(button_id) {
|
510 |
+
const radio = document.querySelector('input[type=radio][value="' + button_id + '"]');
|
511 |
+
if (radio) {
|
512 |
+
radio.click(); // ้ปๆๆ้ๅพ่งธ็ผไบไปถ
|
513 |
+
} else {
|
514 |
+
console.error("Radio button not found:", button_id);
|
515 |
+
}
|
516 |
+
}
|
517 |
+
</script>
|
518 |
"""
|
519 |
|
520 |
initial_state = {
|
|
|
531 |
return error_msg, None, gr.update(visible=False, choices=[]), None
|
532 |
|
533 |
|
534 |
+
|
535 |
+
|
536 |
def show_details_html(choice, previous_output, initial_state):
|
537 |
if not choice:
|
538 |
return previous_output, gr.update(visible=True), initial_state
|