| import streamlit as st |
| import pickle |
| from html_information2 import html2 |
|
|
| st.set_page_config(layout="wide") |
|
|
| |
| def read_pickle_files(pickle_file): |
| with open(pickle_file, 'rb') as f: |
| return pickle.load(f) |
|
|
| |
| cross_sell_data = read_pickle_files("fynd.cross_sell_recommendations-000000000000000000000001s.pkl") |
| upsell_data = read_pickle_files("fynd.up_sell_recommendations_000000000000000000000002s.pkl") |
| uid_name_pairs = read_pickle_files("uid_name_pairs.pkl") |
| uid_image_html_pairs = read_pickle_files("uid_image_html_pairs.pkl") |
| item_costs_sephora_data = read_pickle_files("sephora_prices.pkl") |
|
|
|
|
| |
| product_name_to_id = {name: uid for name, uid in uid_name_pairs.items()} |
| product_id_to_name = {uid: name for name, uid in uid_name_pairs.items()} |
|
|
| |
| def extract_product_list(recommendation_data): |
| product_ids = [entry['product_id'] for entry in recommendation_data] |
| |
| return [product_id_to_name[product_id] for product_id in product_ids if product_id in product_id_to_name] |
|
|
| |
| def get_recommendations(product_id, recommendation_data): |
| for product in recommendation_data: |
| if product['product_id'] == product_id: |
| return product['recommendations'] |
| return [] |
|
|
| |
| st.title("Cross-Sell & Up-Sell Recommendations") |
|
|
| |
| recommendation_type = st.selectbox("Select recommendation type:", ["Cross-sell", "Up-sell"]) |
|
|
| |
| if recommendation_type == "Cross-sell": |
| recommendations_data = cross_sell_data |
| elif recommendation_type == "Up-sell": |
| recommendations_data = upsell_data |
|
|
| |
| product_list = extract_product_list(recommendations_data) |
|
|
| |
| selected_product_name = st.selectbox("Select a product:", product_list) |
|
|
| |
| selected_product_id = product_name_to_id.get(selected_product_name) |
|
|
| |
| if selected_product_id: |
| |
| |
| |
| |
| if selected_product_id in uid_image_html_pairs: |
| image_url = uid_image_html_pairs[selected_product_id] |
| st.image(image_url, use_column_width=False, width=450) |
| items_cost_is = item_costs_sephora_data[str(selected_product_id)] |
| st.write("Product Price:",str(items_cost_is) ) |
|
|
|
|
| |
| if selected_product_id: |
| recommendations = get_recommendations(selected_product_id, recommendations_data) |
| reccomendation_names = [] |
| reccomendation_images = [] |
| reccomendation_costs = [] |
| |
| |
|
|
| if recommendations: |
| |
| if len(recommendations)>10: |
| recommendations= recommendations[:10] |
| else: |
| pass |
|
|
| for recommendation in recommendations: |
| product_name = recommendation.get('product_name') |
| recommended_product_id = recommendation.get('product_id') |
| recommended_product_cost = item_costs_sephora_data.get(str(recommended_product_id), "item missing") |
|
|
| |
| if recommended_product_id in uid_image_html_pairs: |
| recommended_image_url = uid_image_html_pairs[recommended_product_id] |
| |
|
|
| reccomendation_names.append(product_name) |
| reccomendation_images.append(recommended_image_url) |
| reccomendation_costs.append(recommended_product_cost) |
|
|
| |
| else: |
| st.write("No recommendations found for this product.") |
| |
| mid_section = "" |
| for index, value in enumerate(reccomendation_names): |
| |
| |
| mid_section += f"""<div class="item"> |
| <div id="image-container"><img src='{reccomendation_images[index]}' /></div> |
| <p style="font-size: 16px; font-weight: bold; white-space: normal; word-wrap: break-word;">{str(reccomendation_names[index])}</p> |
| <p>Product Price: {reccomendation_costs[index]}</p> |
| </div>""" |
| mid_html = html2 + mid_section + """</div></div></body>""" |
| st.markdown(mid_html, unsafe_allow_html=True) |