Spaces:
Runtime error
Runtime error
| import pickle | |
| import streamlit as st | |
| from html_information import html | |
| import random | |
| random.seed(42) | |
| def load_pickle_file(file_name): | |
| with open(file_name, 'rb') as f: | |
| return pickle.load(f) | |
| def streamlit_carousel(header_name: str, rec_item_url: list, | |
| rec_item_name: list) -> None: | |
| st.header(header_name) | |
| mid_section = "" | |
| for index, value in enumerate(rec_item_url): | |
| mid_section += """<div class="item"><div id="image-container"><img src='""" + str(value) + """' /></div><p>""" + str(rec_item_name[index]) + """</p></div>""" | |
| mid_html = html + mid_section + """</div></div></body>""" | |
| st.markdown(mid_html, unsafe_allow_html=True) | |
| companies_list = ["JMD", "JMP", "FRESHPIK"] | |
| st.set_page_config(page_title="My App", page_icon=":guardsman:", layout="wide", initial_sidebar_state="auto") | |
| st.header("Similar Products, Bought Together Recommendations") | |
| st.subheader("Choose a Company") | |
| company_name = st.selectbox("Company List", companies_list) | |
| if company_name == "JMD": | |
| id_url = load_pickle_file("jmd_uid_image_url_map.pkl") | |
| bt_document = load_pickle_file("jmd_bt_rec.pkl") | |
| sim_document = load_pickle_file("jmd_sim_rec.pkl") | |
| elif company_name == "JMP": | |
| id_url = load_pickle_file("jmp_uid_image_url_map.pkl") | |
| bt_document = load_pickle_file("jmp_bt_rec.pkl") | |
| sim_document = load_pickle_file("jmp_sim_rec.pkl") | |
| else: | |
| id_url = load_pickle_file("freshpik_uid_image_url_map.pkl") | |
| bt_document = load_pickle_file("freshpik_bt_rec.pkl") | |
| sim_document = load_pickle_file("freshpik_sim_rec.pkl") | |
| product_names = [item["product_name"] for item in bt_document] | |
| st.subheader("Choose a Product") | |
| index = st.selectbox("Product List", range(len(product_names)), format_func=lambda x: product_names[x]) | |
| query_uid = bt_document[index]["product_id"] | |
| print(f"Query ID: {query_uid}") | |
| print() | |
| query_url = id_url[query_uid] | |
| st.image(query_url, width=200) | |
| #sim_recommendations = sim_document[index]["recommendations"] | |
| for val in sim_document: | |
| if val["product_id"] == query_uid: | |
| sim_recommendations = val["recommendations"] | |
| print("Similar Product Recommendations") | |
| print(sim_recommendations) | |
| print() | |
| sim_recommendations_uid = [item["product_id"] for item in sim_recommendations] | |
| sim_recommendations_name = [item["product_name"] for item in sim_recommendations] | |
| sim_recommendations_url = [id_url[item] for item in sim_recommendations_uid] | |
| streamlit_carousel("Similar Product Recommendations", sim_recommendations_url, sim_recommendations_name) | |
| for val in bt_document: | |
| if val["product_id"] == query_uid: | |
| bt_recommendations = val["recommendations"] | |
| print("Bought Together Recommendations") | |
| print(bt_recommendations) | |
| print() | |
| bt_recommendations_uid = [item["product_id"] for item in bt_recommendations] | |
| bt_recommendations_name = [item["product_name"] for item in bt_recommendations] | |
| bt_recommendations_url = [id_url[item] for item in bt_recommendations_uid] | |
| streamlit_carousel("Bought Together Recommendations", bt_recommendations_url, bt_recommendations_name) | |