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