Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +33 -10
breed_recommendation.py
CHANGED
@@ -379,23 +379,46 @@ 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':
|
386 |
-
'
|
387 |
-
} for rec in final_recommendations[:10]]
|
388 |
-
|
|
|
389 |
history_component.save_search(
|
390 |
-
user_preferences=
|
|
|
|
|
|
|
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)]
|
|
|
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': i + 1, # 確保從1開始計數
|
406 |
+
'score': round(rec['final_score'] * 100, 1) # 轉換為百分比格式
|
407 |
+
} for i, rec in enumerate(final_recommendations[:10])]
|
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)]
|