Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +15 -79
breed_recommendation.py
CHANGED
@@ -125,63 +125,6 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
125 |
elem_id="recommendation-output" # 添加唯一ID以便追蹤
|
126 |
)
|
127 |
|
128 |
-
# def on_find_match_click(*args):
|
129 |
-
# try:
|
130 |
-
# user_prefs = UserPreferences(
|
131 |
-
# living_space=args[0],
|
132 |
-
# yard_access=args[1],
|
133 |
-
# exercise_time=args[2],
|
134 |
-
# exercise_type=args[3],
|
135 |
-
# grooming_commitment=args[4],
|
136 |
-
# experience_level=args[5],
|
137 |
-
# time_availability=args[6],
|
138 |
-
# has_children=args[7],
|
139 |
-
# children_age=args[8] if args[7] else None,
|
140 |
-
# noise_tolerance=args[9],
|
141 |
-
# space_for_play=True if args[0] != "apartment" else False,
|
142 |
-
# other_pets=False,
|
143 |
-
# climate="moderate",
|
144 |
-
# health_sensitivity="medium",
|
145 |
-
# barking_acceptance=args[9]
|
146 |
-
# )
|
147 |
-
|
148 |
-
# recommendations = get_breed_recommendations(user_prefs, top_n=10)
|
149 |
-
|
150 |
-
# history_results = [{
|
151 |
-
# 'breed': rec['breed'],
|
152 |
-
# 'rank': rec['rank'],
|
153 |
-
# 'overall_score': rec['final_score'],
|
154 |
-
# 'base_score': rec['base_score'],
|
155 |
-
# 'bonus_score': rec['bonus_score'],
|
156 |
-
# 'scores': rec['scores']
|
157 |
-
# } for rec in recommendations]
|
158 |
-
|
159 |
-
# history_component.save_search(
|
160 |
-
# user_preferences={
|
161 |
-
# 'living_space': args[0],
|
162 |
-
# 'yard_access': args[1],
|
163 |
-
# 'exercise_time': args[2],
|
164 |
-
# 'exercise_type': args[3],
|
165 |
-
# 'grooming_commitment': args[4],
|
166 |
-
# 'experience_level': args[5],
|
167 |
-
# 'time_availability': args[6],
|
168 |
-
# 'has_children': args[7],
|
169 |
-
# 'children_age': args[8] if args[7] else None,
|
170 |
-
# 'noise_tolerance': args[9],
|
171 |
-
# 'search_type': 'Criteria'
|
172 |
-
# },
|
173 |
-
# results=history_results
|
174 |
-
# )
|
175 |
-
|
176 |
-
# return format_recommendation_html(recommendations, is_description_search=False)
|
177 |
-
|
178 |
-
# except Exception as e:
|
179 |
-
# print(f"Error in find match: {str(e)}")
|
180 |
-
# import traceback
|
181 |
-
# print(traceback.format_exc())
|
182 |
-
# return "Error getting recommendations"
|
183 |
-
|
184 |
-
|
185 |
def on_find_match_click(*args):
|
186 |
try:
|
187 |
user_prefs = UserPreferences(
|
@@ -201,24 +144,18 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
201 |
health_sensitivity="medium",
|
202 |
barking_acceptance=args[9]
|
203 |
)
|
204 |
-
|
205 |
-
# 獲取推薦結果
|
206 |
recommendations = get_breed_recommendations(user_prefs, top_n=10)
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
'scores': rec['scores'],
|
218 |
-
'final_score': rec['final_score']
|
219 |
-
})
|
220 |
-
|
221 |
-
# 保存搜索歷史
|
222 |
history_component.save_search(
|
223 |
user_preferences={
|
224 |
'living_space': args[0],
|
@@ -231,19 +168,18 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
231 |
'has_children': args[7],
|
232 |
'children_age': args[8] if args[7] else None,
|
233 |
'noise_tolerance': args[9],
|
234 |
-
'search_type': 'Criteria'
|
235 |
},
|
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,
|
|
|
125 |
elem_id="recommendation-output" # 添加唯一ID以便追蹤
|
126 |
)
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
def on_find_match_click(*args):
|
129 |
try:
|
130 |
user_prefs = UserPreferences(
|
|
|
144 |
health_sensitivity="medium",
|
145 |
barking_acceptance=args[9]
|
146 |
)
|
147 |
+
|
|
|
148 |
recommendations = get_breed_recommendations(user_prefs, top_n=10)
|
149 |
+
|
150 |
+
history_results = [{
|
151 |
+
'breed': rec['breed'],
|
152 |
+
'rank': rec['rank'],
|
153 |
+
'overall_score': rec['final_score'],
|
154 |
+
'base_score': rec['base_score'],
|
155 |
+
'bonus_score': rec['bonus_score'],
|
156 |
+
'scores': rec['scores']
|
157 |
+
} for rec in recommendations]
|
158 |
+
|
|
|
|
|
|
|
|
|
|
|
159 |
history_component.save_search(
|
160 |
user_preferences={
|
161 |
'living_space': args[0],
|
|
|
168 |
'has_children': args[7],
|
169 |
'children_age': args[8] if args[7] else None,
|
170 |
'noise_tolerance': args[9],
|
171 |
+
'search_type': 'Criteria'
|
172 |
},
|
173 |
results=history_results
|
174 |
)
|
175 |
+
|
|
|
176 |
return format_recommendation_html(recommendations, is_description_search=False)
|
177 |
+
|
178 |
except Exception as e:
|
179 |
print(f"Error in find match: {str(e)}")
|
180 |
import traceback
|
181 |
print(traceback.format_exc())
|
182 |
+
return "Error getting recommendations"
|
183 |
|
184 |
get_recommendations_btn.click(
|
185 |
fn=on_find_match_click,
|