import streamlit as st import pickle from html_information import html 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, rec_dict: dict) -> None: st.header(header_name) st.write(rec_dict) mid_section = "" for index, value in enumerate(rec_item_url): mid_section += """

""" + str(rec_item_name[index]) + """

""" mid_html = html + mid_section + """""" st.markdown(mid_html, unsafe_allow_html=True) def get_mapped_values(uid_list, uid_map_dict): res = [] for val in uid_list: res.append(uid_map_dict[val]) return res uid_name_map = load_pickle_file('generalize_uid_name_map.pkl') uid_media_map = load_pickle_file('generalize_uid_media_map.pkl') img_rec = load_pickle_file('img.pkl') text_rec = load_pickle_file('text.pkl') both_rec = load_pickle_file('both.pkl') text_dict = { "path": "gs://cml-datalake-dev/fynd_latest.json", "row": ["uid", "slug", "brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color", "medias"], "multiple_media": True, "max_workers": 15, "clip_model": "ViT-B/32", "token_word": 77, "text_row": ["brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color"], "req_row": ["uid", "slug"], "similarity_fields": ["category_name", "attributes_gender"], "text_weightage": [0.2, 0.2, 0.2, 0.2, 0.2], "text_image_weightage": [0.1, 0.9], "number_recommendations": 50, "collection_name": "similar_product_generalize_img_emd", "mongo_url": "", "mongo_db": "fynd", "both_embeddings": False, "text_embeddings": True } img_dict = { "path": "gs://cml-datalake-dev/fynd_latest.json", "row": ["uid", "slug", "brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color", "medias"], "multiple_media": True, "max_workers": 15, "clip_model": "ViT-B/32", "token_word": 77, "text_row": ["brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color"], "req_row": ["uid", "slug"], "similarity_fields": ["category_name", "attributes_gender"], "text_weightage": [0.2, 0.2, 0.2, 0.2, 0.2], "text_image_weightage": [0.1, 0.9], "number_recommendations": 50, "collection_name": "similar_product_generalize_img_emd", "mongo_url": "", "mongo_db": "fynd", "both_embeddings": False, "text_embeddings": False } both_dict = { "path": "gs://cml-datalake-dev/fynd_latest.json", "row": ["uid", "slug", "brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color", "medias"], "multiple_media": True, "max_workers": 15, "clip_model": "ViT-B/32", "token_word": 77, "text_row": ["brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color"], "req_row": ["uid", "slug"], "similarity_fields": ["category_name", "attributes_gender"], "text_weightage": [0.2, 0.2, 0.2, 0.2, 0.2], "text_image_weightage": [0.1, 0.9], "number_recommendations": 50, "collection_name": "similar_product_generalize_img_emd", "mongo_url": "", "mongo_db": "fynd", "both_embeddings": True, "text_embeddings": False } st.set_page_config(page_title="My App", page_icon=":guardsman:", layout="wide", initial_sidebar_state="auto") st.header("Similar Recommendations") uid_list = list(uid_name_map) uid_name_list = get_mapped_values(uid_list, uid_name_map) st.subheader("Choose a Product") index = st.selectbox("Product List", range(len(uid_name_list)), format_func=lambda x: uid_name_list[x]) query_id = uid_list[index] print(query_id) print() query_url = uid_media_map[query_id] st.image(query_url, width=200) for val in text_rec: if val["product_id"] == query_id: text_rec_list = val["recommendations"] print(text_rec_list) if text_rec_list: text_rec_url = [] text_rec_name = [] for val in text_rec_list: text_rec_url.append(uid_media_map[val["product_id"]]) text_rec_name.append(uid_name_map[val["product_id"]]) streamlit_carousel("Text Recommendations", text_rec_url, text_rec_name, text_dict) else: st.write("No text recommendations found") for val in img_rec: if val["product_id"] == query_id: img_rec_list = val["recommendations"] if img_rec_list: img_rec_url = [] img_rec_name = [] for val in img_rec_list: img_rec_url.append(uid_media_map[val["product_id"]]) img_rec_name.append(uid_name_map[val["product_id"]]) streamlit_carousel("Image Recommendations", img_rec_url, img_rec_name, img_dict) else: st.write("No both recommendations found") for val in both_rec: if val["product_id"] == query_id: both_rec_list = val["recommendations"] if both_rec_list: both_rec_url = [] both_rec_name = [] for val in both_rec_list: both_rec_url.append(uid_media_map[val["product_id"]]) both_rec_name.append(uid_name_map[val["product_id"]]) streamlit_carousel("Both Recommendations 0.1 Text 0.9 Image Weightage", both_rec_url, both_rec_name, both_dict) else: st.write("No both recommendations found")