Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +13 -8
breed_recommendation.py
CHANGED
|
@@ -214,12 +214,8 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 214 |
elem_id="recommendation-output"
|
| 215 |
)
|
| 216 |
|
| 217 |
-
def show_loading_status():
|
| 218 |
-
return gr.HTML.update(visible=True)
|
| 219 |
-
|
| 220 |
def on_find_match_click(*args):
|
| 221 |
try:
|
| 222 |
-
yield ["", gr.HTML.update(visible=True)]
|
| 223 |
print("Starting breed matching process...")
|
| 224 |
user_prefs = UserPreferences(
|
| 225 |
living_space=args[0],
|
|
@@ -269,9 +265,9 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 269 |
results=history_results
|
| 270 |
)
|
| 271 |
|
| 272 |
-
|
| 273 |
format_recommendation_html(recommendations, is_description_search=False),
|
| 274 |
-
gr.HTML.update(visible=False)
|
| 275 |
]
|
| 276 |
|
| 277 |
except Exception as e:
|
|
@@ -279,8 +275,18 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 279 |
import traceback
|
| 280 |
print(traceback.format_exc())
|
| 281 |
return ["Error getting recommendations", gr.HTML.update(visible=False)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
get_recommendations_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
fn=on_find_match_click,
|
| 285 |
inputs=[
|
| 286 |
living_space,
|
|
@@ -295,8 +301,7 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 295 |
children_age,
|
| 296 |
noise_tolerance
|
| 297 |
],
|
| 298 |
-
outputs=[recommendation_output, search_status]
|
| 299 |
-
queue=True # 確保異步處理
|
| 300 |
)
|
| 301 |
|
| 302 |
return {
|
|
|
|
| 214 |
elem_id="recommendation-output"
|
| 215 |
)
|
| 216 |
|
|
|
|
|
|
|
|
|
|
| 217 |
def on_find_match_click(*args):
|
| 218 |
try:
|
|
|
|
| 219 |
print("Starting breed matching process...")
|
| 220 |
user_prefs = UserPreferences(
|
| 221 |
living_space=args[0],
|
|
|
|
| 265 |
results=history_results
|
| 266 |
)
|
| 267 |
|
| 268 |
+
return [
|
| 269 |
format_recommendation_html(recommendations, is_description_search=False),
|
| 270 |
+
gr.HTML.update(visible=False) # 隱藏搜尋狀態
|
| 271 |
]
|
| 272 |
|
| 273 |
except Exception as e:
|
|
|
|
| 275 |
import traceback
|
| 276 |
print(traceback.format_exc())
|
| 277 |
return ["Error getting recommendations", gr.HTML.update(visible=False)]
|
| 278 |
+
|
| 279 |
+
def update_status_and_process(*args):
|
| 280 |
+
return [
|
| 281 |
+
"", # 清空現有結果
|
| 282 |
+
gr.HTML.update(visible=True) # 顯示載入狀態
|
| 283 |
+
]
|
| 284 |
|
| 285 |
get_recommendations_btn.click(
|
| 286 |
+
fn=update_status_and_process, # 先更新狀態
|
| 287 |
+
outputs=[recommendation_output, search_status],
|
| 288 |
+
queue=False # 確保立即執行
|
| 289 |
+
).then( # 然後執行主要處理
|
| 290 |
fn=on_find_match_click,
|
| 291 |
inputs=[
|
| 292 |
living_space,
|
|
|
|
| 301 |
children_age,
|
| 302 |
noise_tolerance
|
| 303 |
],
|
| 304 |
+
outputs=[recommendation_output, search_status]
|
|
|
|
| 305 |
)
|
| 306 |
|
| 307 |
return {
|