Upload 5 files
Browse files
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
|
4 |
+
# Function to load pickle files
|
5 |
+
def read_pickle_files(pickle_file):
|
6 |
+
with open(pickle_file, 'rb') as f:
|
7 |
+
return pickle.load(f)
|
8 |
+
|
9 |
+
# Load the necessary pickle files
|
10 |
+
cross_sell_data = read_pickle_files("fynd.cross_sell_recommendations-000000000000000000000001s.pkl")
|
11 |
+
upsell_data = read_pickle_files("fynd.up_sell_recommendations_000000000000000000000002s.pkl")
|
12 |
+
catalog_data = read_pickle_files("clickstream_data_sephora_sephora_products_1724404940894(1).pkl")
|
13 |
+
uid_name_pairs = read_pickle_files("uid_name_pairs.pkl")
|
14 |
+
|
15 |
+
# Create a mapping from product_id to product name for dropdown
|
16 |
+
product_name_to_id = {name: uid for name, uid in uid_name_pairs.items()}
|
17 |
+
|
18 |
+
# Create a reverse mapping from product_id to product_name for display purposes
|
19 |
+
product_id_to_name = {uid: name for name, uid in uid_name_pairs.items()}
|
20 |
+
|
21 |
+
# Function to get product image URL from catalog
|
22 |
+
def get_product_image_url(product_id, catalog_data):
|
23 |
+
for product in catalog_data:
|
24 |
+
if product['uid'] == product_id:
|
25 |
+
medias = product.get('medias', [])
|
26 |
+
if medias and 'url' in medias[0]:
|
27 |
+
return medias[0]['url']
|
28 |
+
return None
|
29 |
+
|
30 |
+
# Extract product names from recommendation data
|
31 |
+
def extract_product_list(recommendation_data):
|
32 |
+
product_ids = [entry['product_id'] for entry in recommendation_data]
|
33 |
+
# Map the product IDs to names for the dropdown
|
34 |
+
return [product_id_to_name[product_id] for product_id in product_ids if product_id in product_id_to_name]
|
35 |
+
|
36 |
+
# Extract recommendations for a specific product_id
|
37 |
+
def get_recommendations(product_id, recommendation_data):
|
38 |
+
for product in recommendation_data:
|
39 |
+
if product['product_id'] == product_id:
|
40 |
+
return product['recommendations']
|
41 |
+
return []
|
42 |
+
|
43 |
+
# Streamlit App Layout
|
44 |
+
st.title("Product Recommendations")
|
45 |
+
|
46 |
+
# Dropdown for selecting type (cross-sell or up-sell)
|
47 |
+
recommendation_type = st.selectbox("Select recommendation type:", ["Cross-sell", "Up-sell"])
|
48 |
+
|
49 |
+
# Choose the appropriate data based on recommendation type
|
50 |
+
if recommendation_type == "Cross-sell":
|
51 |
+
recommendations_data = cross_sell_data
|
52 |
+
elif recommendation_type == "Up-sell":
|
53 |
+
recommendations_data = upsell_data
|
54 |
+
|
55 |
+
# Get the list of product names for the dropdown
|
56 |
+
product_list = extract_product_list(recommendations_data)
|
57 |
+
|
58 |
+
# Dropdown for selecting a product by name
|
59 |
+
selected_product_name = st.selectbox("Select a product:", product_list)
|
60 |
+
|
61 |
+
# Get the selected product's ID using the name
|
62 |
+
selected_product_id = product_name_to_id.get(selected_product_name)
|
63 |
+
|
64 |
+
# Display recommendations for the selected product
|
65 |
+
if selected_product_id:
|
66 |
+
recommendations = get_recommendations(selected_product_id, recommendations_data)
|
67 |
+
|
68 |
+
if recommendations:
|
69 |
+
st.subheader(f"Recommendations for {selected_product_name}")
|
70 |
+
for recommendation in recommendations:
|
71 |
+
product_name = recommendation.get('product_name')
|
72 |
+
product_image_url = get_product_image_url(recommendation['product_id'], catalog_data)
|
73 |
+
|
74 |
+
if product_image_url:
|
75 |
+
st.image(product_image_url, width=100) # Display image
|
76 |
+
st.write(f"{product_name}")
|
77 |
+
else:
|
78 |
+
st.write("No recommendations found for this product.")
|
clickstream_data_sephora_sephora_products_1724404940894(1).pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3f3e3565f77f7caf2dbe01721d069edf9a468b70654767aeec3cc2c6bd8c4eda
|
3 |
+
size 116037960
|
fynd.cross_sell_recommendations-000000000000000000000001s.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1bfa8af834b192563f67095e128b888669024641d66781baf81fc1c7be8ca8a8
|
3 |
+
size 108384783
|
fynd.up_sell_recommendations_000000000000000000000002s.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:47b70f4be3b7eb9f69c0289aa2a808409248e6849a01f18e722863369e4cdd54
|
3 |
+
size 118980067
|
uid_name_pairs.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8575bfa829cce8796a1a2dd1a2b612b2e552871ba0c61daad067f311021d7c55
|
3 |
+
size 756290
|