DawnC commited on
Commit
4180a1b
1 Parent(s): 293f73d

Update breed_recommendation.py

Browse files
Files changed (1) hide show
  1. 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': 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)]
@@ -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