DawnC commited on
Commit
0bf2519
1 Parent(s): 6956b6e

Update breed_recommendation.py

Browse files
Files changed (1) hide show
  1. breed_recommendation.py +17 -22
breed_recommendation.py CHANGED
@@ -202,21 +202,19 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
202
  barking_acceptance=args[9]
203
  )
204
 
 
205
  recommendations = get_breed_recommendations(user_prefs, top_n=10)
206
-
207
- # 格式化結果以確保所有必要的資訊都被包含
208
- history_results = []
209
- for i, rec in enumerate(recommendations, 1):
210
- result_entry = {
211
- 'breed': rec['breed'],
212
- 'rank': i,
213
- 'overall_score': rec['final_score'],
214
- 'base_score': rec.get('base_score', 0),
215
- 'bonus_score': rec.get('bonus_score', 0),
216
- 'scores': rec.get('scores', {}),
217
- 'final_score': rec['final_score'] # 確保這個欄位存在
218
- }
219
- history_results.append(result_entry)
220
 
221
  # 保存搜索歷史
222
  history_component.save_search(
@@ -236,17 +234,14 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
236
  results=history_results
237
  )
238
 
239
- # 生成 HTML 結果
240
- html_result = format_recommendation_html(recommendations, is_description_search=False)
241
-
242
- # 強制更新顯示
243
- gr.Info("Results updated successfully!")
244
- return gr.update(value=html_result)
245
 
246
  except Exception as e:
247
  print(f"Error in find match: {str(e)}")
248
- traceback.print_exc()
249
- return gr.update(value="Error getting recommendations")
 
250
 
251
  get_recommendations_btn.click(
252
  fn=on_find_match_click,
 
202
  barking_acceptance=args[9]
203
  )
204
 
205
+ # 獲取推薦結果
206
  recommendations = get_breed_recommendations(user_prefs, top_n=10)
207
+
208
+ # 為歷史記錄準備資料
209
+ history_results = [{
210
+ 'breed': rec['breed'],
211
+ 'rank': i + 1, # 確保排名從1開始
212
+ 'overall_score': rec['final_score'],
213
+ 'base_score': rec.get('base_score', 0),
214
+ 'bonus_score': rec.get('bonus_score', 0),
215
+ 'scores': rec.get('scores', {}),
216
+ 'final_score': rec['final_score']
217
+ } for i, rec in enumerate(recommendations)]
 
 
 
218
 
219
  # 保存搜索歷史
220
  history_component.save_search(
 
234
  results=history_results
235
  )
236
 
237
+ # 返回推薦結果的 HTML(這是關鍵!)
238
+ return format_recommendation_html(recommendations, is_description_search=False)
 
 
 
 
239
 
240
  except Exception as e:
241
  print(f"Error in find match: {str(e)}")
242
+ import traceback
243
+ print(traceback.format_exc())
244
+ return "Error getting recommendations"
245
 
246
  get_recommendations_btn.click(
247
  fn=on_find_match_click,