waseoke commited on
Commit
2dfec3c
·
verified ·
1 Parent(s): e6dc15e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +56 -18
main.py CHANGED
@@ -1,28 +1,66 @@
1
- import torch
 
2
  from calculate_cosine_similarity import (
 
3
  find_most_similar_anchor,
4
  find_most_similar_product,
5
  recommend_shop_product,
6
  )
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def main():
9
- # 사용자 ID 입력
10
- user_id = "user_123" # 사용자 ID 예시
11
-
12
- # Step 1: 사용자와 가장 유사한 anchor 찾기
13
- print(f"Finding the most similar anchor for user {user_id}...")
14
- most_similar_anchor, anchor_embedding = find_most_similar_anchor(user_id)
15
- print(f"Most similar anchor: {most_similar_anchor}")
16
-
17
- # Step 2: anchor와 가장 유사한 상품 찾기
18
- print("Finding the most similar product to the anchor...")
19
- most_similar_product, similar_product_embedding = find_most_similar_product(anchor_embedding)
20
- print(f"Most similar product to anchor: {most_similar_product}")
21
-
22
- # Step 3: 쇼핑몰 상품 추천
23
- print("Recommending the best shop product...")
24
- recommended_product_id = recommend_shop_product(similar_product_embedding)
25
- print(f"Recommended shop product ID: {recommended_product_id}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  if __name__ == "__main__":
28
  main()
 
1
+ import os
2
+ from subprocess import run
3
  from calculate_cosine_similarity import (
4
+ load_trained_model,
5
  find_most_similar_anchor,
6
  find_most_similar_product,
7
  recommend_shop_product,
8
  )
9
 
10
+
11
+ def execute_script(script_name):
12
+ """
13
+ Helper function to execute a Python script.
14
+ """
15
+ print(f"Executing {script_name}...")
16
+ result = run(["python", script_name], capture_output=True, text=True)
17
+ if result.returncode == 0:
18
+ print(f"{script_name} executed successfully.")
19
+ else:
20
+ print(f"Error executing {script_name}:")
21
+ print(result.stderr)
22
+
23
+
24
  def main():
25
+ # # Step 0: 모델 학습
26
+ print("Step 1: 모델 학습 중...")
27
+ execute_script("train_model.py")
28
+
29
+ # Step 1: 쇼핑물 상품과 사용자 임베딩
30
+ print("Step 2: 쇼핑물 상품과 사용자 임베딩...")
31
+ execute_script("embed_data.py")
32
+
33
+ # Step 2: product_model.pth 불러오기
34
+ print("Step 3: product_model.pth 불러오는 중...")
35
+ model = load_trained_model("product_model.pth")
36
+
37
+ # Step 3: 추천을 위한 사용자 ID 입력
38
+ user_id = input("사용자 ID 입력: ").strip()
39
+ print(f"사용자 ID: {user_id}에게 추천해줄 상품 찾는 중...")
40
+
41
+ try:
42
+ # Step 4: 사용자와 가장 유사한 anchor 찾기
43
+ print(f"사용자 ID: {user_id} 와 가장 유사한 anchor 찾는 중...")
44
+ most_similar_anchor, most_similar_anchor_embedding = find_most_similar_anchor(
45
+ user_id, model
46
+ )
47
+ print(f"가장 유사한 anchor: {most_similar_anchor}")
48
+
49
+ # Step 5: anchor와 가장 유사한 상품 찾기
50
+ print("anchor와 가장 유사한 학습 상품 찾는 중...")
51
+ most_similar_product, most_similar_product_embedding = (
52
+ find_most_similar_product(most_similar_anchor_embedding, model)
53
+ )
54
+ print(f"anchor와 가장 유사한 학습 상품 ID: {most_similar_product}")
55
+
56
+ # Step 6: 쇼핑몰 상품 추천
57
+ print("추천 쇼핑몰 상품 찾는 중...")
58
+ recommended_product_id = recommend_shop_product(most_similar_product_embedding)
59
+ print(f"추천 쇼핑몰 상품 ID: {recommended_product_id}")
60
+
61
+ except Exception as e:
62
+ print(f"An error occurred during the recommendation process: {e}")
63
+
64
 
65
  if __name__ == "__main__":
66
  main()