File size: 3,654 Bytes
c3f3d16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94f6f46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3f3d16
 
 
94f6f46
 
 
 
 
 
c3f3d16
 
 
 
 
 
 
 
 
 
 
 
 
94f6f46
 
 
 
 
 
c3f3d16
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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")