-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
86 lines (63 loc) · 2.51 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from utils.read_utils import read_yaml_key, read_from_parquet
from utils.images_utils import get_relative_image_path
from src.models.predict_model import Recommendation
from config.config import CONFIGURATION_PATH
import streamlit as st
import os
import gc
model_obj = Recommendation()
@st.cache
def load_customer_id():
PATH = os.path.join(
read_yaml_key(CONFIGURATION_PATH, 'data_source','data_folders'),
'customer_lists.parquet'
)
unique_customer_id = read_from_parquet(PATH)
customer_lists = (unique_customer_id[['customer_id','article_id']]
.groupby('customer_id')['article_id']
.apply(list)
.reset_index()
)
customer_lists = customer_lists.merge(unique_customer_id[['customer_id','org_customer_id']], on = ['customer_id'], how = 'inner')
customer_lists = customer_lists.drop_duplicates(['customer_id','org_customer_id'], keep ='last')
del [unique_customer_id]
gc.collect()
return customer_lists
def recommend(customer_id):
#Recommended Items
recommend_items = model_obj.predict(customer_id)
#Map the recommended items to the image path
recommend_items['image_path'] = list(map(get_relative_image_path, recommend_items['article_id']))
return recommend_items
def main():
st.markdown("<h1 style='text-align: center; font-size: 65px; color: #4682B4;'>{}</h1>".format('Recommender System'),
unsafe_allow_html=True)
st.image("./references/banner.png")
customer_lists = load_customer_id()
selected_customer = st.selectbox(
"Type or select a customer from the dropdown",
customer_lists.org_customer_id.values
)
if st.button('Recommend'):
output = recommend(selected_customer)
items = output.article_id.values
image_path = output.image_path.values
st.header("Recommendation")
cnt = 0
cols = st.columns(5)
for i in range(5):
#cols[i].header(items[cnt])
cols[i].image(image_path[cnt])
cnt += 1
cols = st.columns(5)
for i in range(5):
#[i].header(items[cnt])
cols[i].image(image_path[cnt])
cnt += 1
cols = st.columns(5)
for i in range(5):
#cols[i].header(items[cnt])
cols[i].image(image_path[cnt])
cnt += 1
if __name__ == "__main__":
main()