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

Update breed_recommendation.py

Browse files
Files changed (1) hide show
  1. breed_recommendation.py +15 -13
breed_recommendation.py CHANGED
@@ -204,17 +204,19 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
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,14 +236,14 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
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,
 
204
 
205
  # 獲取推薦結果
206
  recommendations = get_breed_recommendations(user_prefs, top_n=10)
207
+
208
+ # 關鍵改動:確保歷史記錄的資料結構完整
209
+ history_results = []
210
+ for i, rec in enumerate(recommendations):
211
+ history_results.append({
212
+ 'breed': rec['breed'],
213
+ 'rank': i + 1, # 確保排名從1開始
214
+ 'overall_score': rec['final_score'],
215
+ 'base_score': rec['base_score'],
216
+ 'bonus_score': rec['bonus_score'],
217
+ 'scores': rec['scores'],
218
+ 'final_score': rec['final_score']
219
+ })
220
 
221
  # 保存搜索歷史
222
  history_component.save_search(
 
236
  results=history_results
237
  )
238
 
239
+ # 保持原有的返回方式
240
  return format_recommendation_html(recommendations, is_description_search=False)
241
 
242
  except Exception as e:
243
  print(f"Error in find match: {str(e)}")
244
  import traceback
245
  print(traceback.format_exc())
246
+ return "Error getting recommendations"
247
 
248
  get_recommendations_btn.click(
249
  fn=on_find_match_click,