Update app.py
Browse files
app.py
CHANGED
@@ -1037,6 +1037,8 @@ def recommend_content_based(user_profile, top_n=5):
|
|
1037 |
user_extroversion = user_profile.get("extroversion", "")
|
1038 |
user_feeling_thinking = user_profile.get("feeling_thinking", "")
|
1039 |
|
|
|
|
|
1040 |
for item in items:
|
1041 |
item_id = item["item_id"]
|
1042 |
item_emb = item_embedding_dict[item_id]
|
@@ -1045,21 +1047,19 @@ def recommend_content_based(user_profile, top_n=5):
|
|
1045 |
# ๊ธฐ๋ณธ ๊ฐ์ค์น
|
1046 |
weight = 1.0
|
1047 |
|
1048 |
-
# (1) ์ทจ๋ฏธ ๊ฐ์ค์น
|
1049 |
desc_hobby = extract_hobby(item["desc"]) # ์: "(์ด๋, ํฌ์ค)"
|
1050 |
|
1051 |
-
# [hobby] ๊ฐ ์์๊ฐ desc_hobby์ ์์ผ๋ฉด ๊ฐ์ค์น ๋ถ์ฌ
|
1052 |
for h in user_hobbies:
|
1053 |
if h in desc_hobby:
|
1054 |
-
weight *= 1.
|
|
|
1055 |
|
1056 |
-
# [detail_hobby] ๊ฐ ์์๊ฐ desc_hobby์ ์์ผ๋ฉด ๊ฐ์ค์น ๋ถ์ฌ
|
1057 |
for dh in user_details:
|
1058 |
if dh in desc_hobby:
|
1059 |
-
weight *= 1.3
|
1060 |
|
1061 |
-
# (2) ์ฑํฅ
|
1062 |
-
# ์ฑํฅ 2๊ฐ(์ธํฅํ/๋ดํฅํ, ๊ฐ์ ํ/์ด์ฑํ) ์ค ๋ช ๊ฐ๊ฐ ๋งค์นญ๋๋์ง
|
1063 |
personality_match_count = sum(
|
1064 |
trait in item["personality"]
|
1065 |
for trait in [user_extroversion, user_feeling_thinking]
|
@@ -1074,7 +1074,26 @@ def recommend_content_based(user_profile, top_n=5):
|
|
1074 |
|
1075 |
# ์ ์๊ฐ ๋์ ์์ผ๋ก ์ ๋ ฌ
|
1076 |
scored.sort(key=lambda x: x[1], reverse=True)
|
1077 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1078 |
|
1079 |
|
1080 |
#####################################
|
@@ -1215,8 +1234,8 @@ def chat_or_recommend(req: ChatOrRecommendRequest):
|
|
1215 |
response_text = "๋น์ ์ ์ํ ๋ง์ถค ์ถ์ฒ์ ๊ฐ์ ธ์์ด์! โบ๏ธ"
|
1216 |
for i, (item, score) in enumerate(top_items, start=1):
|
1217 |
response_text += (
|
1218 |
-
f"{i}. **{item['title']}
|
1219 |
-
f" - {item['desc']}
|
1220 |
)
|
1221 |
response_text += "์ด ์ค์์ ์ด๋ค ํ๋์ด ๊ฐ์ฅ ๋๋ฆฌ์๋์? ๐"
|
1222 |
return {
|
|
|
1037 |
user_extroversion = user_profile.get("extroversion", "")
|
1038 |
user_feeling_thinking = user_profile.get("feeling_thinking", "")
|
1039 |
|
1040 |
+
hobby_count = {hobby: 0 for hobby in user_hobbies} # ์ทจ๋ฏธ๋ณ ์ถ์ฒ ๊ฐ์ ์ ํ
|
1041 |
+
|
1042 |
for item in items:
|
1043 |
item_id = item["item_id"]
|
1044 |
item_emb = item_embedding_dict[item_id]
|
|
|
1047 |
# ๊ธฐ๋ณธ ๊ฐ์ค์น
|
1048 |
weight = 1.0
|
1049 |
|
1050 |
+
# (1) ์ทจ๋ฏธ ๊ฐ์ค์น (๋
์ ์ ๋ฆผ ๋ฐฉ์ง)
|
1051 |
desc_hobby = extract_hobby(item["desc"]) # ์: "(์ด๋, ํฌ์ค)"
|
1052 |
|
|
|
1053 |
for h in user_hobbies:
|
1054 |
if h in desc_hobby:
|
1055 |
+
weight *= 1.1 # ๊ธฐ๋ณธ ๊ฐ์ค์น 1.1๋ฐฐ
|
1056 |
+
hobby_count[h] += 1
|
1057 |
|
|
|
1058 |
for dh in user_details:
|
1059 |
if dh in desc_hobby:
|
1060 |
+
weight *= 1.3 # ์ธ๋ถ ์ทจ๋ฏธ๋ 1.3๋ฐฐ ๊ฐ์ค์น
|
1061 |
|
1062 |
+
# (2) ์ฑํฅ (์ธํฅ/๋ดํฅ, ๊ฐ์ /์ด์ฑ)
|
|
|
1063 |
personality_match_count = sum(
|
1064 |
trait in item["personality"]
|
1065 |
for trait in [user_extroversion, user_feeling_thinking]
|
|
|
1074 |
|
1075 |
# ์ ์๊ฐ ๋์ ์์ผ๋ก ์ ๋ ฌ
|
1076 |
scored.sort(key=lambda x: x[1], reverse=True)
|
1077 |
+
|
1078 |
+
# ๐ข ํน์ ์ทจ๋ฏธ(์: ๋
์)๊ฐ ๊ณผํ๊ฒ ๋์ค๋ ๋ฌธ์ ํด๊ฒฐ (์ต๋ 2๊ฐ ์ ํ)
|
1079 |
+
balanced_recommendations = []
|
1080 |
+
hobby_limits = {hobby: 2 for hobby in user_hobbies} # ๊ฐ ์ทจ๋ฏธ๋ณ ์ต๋ ์ถ์ฒ ๊ฐ์ ์ ํ
|
1081 |
+
|
1082 |
+
for item, score in scored:
|
1083 |
+
item_hobby = extract_hobby(item["desc"]) # "(๋
์, ์์ค)" โ "๋
์, ์์ค"
|
1084 |
+
item_main_hobby = item_hobby.split(", ")[0] if item_hobby else None
|
1085 |
+
|
1086 |
+
# ํน์ ์ทจ๋ฏธ๊ฐ ์ด๋ฏธ ๋๋ฌด ๋ง๋ค๋ฉด ์คํต
|
1087 |
+
if item_main_hobby and hobby_limits.get(item_main_hobby, 0) > 0:
|
1088 |
+
balanced_recommendations.append((item, score))
|
1089 |
+
hobby_limits[item_main_hobby] -= 1
|
1090 |
+
|
1091 |
+
# ์ถ์ฒ ๊ฐ์๊ฐ ์ถฉ๋ถํ๋ฉด ์ข
๋ฃ
|
1092 |
+
if len(balanced_recommendations) >= top_n:
|
1093 |
+
break
|
1094 |
+
|
1095 |
+
return balanced_recommendations
|
1096 |
+
|
1097 |
|
1098 |
|
1099 |
#####################################
|
|
|
1234 |
response_text = "๋น์ ์ ์ํ ๋ง์ถค ์ถ์ฒ์ ๊ฐ์ ธ์์ด์! โบ๏ธ"
|
1235 |
for i, (item, score) in enumerate(top_items, start=1):
|
1236 |
response_text += (
|
1237 |
+
f"{i}. **{item['title']}**"
|
1238 |
+
f" - {item['desc']}"
|
1239 |
)
|
1240 |
response_text += "์ด ์ค์์ ์ด๋ค ํ๋์ด ๊ฐ์ฅ ๋๋ฆฌ์๋์? ๐"
|
1241 |
return {
|