Spaces:
Sleeping
Sleeping
Update breed_recommendation.py
Browse files- breed_recommendation.py +10 -74
breed_recommendation.py
CHANGED
@@ -461,84 +461,22 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
461 |
"💭 Getting opinions from our experts..."
|
462 |
]
|
463 |
|
464 |
-
|
465 |
-
message_cycle = itertools.cycle(loading_messages)
|
466 |
-
|
467 |
-
# 設定最大循環次數(例如3次)
|
468 |
-
max_cycles = 3
|
469 |
-
current_cycle = 0
|
470 |
-
|
471 |
-
while current_cycle < max_cycles:
|
472 |
-
message = next(message_cycle)
|
473 |
yield gr.HTML("""
|
474 |
<div style="
|
475 |
text-align: center;
|
476 |
-
|
477 |
-
|
478 |
-
|
|
|
|
|
|
|
|
|
479 |
">
|
480 |
-
|
481 |
-
<div style="
|
482 |
-
padding: 20px;
|
483 |
-
background: rgba(255, 255, 255, 0.95);
|
484 |
-
border-radius: 16px;
|
485 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
|
486 |
-
border: 1px solid rgba(255, 140, 66, 0.1);
|
487 |
-
">
|
488 |
-
<!-- 訊息文字 -->
|
489 |
-
<div style="
|
490 |
-
font-size: 1.2em;
|
491 |
-
color: #4a5568;
|
492 |
-
margin-bottom: 15px;
|
493 |
-
font-weight: 500;
|
494 |
-
">
|
495 |
-
{message}
|
496 |
-
</div>
|
497 |
-
|
498 |
-
<!-- 進度條容器 -->
|
499 |
-
<div style="
|
500 |
-
width: 100%;
|
501 |
-
height: 4px;
|
502 |
-
background: #f5f5f5;
|
503 |
-
border-radius: 4px;
|
504 |
-
overflow: hidden;
|
505 |
-
position: relative;
|
506 |
-
">
|
507 |
-
<!-- 動畫進度條 -->
|
508 |
-
<div style="
|
509 |
-
position: absolute;
|
510 |
-
width: 30%;
|
511 |
-
height: 100%;
|
512 |
-
background: linear-gradient(to right, #ff8c42, #ff6b2b);
|
513 |
-
animation: loading 2s infinite ease-in-out;
|
514 |
-
border-radius: 4px;
|
515 |
-
"></div>
|
516 |
-
</div>
|
517 |
-
</div>
|
518 |
</div>
|
519 |
-
|
520 |
-
<style>
|
521 |
-
@keyframes loading {{
|
522 |
-
0% {{
|
523 |
-
transform: translateX(-100%);
|
524 |
-
opacity: 0.7;
|
525 |
-
}}
|
526 |
-
50% {{
|
527 |
-
opacity: 1;
|
528 |
-
}}
|
529 |
-
100% {{
|
530 |
-
transform: translateX(400%);
|
531 |
-
opacity: 0.7;
|
532 |
-
}}
|
533 |
-
}}
|
534 |
-
</style>
|
535 |
""".format(message=message))
|
536 |
-
|
537 |
-
await asyncio.sleep(1.5) # 稍微延長每個訊息的顯示時間
|
538 |
-
|
539 |
-
# 如果是最後一個訊息,增加循環計數
|
540 |
-
if message == loading_messages[-1]:
|
541 |
-
current_cycle += 1
|
542 |
|
543 |
# 處理用戶數據和獲取推薦
|
544 |
user_prefs = UserPreferences(
|
@@ -595,8 +533,6 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
595 |
|
596 |
except Exception as e:
|
597 |
print(f"Error in find match: {str(e)}")
|
598 |
-
import traceback
|
599 |
-
print(traceback.format_exc())
|
600 |
yield gr.HTML("Error getting recommendations")
|
601 |
|
602 |
|
|
|
461 |
"💭 Getting opinions from our experts..."
|
462 |
]
|
463 |
|
464 |
+
for message in loading_messages:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
yield gr.HTML("""
|
466 |
<div style="
|
467 |
text-align: center;
|
468 |
+
padding: 15px;
|
469 |
+
background: white;
|
470 |
+
border-radius: 8px;
|
471 |
+
margin: 10px 0;
|
472 |
+
color: #4a5568;
|
473 |
+
font-size: 1.1em;
|
474 |
+
font-weight: 500;
|
475 |
">
|
476 |
+
{message}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
478 |
""".format(message=message))
|
479 |
+
await asyncio.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
|
480 |
|
481 |
# 處理用戶數據和獲取推薦
|
482 |
user_prefs = UserPreferences(
|
|
|
533 |
|
534 |
except Exception as e:
|
535 |
print(f"Error in find match: {str(e)}")
|
|
|
|
|
536 |
yield gr.HTML("Error getting recommendations")
|
537 |
|
538 |
|