Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- 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 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
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 |
-
#
|
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,
|