Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +22 -45
breed_recommendation.py
CHANGED
@@ -379,46 +379,23 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
379 |
for i, rec in enumerate(final_recommendations, 1):
|
380 |
rec['rank'] = i
|
381 |
|
382 |
-
|
383 |
-
# history_results = [{
|
384 |
-
# 'breed': rec['breed'],
|
385 |
-
# 'rank': rec['rank'],
|
386 |
-
# 'final_score': rec['final_score']
|
387 |
-
# } for rec in final_recommendations[:10]]
|
388 |
-
|
389 |
-
# history_component.save_search(
|
390 |
-
# user_preferences=None,
|
391 |
-
# results=history_results,
|
392 |
-
# search_type="description",
|
393 |
-
# description=description
|
394 |
-
# )
|
395 |
-
|
396 |
-
# result = format_recommendation_html(final_recommendations, is_description_search=True)
|
397 |
-
# return [gr.update(value=result), gr.update(visible=False)]
|
398 |
-
|
399 |
-
# except Exception as e:
|
400 |
-
# error_msg = f"Error processing your description. Details: {str(e)}"
|
401 |
-
# return [gr.update(value=error_msg), gr.update(visible=False)]
|
402 |
-
|
403 |
history_results = [{
|
404 |
'breed': rec['breed'],
|
405 |
-
'rank':
|
406 |
-
'
|
407 |
-
} for
|
408 |
-
|
409 |
-
# 保存簡化後的搜索記錄
|
410 |
history_component.save_search(
|
411 |
-
user_preferences=
|
412 |
-
'search_type': 'Description', # 標記為描述搜索
|
413 |
-
'description': description # 保存搜索描述
|
414 |
-
},
|
415 |
results=history_results,
|
416 |
-
search_type="description"
|
|
|
417 |
)
|
418 |
-
|
419 |
result = format_recommendation_html(final_recommendations, is_description_search=True)
|
420 |
return [gr.update(value=result), gr.update(visible=False)]
|
421 |
-
|
422 |
except Exception as e:
|
423 |
error_msg = f"Error processing your description. Details: {str(e)}"
|
424 |
return [gr.update(value=error_msg), gr.update(visible=False)]
|
@@ -428,21 +405,21 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
428 |
"""住宿空間適應性評分"""
|
429 |
if living_space == "apartment":
|
430 |
scores = {
|
431 |
-
'Tiny': 0.6,
|
432 |
-
'Small': 0.8,
|
433 |
-
'Medium': 1.0,
|
434 |
-
'Medium-Large': 0.6,
|
435 |
-
'Large': 0.4,
|
436 |
-
'Giant': 0.2
|
437 |
}
|
438 |
else: # house
|
439 |
scores = {
|
440 |
-
'Tiny': 0.4,
|
441 |
-
'Small': 0.6,
|
442 |
-
'Medium': 0.8,
|
443 |
-
'Medium-Large': 1.0,
|
444 |
-
'Large': 0.9,
|
445 |
-
'Giant': 0.7
|
446 |
}
|
447 |
return scores.get(size, 0.5)
|
448 |
|
|
|
379 |
for i, rec in enumerate(final_recommendations, 1):
|
380 |
rec['rank'] = i
|
381 |
|
382 |
+
# 保存到歷史記錄
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
history_results = [{
|
384 |
'breed': rec['breed'],
|
385 |
+
'rank': rec['rank'],
|
386 |
+
'final_score': rec['final_score']
|
387 |
+
} for rec in final_recommendations[:10]]
|
388 |
+
|
|
|
389 |
history_component.save_search(
|
390 |
+
user_preferences=None,
|
|
|
|
|
|
|
391 |
results=history_results,
|
392 |
+
search_type="description",
|
393 |
+
description=description
|
394 |
)
|
395 |
+
|
396 |
result = format_recommendation_html(final_recommendations, is_description_search=True)
|
397 |
return [gr.update(value=result), gr.update(visible=False)]
|
398 |
+
|
399 |
except Exception as e:
|
400 |
error_msg = f"Error processing your description. Details: {str(e)}"
|
401 |
return [gr.update(value=error_msg), gr.update(visible=False)]
|
|
|
405 |
"""住宿空間適應性評分"""
|
406 |
if living_space == "apartment":
|
407 |
scores = {
|
408 |
+
'Tiny': 0.6,
|
409 |
+
'Small': 0.8,
|
410 |
+
'Medium': 1.0,
|
411 |
+
'Medium-Large': 0.6,
|
412 |
+
'Large': 0.4,
|
413 |
+
'Giant': 0.2
|
414 |
}
|
415 |
else: # house
|
416 |
scores = {
|
417 |
+
'Tiny': 0.4,
|
418 |
+
'Small': 0.6,
|
419 |
+
'Medium': 0.8,
|
420 |
+
'Medium-Large': 1.0,
|
421 |
+
'Large': 0.9,
|
422 |
+
'Giant': 0.7
|
423 |
}
|
424 |
return scores.get(size, 0.5)
|
425 |
|