Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +11 -18
breed_recommendation.py
CHANGED
@@ -63,7 +63,7 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
63 |
recommendation_output = gr.HTML(label="Breed Recommendations")
|
64 |
|
65 |
with gr.Tab("Find by Description"):
|
66 |
-
description_input, description_search_btn, description_output,
|
67 |
|
68 |
|
69 |
def on_find_match_click(*args):
|
@@ -201,25 +201,15 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
201 |
|
202 |
result = format_recommendation_html(final_recommendations)
|
203 |
|
204 |
-
return [
|
205 |
-
result, # 結果
|
206 |
-
False, # 隱藏處理消息
|
207 |
-
True, # 顯示結果區域
|
208 |
-
True # 重新啟用輸入框
|
209 |
-
]
|
210 |
|
211 |
|
212 |
except Exception as e:
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
error_message, # 錯誤消息
|
219 |
-
False, # 隱藏處理消息
|
220 |
-
True, # 顯示結果區域
|
221 |
-
True # 重新啟用輸入框
|
222 |
-
]
|
223 |
|
224 |
|
225 |
get_recommendations_btn.click(
|
@@ -236,9 +226,12 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
236 |
)
|
237 |
|
238 |
description_search_btn.click(
|
|
|
|
|
|
|
239 |
fn=on_description_search,
|
240 |
inputs=[description_input],
|
241 |
-
outputs=[description_output,
|
242 |
)
|
243 |
|
244 |
return {
|
|
|
63 |
recommendation_output = gr.HTML(label="Breed Recommendations")
|
64 |
|
65 |
with gr.Tab("Find by Description"):
|
66 |
+
description_input, description_search_btn, description_output, loading_msg = create_description_search_tab()
|
67 |
|
68 |
|
69 |
def on_find_match_click(*args):
|
|
|
201 |
|
202 |
result = format_recommendation_html(final_recommendations)
|
203 |
|
204 |
+
return [gr.update(value=result), gr.update(visible=False)]
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
|
207 |
except Exception as e:
|
208 |
+
error_msg = f"Error processing your description. Details: {str(e)}"
|
209 |
+
return [gr.update(value=error_msg), gr.update(visible=False)]
|
210 |
+
|
211 |
+
def show_loading():
|
212 |
+
return [gr.update(value=""), gr.update(visible=True)]
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
|
215 |
get_recommendations_btn.click(
|
|
|
226 |
)
|
227 |
|
228 |
description_search_btn.click(
|
229 |
+
fn=show_loading, # 先顯示加載消息
|
230 |
+
outputs=[description_output, loading_msg]
|
231 |
+
).then( # 然後執行搜索
|
232 |
fn=on_description_search,
|
233 |
inputs=[description_input],
|
234 |
+
outputs=[description_output, loading_msg]
|
235 |
)
|
236 |
|
237 |
return {
|