Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +42 -31
breed_recommendation.py
CHANGED
|
@@ -11,32 +11,33 @@ from search_history import create_history_tab, create_history_component
|
|
| 11 |
def create_custom_button_style():
|
| 12 |
return """
|
| 13 |
<style>
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
border
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
overflow: hidden;
|
| 29 |
}
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
}
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
}
|
|
|
|
| 40 |
#search-status {
|
| 41 |
text-align: center;
|
| 42 |
padding: 15px;
|
|
@@ -46,6 +47,12 @@ def create_custom_button_style():
|
|
| 46 |
border-radius: 8px;
|
| 47 |
background: rgba(255, 95, 109, 0.1);
|
| 48 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
</style>
|
| 50 |
"""
|
| 51 |
|
|
@@ -203,17 +210,17 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 203 |
)
|
| 204 |
gr.HTML(create_custom_button_style())
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
search_status = gr.HTML(
|
| 207 |
'<div id="search-status">🔍 Sniffing out your perfect furry companion...</div>',
|
| 208 |
visible=False,
|
| 209 |
elem_id="search-status-container"
|
| 210 |
)
|
| 211 |
|
| 212 |
-
get_recommendations_btn = gr.Button(
|
| 213 |
-
"Find My Perfect Match! 🔍",
|
| 214 |
-
elem_id="find-match-btn" # 添加自定義ID
|
| 215 |
-
)
|
| 216 |
-
|
| 217 |
recommendation_output = gr.HTML(
|
| 218 |
label="Breed Recommendations",
|
| 219 |
visible=True, # 確保可見性
|
|
@@ -273,7 +280,7 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 273 |
|
| 274 |
return [
|
| 275 |
format_recommendation_html(recommendations, is_description_search=False),
|
| 276 |
-
gr.update(visible=
|
| 277 |
]
|
| 278 |
|
| 279 |
except Exception as e:
|
|
@@ -285,10 +292,14 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 285 |
def update_status_and_process(*args):
|
| 286 |
return [
|
| 287 |
"", # 清空現有結果
|
| 288 |
-
gr.
|
| 289 |
]
|
| 290 |
-
|
| 291 |
get_recommendations_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
fn=on_find_match_click,
|
| 293 |
inputs=[
|
| 294 |
living_space,
|
|
|
|
| 11 |
def create_custom_button_style():
|
| 12 |
return """
|
| 13 |
<style>
|
| 14 |
+
/* 確保選擇器精確匹配 */
|
| 15 |
+
button#find-match-btn {
|
| 16 |
+
background: linear-gradient(90deg, #ff5f6d 0%, #ffc371 100%) !important;
|
| 17 |
+
border: none !important;
|
| 18 |
+
border-radius: 30px !important;
|
| 19 |
+
padding: 12px 24px !important;
|
| 20 |
+
color: white !important;
|
| 21 |
+
font-weight: bold !important;
|
| 22 |
+
cursor: pointer !important;
|
| 23 |
+
transition: all 0.3s ease !important;
|
| 24 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
|
| 25 |
+
width: 100% !important;
|
| 26 |
+
margin: 20px 0 !important;
|
| 27 |
+
font-size: 1.1em !important;
|
|
|
|
| 28 |
}
|
| 29 |
+
|
| 30 |
+
button#find-match-btn:hover {
|
| 31 |
+
background: linear-gradient(90deg, #ff4f5d 0%, #ffb361 100%) !important;
|
| 32 |
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2) !important;
|
| 33 |
+
transform: translateY(-2px) !important;
|
| 34 |
}
|
| 35 |
+
|
| 36 |
+
button#find-match-btn:active {
|
| 37 |
+
transform: translateY(1px) !important;
|
| 38 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
|
| 39 |
}
|
| 40 |
+
|
| 41 |
#search-status {
|
| 42 |
text-align: center;
|
| 43 |
padding: 15px;
|
|
|
|
| 47 |
border-radius: 8px;
|
| 48 |
background: rgba(255, 95, 109, 0.1);
|
| 49 |
}
|
| 50 |
+
|
| 51 |
+
/* 強制覆蓋任何其他樣式 */
|
| 52 |
+
.gradio-button {
|
| 53 |
+
position: relative !important;
|
| 54 |
+
overflow: visible !important;
|
| 55 |
+
}
|
| 56 |
</style>
|
| 57 |
"""
|
| 58 |
|
|
|
|
| 210 |
)
|
| 211 |
gr.HTML(create_custom_button_style())
|
| 212 |
|
| 213 |
+
get_recommendations_btn = gr.Button(
|
| 214 |
+
"Find My Perfect Match! 🔍",
|
| 215 |
+
elem_id="find-match-btn"
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
search_status = gr.HTML(
|
| 219 |
'<div id="search-status">🔍 Sniffing out your perfect furry companion...</div>',
|
| 220 |
visible=False,
|
| 221 |
elem_id="search-status-container"
|
| 222 |
)
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
recommendation_output = gr.HTML(
|
| 225 |
label="Breed Recommendations",
|
| 226 |
visible=True, # 確保可見性
|
|
|
|
| 280 |
|
| 281 |
return [
|
| 282 |
format_recommendation_html(recommendations, is_description_search=False),
|
| 283 |
+
gr.update(visible=False)
|
| 284 |
]
|
| 285 |
|
| 286 |
except Exception as e:
|
|
|
|
| 292 |
def update_status_and_process(*args):
|
| 293 |
return [
|
| 294 |
"", # 清空現有結果
|
| 295 |
+
gr.update(visible=True)
|
| 296 |
]
|
| 297 |
+
|
| 298 |
get_recommendations_btn.click(
|
| 299 |
+
fn=update_status_and_process, # 先執行狀態更新
|
| 300 |
+
outputs=[recommendation_output, search_status],
|
| 301 |
+
queue=False # 確保狀態更新立即執行
|
| 302 |
+
).then( # 然後執行主要處理邏輯
|
| 303 |
fn=on_find_match_click,
|
| 304 |
inputs=[
|
| 305 |
living_space,
|