DawnC commited on
Commit
5db0349
1 Parent(s): b62a32e

Update breed_recommendation.py

Browse files
Files changed (1) hide show
  1. breed_recommendation.py +17 -9
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 = create_description_search_tab()
67
 
68
 
69
  def on_find_match_click(*args):
@@ -118,9 +118,6 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
118
 
119
  def on_description_search(description: str):
120
  try:
121
- processing_message.update(visible=True)
122
- description_output.update(visible=False)
123
-
124
  matcher = SmartBreedMatcher(dog_data)
125
  breed_recommendations = matcher.match_user_preference(description, top_n=10)
126
 
@@ -201,17 +198,28 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
201
 
202
  processing_message.update(visible=False)
203
  description_output.update(visible=True)
 
 
204
 
205
- return format_recommendation_html(final_recommendations)
 
 
 
 
 
206
 
207
- except Exception as e:
208
- processing_message.update(visible=False)
209
- description_output.update(visible=True)
210
 
 
211
  import traceback
212
  error_details = traceback.format_exc()
213
  print(f"Detailed error:\n{error_details}")
214
- return f"Error processing your description. Details: {str(e)}"
 
 
 
 
 
 
215
 
216
 
217
  get_recommendations_btn.click(
 
63
  recommendation_output = gr.HTML(label="Breed Recommendations")
64
 
65
  with gr.Tab("Find by Description"):
66
+ description_input, description_search_btn, description_output, processing_message = create_description_search_tab()
67
 
68
 
69
  def on_find_match_click(*args):
 
118
 
119
  def on_description_search(description: str):
120
  try:
 
 
 
121
  matcher = SmartBreedMatcher(dog_data)
122
  breed_recommendations = matcher.match_user_preference(description, top_n=10)
123
 
 
198
 
199
  processing_message.update(visible=False)
200
  description_output.update(visible=True)
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
  import traceback
214
  error_details = traceback.format_exc()
215
  print(f"Detailed error:\n{error_details}")
216
+ error_message = f"Error processing your description. Details: {str(e)}"
217
+ return [
218
+ error_message, # 錯誤消息
219
+ False, # 隱藏處理消息
220
+ True, # 顯示結果區域
221
+ True # 重新啟用輸入框
222
+ ]
223
 
224
 
225
  get_recommendations_btn.click(