Spaces:
Runtime error
Runtime error
initial commit
Browse files- app.py +77 -0
- freshpik_bt_rec.pkl +3 -0
- freshpik_sim_rec.pkl +3 -0
- freshpik_uid_image_url_map.pkl +3 -0
- html_information.py +69 -0
- jmd_bt_rec.pkl +3 -0
- jmd_sim_rec.pkl +3 -0
- jmd_uid_image_url_map.pkl +3 -0
- jmp_bt_rec.pkl +3 -0
- jmp_sim_rec.pkl +3 -0
- jmp_uid_image_url_map.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from html_information import html
|
| 4 |
+
import random
|
| 5 |
+
random.seed(42)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def load_pickle_file(file_name):
|
| 9 |
+
with open(file_name, 'rb') as f:
|
| 10 |
+
return pickle.load(f)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def streamlit_carousel(header_name: str, rec_item_url: list,
|
| 14 |
+
rec_item_name: list) -> None:
|
| 15 |
+
st.header(header_name)
|
| 16 |
+
mid_section = ""
|
| 17 |
+
for index, value in enumerate(rec_item_url):
|
| 18 |
+
mid_section += """<div class="item"><div id="image-container"><img src='""" + str(value) + """' /></div><p>""" + str(rec_item_name[index]) + """</p></div>"""
|
| 19 |
+
|
| 20 |
+
mid_html = html + mid_section + """</div></div></body>"""
|
| 21 |
+
st.markdown(mid_html, unsafe_allow_html=True)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
companies_list = ["JMD", "JMP", "FRESHPIK"]
|
| 25 |
+
st.set_page_config(page_title="My App", page_icon=":guardsman:", layout="wide", initial_sidebar_state="auto")
|
| 26 |
+
st.header("Similar Products, Bought Together Recommendations")
|
| 27 |
+
st.subheader("Choose a Company")
|
| 28 |
+
company_name = st.selectbox("Company List", companies_list)
|
| 29 |
+
if company_name == "JMD":
|
| 30 |
+
id_url = load_pickle_file("jmd_uid_image_url_map.pkl")
|
| 31 |
+
bt_document = load_pickle_file("jmd_bt_rec.pkl")
|
| 32 |
+
sim_document = load_pickle_file("jmd_sim_rec.pkl")
|
| 33 |
+
elif company_name == "JMP":
|
| 34 |
+
id_url = load_pickle_file("jmp_uid_image_url_map.pkl")
|
| 35 |
+
bt_document = load_pickle_file("jmp_bt_rec.pkl")
|
| 36 |
+
sim_document = load_pickle_file("jmp_sim_rec.pkl")
|
| 37 |
+
else:
|
| 38 |
+
id_url = load_pickle_file("freshpik_uid_image_url_map.pkl")
|
| 39 |
+
bt_document = load_pickle_file("freshpik_bt_rec.pkl")
|
| 40 |
+
sim_document = load_pickle_file("freshpik_sim_rec.pkl")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
product_names = [item["product_name"] for item in bt_document]
|
| 44 |
+
st.subheader("Choose a Product")
|
| 45 |
+
index = st.selectbox("Product List", range(len(product_names)), format_func=lambda x: product_names[x])
|
| 46 |
+
query_uid = bt_document[index]["product_id"]
|
| 47 |
+
print(f"Query ID: {query_uid}")
|
| 48 |
+
print()
|
| 49 |
+
query_url = id_url[query_uid]
|
| 50 |
+
st.image(query_url, width=200)
|
| 51 |
+
|
| 52 |
+
#sim_recommendations = sim_document[index]["recommendations"]
|
| 53 |
+
|
| 54 |
+
for val in sim_document:
|
| 55 |
+
if val["product_id"] == query_uid:
|
| 56 |
+
sim_recommendations = val["recommendations"]
|
| 57 |
+
|
| 58 |
+
print("Similar Product Recommendations")
|
| 59 |
+
print(sim_recommendations)
|
| 60 |
+
print()
|
| 61 |
+
sim_recommendations_uid = [item["product_id"] for item in sim_recommendations]
|
| 62 |
+
sim_recommendations_name = [item["product_name"] for item in sim_recommendations]
|
| 63 |
+
sim_recommendations_url = [id_url[item] for item in sim_recommendations_uid]
|
| 64 |
+
streamlit_carousel("Similar Product Recommendations", sim_recommendations_url, sim_recommendations_name)
|
| 65 |
+
|
| 66 |
+
for val in bt_document:
|
| 67 |
+
if val["product_id"] == query_uid:
|
| 68 |
+
bt_recommendations = val["recommendations"]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
print("Bought Together Recommendations")
|
| 72 |
+
print(bt_recommendations)
|
| 73 |
+
print()
|
| 74 |
+
bt_recommendations_uid = [item["product_id"] for item in bt_recommendations]
|
| 75 |
+
bt_recommendations_name = [item["product_name"] for item in bt_recommendations]
|
| 76 |
+
bt_recommendations_url = [id_url[item] for item in bt_recommendations_uid]
|
| 77 |
+
streamlit_carousel("Bought Together Recommendations", bt_recommendations_url, bt_recommendations_name)
|
freshpik_bt_rec.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5524cdedc49a91d026637d46c62ba0acae94e31587de4ebd96276e57e19d5bd2
|
| 3 |
+
size 3430543
|
freshpik_sim_rec.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:baf7f829d88e3815ec61d61c3df17055115a03297b8c3667344b9262b11fbfe4
|
| 3 |
+
size 3199878
|
freshpik_uid_image_url_map.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f8e8c891409b686a6f6c2222b2d7ae64638e0d06d5130afe6ab031a52893b5d9
|
| 3 |
+
size 393643
|
html_information.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
html = """
|
| 2 |
+
<style>
|
| 3 |
+
body{
|
| 4 |
+
font-family: sans-serif;
|
| 5 |
+
}
|
| 6 |
+
h1{
|
| 7 |
+
font-weight: 100;
|
| 8 |
+
}
|
| 9 |
+
.container{
|
| 10 |
+
width: 100%;
|
| 11 |
+
display:block;
|
| 12 |
+
overflow:hidden;
|
| 13 |
+
}
|
| 14 |
+
.carousel{
|
| 15 |
+
display:block;
|
| 16 |
+
width: 100%;
|
| 17 |
+
height: 320px;
|
| 18 |
+
background: white;
|
| 19 |
+
overflow-x: scroll;
|
| 20 |
+
padding: 10px;
|
| 21 |
+
margin: 0;
|
| 22 |
+
white-space: nowrap;
|
| 23 |
+
border-top: 2px solid rgba(0, 0, 0, 0.1);
|
| 24 |
+
border-bottom: 2px solid rgba(0, 0, 0, 0.1);
|
| 25 |
+
}
|
| 26 |
+
.item {
|
| 27 |
+
display: inline-block;
|
| 28 |
+
overflow: hidden;
|
| 29 |
+
width: 250px;
|
| 30 |
+
margin: 0 10px;
|
| 31 |
+
height: calc(100%);
|
| 32 |
+
background: rgba(0, 0, 0, 0.05) no-repeat center center;
|
| 33 |
+
background-size: cover;
|
| 34 |
+
position:relative;
|
| 35 |
+
border-radius: 20px;
|
| 36 |
+
box-shadow: 0 0 10px #dfdfdf;
|
| 37 |
+
}
|
| 38 |
+
.item p {
|
| 39 |
+
padding: 20px;
|
| 40 |
+
word-break: break-all;
|
| 41 |
+
white-space: break-spaces;
|
| 42 |
+
overflow: hidden;
|
| 43 |
+
display: -webkit-box;
|
| 44 |
+
-webkit-line-clamp: 4;
|
| 45 |
+
-webkit-box-orient: vertical;
|
| 46 |
+
margin: 0;
|
| 47 |
+
align: center;
|
| 48 |
+
}
|
| 49 |
+
#image-container{
|
| 50 |
+
width: 100%;
|
| 51 |
+
height: 60%;
|
| 52 |
+
text-align:center;
|
| 53 |
+
font-size: 9em;
|
| 54 |
+
color: white;
|
| 55 |
+
overflow: hidden;
|
| 56 |
+
}
|
| 57 |
+
#image-container img{
|
| 58 |
+
width: 100%;
|
| 59 |
+
height: 100%;
|
| 60 |
+
object-fit: contain;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
</style>
|
| 64 |
+
</head>
|
| 65 |
+
<body>
|
| 66 |
+
<div class="container">
|
| 67 |
+
<div class="carousel">
|
| 68 |
+
|
| 69 |
+
"""
|
jmd_bt_rec.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a5a86e9db94e9d8c76bc6f4c6430a515d85c68780c6c1f033dc6458a14e11223
|
| 3 |
+
size 14909452
|
jmd_sim_rec.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68c1832f403205340d76e427af931367b03296471e5f30a55a922fd73105b1a3
|
| 3 |
+
size 18187489
|
jmd_uid_image_url_map.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:becf3f3010d1b050b01fb12c450f802a80e7956dddcac947ee778032b090c6b2
|
| 3 |
+
size 1537022
|
jmp_bt_rec.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf6aaa999cb9065ec7f7e67d2896b84ee730b0c88ac2c19c77070d3dcaea584a
|
| 3 |
+
size 64114321
|
jmp_sim_rec.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6acfe7f41308f79a23262c11a01907458fdb935f638f5f032b250e16e6513456
|
| 3 |
+
size 65712337
|
jmp_uid_image_url_map.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a15e8174053ce9aeeecff7a406961f66245753ea5b4ac38ed916a3bfba0abc37
|
| 3 |
+
size 5202317
|