Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +12 -79
breed_recommendation.py
CHANGED
|
@@ -531,68 +531,13 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 531 |
)
|
| 532 |
|
| 533 |
def on_find_match_click(*args):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
try:
|
| 535 |
-
#
|
| 536 |
-
status_html = """
|
| 537 |
-
<div id="loading-status" style="
|
| 538 |
-
text-align: center;
|
| 539 |
-
padding: 20px;
|
| 540 |
-
margin: 20px 0;
|
| 541 |
-
background: linear-gradient(to right, rgba(66, 153, 225, 0.1), rgba(72, 187, 120, 0.1));
|
| 542 |
-
border-radius: 10px;
|
| 543 |
-
opacity: 1;
|
| 544 |
-
">
|
| 545 |
-
<div style="font-size: 40px; margin-bottom: 10px;">🐕</div>
|
| 546 |
-
<div style="
|
| 547 |
-
color: #2D3748;
|
| 548 |
-
font-size: 1.2em;
|
| 549 |
-
margin-bottom: 10px;
|
| 550 |
-
font-weight: 500;
|
| 551 |
-
">Finding your perfect match...</div>
|
| 552 |
-
<div id="status-dots" style="
|
| 553 |
-
display: flex;
|
| 554 |
-
justify-content: center;
|
| 555 |
-
gap: 8px;
|
| 556 |
-
margin: 15px 0;
|
| 557 |
-
">
|
| 558 |
-
<span style="
|
| 559 |
-
width: 10px;
|
| 560 |
-
height: 10px;
|
| 561 |
-
background: #4299e1;
|
| 562 |
-
border-radius: 50%;
|
| 563 |
-
display: inline-block;
|
| 564 |
-
animation: pulse 1s infinite;
|
| 565 |
-
"></span>
|
| 566 |
-
<span style="
|
| 567 |
-
width: 10px;
|
| 568 |
-
height: 10px;
|
| 569 |
-
background: #4299e1;
|
| 570 |
-
border-radius: 50%;
|
| 571 |
-
display: inline-block;
|
| 572 |
-
animation: pulse 1s infinite .2s;
|
| 573 |
-
"></span>
|
| 574 |
-
<span style="
|
| 575 |
-
width: 10px;
|
| 576 |
-
height: 10px;
|
| 577 |
-
background: #4299e1;
|
| 578 |
-
border-radius: 50%;
|
| 579 |
-
display: inline-block;
|
| 580 |
-
animation: pulse 1s infinite .4s;
|
| 581 |
-
"></span>
|
| 582 |
-
</div>
|
| 583 |
-
<style>
|
| 584 |
-
@keyframes pulse {
|
| 585 |
-
0%, 100% { transform: scale(1); opacity: 1; }
|
| 586 |
-
50% { transform: scale(1.5); opacity: 0.7; }
|
| 587 |
-
}
|
| 588 |
-
</style>
|
| 589 |
-
</div>
|
| 590 |
-
"""
|
| 591 |
-
|
| 592 |
-
# 返回載入狀態
|
| 593 |
-
yield gr.HTML(status_html)
|
| 594 |
-
|
| 595 |
-
# 建立用戶偏好
|
| 596 |
user_prefs = UserPreferences(
|
| 597 |
living_space=args[0],
|
| 598 |
yard_access=args[1],
|
|
@@ -641,27 +586,16 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 641 |
results=history_results
|
| 642 |
)
|
| 643 |
|
| 644 |
-
|
| 645 |
-
yield format_recommendation_html(recommendations, is_description_search=False)
|
| 646 |
|
| 647 |
except Exception as e:
|
| 648 |
print(f"Error in find match: {str(e)}")
|
| 649 |
import traceback
|
| 650 |
print(traceback.format_exc())
|
| 651 |
-
|
| 652 |
-
<div style="
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
background: rgba(255, 0, 0, 0.1);
|
| 656 |
-
border-radius: 10px;
|
| 657 |
-
margin: 20px 0;
|
| 658 |
-
">
|
| 659 |
-
<p style="
|
| 660 |
-
color: #d32f2f;
|
| 661 |
-
font-size: 1.1em;
|
| 662 |
-
margin: 0;
|
| 663 |
-
">
|
| 664 |
-
🐾 Oops! Something went wrong. Please try again!
|
| 665 |
</p>
|
| 666 |
</div>
|
| 667 |
""")
|
|
@@ -682,8 +616,7 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 682 |
noise_tolerance
|
| 683 |
],
|
| 684 |
outputs=recommendation_output,
|
| 685 |
-
show_progress=
|
| 686 |
-
queue=False # 允許連續點擊
|
| 687 |
)
|
| 688 |
|
| 689 |
# 返回頁面組件
|
|
|
|
| 531 |
)
|
| 532 |
|
| 533 |
def on_find_match_click(*args):
|
| 534 |
+
"""
|
| 535 |
+
1. 先顯示處理狀態
|
| 536 |
+
2. 執行推薦邏輯
|
| 537 |
+
3. 返回最終結果
|
| 538 |
+
"""
|
| 539 |
try:
|
| 540 |
+
# 創建用戶偏好對象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
user_prefs = UserPreferences(
|
| 542 |
living_space=args[0],
|
| 543 |
yard_access=args[1],
|
|
|
|
| 586 |
results=history_results
|
| 587 |
)
|
| 588 |
|
| 589 |
+
return format_recommendation_html(recommendations, is_description_search=False)
|
|
|
|
| 590 |
|
| 591 |
except Exception as e:
|
| 592 |
print(f"Error in find match: {str(e)}")
|
| 593 |
import traceback
|
| 594 |
print(traceback.format_exc())
|
| 595 |
+
return gr.HTML("""
|
| 596 |
+
<div style="text-align: center; padding: 20px; background: rgba(255, 0, 0, 0.1); border-radius: 10px; margin: 20px 0;">
|
| 597 |
+
<p style="color: #d32f2f; font-size: 1.1em; margin: 0;">
|
| 598 |
+
🐾 抱歉出了點問題,請再試一次!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
</p>
|
| 600 |
</div>
|
| 601 |
""")
|
|
|
|
| 616 |
noise_tolerance
|
| 617 |
],
|
| 618 |
outputs=recommendation_output,
|
| 619 |
+
show_progress="full", # 使用 Gradio 內建的進度顯示
|
|
|
|
| 620 |
)
|
| 621 |
|
| 622 |
# 返回頁面組件
|