waseoke commited on
Commit
bbd4750
·
verified ·
1 Parent(s): a7ba917

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -36,31 +36,38 @@ def main():
36
  model = load_trained_model("product_model.pth")
37
 
38
  # Step 3: 추천을 위한 사용자 ID 입력
39
- user_id = st.text.input("사용자 ID 입력: ")
40
- print(f"사용자 ID: {user_id}에게 추천해줄 상품 찾는 중...")
41
 
42
- try:
43
- # Step 4: 사용자와 가장 유사한 anchor 찾기
44
- print(f"사용자 ID: {user_id} 와 가장 유사한 anchor 찾는 중...")
45
- most_similar_anchor, most_similar_anchor_embedding = find_most_similar_anchor(
46
- user_id, model
47
- )
48
- print(f"가장 유사한 anchor: {most_similar_anchor}")
49
 
50
- # Step 5: anchor와 가장 유사한 상품 찾기
51
- print("anchor와 가장 유사한 학습 상품 찾는 중...")
52
- most_similar_product, most_similar_product_embedding = (
53
- find_most_similar_product(most_similar_anchor_embedding, model)
54
- )
55
- print(f"anchor와 가장 유사한 학습 상품 ID: {most_similar_product}")
56
 
57
- # Step 6: 쇼핑몰 상품 추천
58
- print("추천 쇼핑몰 상품 찾는 중...")
59
- recommended_product_id = recommend_shop_product(most_similar_product_embedding)
60
- print(f"추천 쇼핑몰 상품 ID: {recommended_product_id}")
 
 
 
61
 
62
- except Exception as e:
63
- print(f"An error occurred during the recommendation process: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
 
66
  if __name__ == "__main__":
 
36
  model = load_trained_model("product_model.pth")
37
 
38
  # Step 3: 추천을 위한 사용자 ID 입력
39
+ if "user_id" not in st.session_state:
40
+ st.session_state["user_id"] = ""
41
 
42
+ user_id = st.text_input("사용자 ID 입력:", st.session_state["user_id"])
 
 
 
 
 
 
43
 
44
+ if user_id:
45
+ print(f"사용자 ID: {user_id}에게 추천해줄 상품 찾는 중...")
 
 
 
 
46
 
47
+ try:
48
+ # Step 4: 사용자와 가장 유사한 anchor 찾기
49
+ print(f"사용자 ID: {user_id} 와 가장 유사한 anchor 찾는 중...")
50
+ most_similar_anchor, most_similar_anchor_embedding = find_most_similar_anchor(
51
+ user_id, model
52
+ )
53
+ print(f"가장 유사한 anchor: {most_similar_anchor}")
54
 
55
+ # Step 5: anchor와 가장 유사한 상품 찾기
56
+ print("anchor와 가장 유사한 학습 상품 찾는 중...")
57
+ most_similar_product, most_similar_product_embedding = (
58
+ find_most_similar_product(most_similar_anchor_embedding, model)
59
+ )
60
+ print(f"anchor와 가장 유사한 학습 상품 ID: {most_similar_product}")
61
+
62
+ # Step 6: 쇼핑몰 상품 추천
63
+ print("추천 쇼핑몰 상품 찾는 중...")
64
+ recommended_product_id = recommend_shop_product(most_similar_product_embedding)
65
+ print(f"추천 쇼핑몰 상품 ID: {recommended_product_id}")
66
+
67
+ except Exception as e:
68
+ print(f"An error occurred during the recommendation process: {e}")
69
+ else:
70
+ st.write("사용자 ID를 입력해주세요.")
71
 
72
 
73
  if __name__ == "__main__":