Spaces:
Runtime error
Runtime error
| 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) -> 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) | |
| def get_mapped_values(uid_list, uid_map_dict): | |
| res = [] | |
| for val in uid_list: | |
| res.append(uid_map_dict[val]) | |
| return res | |
| def carousel_wrapper(rec_list, query_id, uid_media_map, uid_name_map, header_name, exception_header_name): | |
| for val in rec_list: | |
| 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(header_name, text_rec_url, text_rec_name) | |
| else: | |
| st.write(exception_header_name) | |
| uid_name_map = load_pickle_file('generalize_uid_name_map.pkl') | |
| uid_media_map = load_pickle_file('generalize_uid_media_map.pkl') | |
| color_global_local_filters_rec = load_pickle_file('color_global_local_filters.pkl') | |
| color_no_filters_rec = load_pickle_file('color_no_filters.pkl') | |
| no_color_global_local_filters_rec = load_pickle_file('no_color_global_local_filters.pkl') | |
| no_color_no_filters_rec = load_pickle_file('no_color_no_filters.pkl') | |
| no_color_no_filters_attributes_rank_1_rec = load_pickle_file('no_color_no_filters_attributes_rank_1.pkl') | |
| no_color_no_filters_brand_rank_1_rec = load_pickle_file('no_color_no_filters_brand_rank_1.pkl') | |
| st.set_page_config(page_title="My App", page_icon=":guardsman:", layout="wide", initial_sidebar_state="auto") | |
| st.header("Bought Together 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) | |
| carousel_wrapper(color_global_local_filters_rec, query_id, uid_media_map, uid_name_map, "Color Global Filter: 'Jeans', Local Filter: No 'Trousers' for 'Formal Shirts'", "No BT recommendations found") | |
| carousel_wrapper(no_color_global_local_filters_rec, query_id, uid_media_map, uid_name_map, "No Color Global Filter: 'Jeans', Local Filter: No 'Trousers' for 'Formal Shirts'", "No BT recommendations found") | |
| carousel_wrapper(color_no_filters_rec, query_id, uid_media_map, uid_name_map, "Color No Filters", "No BT recommendations found") | |
| carousel_wrapper(no_color_no_filters_rec, query_id, uid_media_map, uid_name_map, "No Color No Filters", "No BT recommendations found") | |
| carousel_wrapper(no_color_no_filters_attributes_rank_1_rec, query_id, uid_media_map, uid_name_map, "No Color No Filters Attributes Name Rank 1", "No BT recommendations found") | |
| carousel_wrapper(no_color_no_filters_brand_rank_1_rec, query_id, uid_media_map, uid_name_map, "No Color No Filters Brand Name Rank 1", "No BT recommendations found") | |