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