subhankarfynd commited on
Commit
0d97de6
·
1 Parent(s): 7f6257b

Add initial files

Browse files
app.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ from html_information import html
4
+
5
+
6
+ def load_pickle_file(file_name):
7
+ with open(file_name, 'rb') as f:
8
+ return pickle.load(f)
9
+
10
+
11
+ def streamlit_carousel(header_name: str, rec_item_url: list,
12
+ rec_item_name: list, rec_dict: dict) -> None:
13
+ st.header(header_name)
14
+ st.write(rec_dict)
15
+ mid_section = ""
16
+ for index, value in enumerate(rec_item_url):
17
+ mid_section += """<div class="item"><div id="image-container"><img src='""" + str(value) + """' /></div><p>""" + str(rec_item_name[index]) + """</p></div>"""
18
+
19
+ mid_html = html + mid_section + """</div></div></body>"""
20
+ st.markdown(mid_html, unsafe_allow_html=True)
21
+
22
+
23
+ def get_mapped_values(uid_list, uid_map_dict):
24
+ res = []
25
+ for val in uid_list:
26
+ res.append(uid_map_dict[val])
27
+ return res
28
+
29
+
30
+ uid_name_map = load_pickle_file('generalize_uid_name_map.pkl')
31
+ uid_media_map = load_pickle_file('generalize_uid_media_map.pkl')
32
+ img_rec = load_pickle_file('img.pkl')
33
+ text_rec = load_pickle_file('text.pkl')
34
+ both_rec = load_pickle_file('both.pkl')
35
+
36
+
37
+ text_dict = {
38
+ "path": "gs://cml-datalake-dev/fynd_latest.json",
39
+ "row": ["uid", "slug", "brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color", "medias"],
40
+ "multiple_media": True,
41
+ "max_workers": 15,
42
+ "clip_model": "ViT-B/32",
43
+ "token_word": 77,
44
+ "text_row": ["brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color"],
45
+ "req_row": ["uid", "slug"],
46
+ "similarity_fields": ["category_name", "attributes_gender"],
47
+ "text_weightage": [0.2, 0.2, 0.2, 0.2, 0.2],
48
+ "text_image_weightage": [0.1, 0.9],
49
+ "number_recommendations": 50,
50
+ "collection_name": "similar_product_generalize_img_emd",
51
+ "mongo_url": "",
52
+ "mongo_db": "fynd",
53
+ "both_embeddings": False,
54
+ "text_embeddings": True
55
+ }
56
+
57
+
58
+ img_dict = {
59
+ "path": "gs://cml-datalake-dev/fynd_latest.json",
60
+ "row": ["uid", "slug", "brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color", "medias"],
61
+ "multiple_media": True,
62
+ "max_workers": 15,
63
+ "clip_model": "ViT-B/32",
64
+ "token_word": 77,
65
+ "text_row": ["brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color"],
66
+ "req_row": ["uid", "slug"],
67
+ "similarity_fields": ["category_name", "attributes_gender"],
68
+ "text_weightage": [0.2, 0.2, 0.2, 0.2, 0.2],
69
+ "text_image_weightage": [0.1, 0.9],
70
+ "number_recommendations": 50,
71
+ "collection_name": "similar_product_generalize_img_emd",
72
+ "mongo_url": "",
73
+ "mongo_db": "fynd",
74
+ "both_embeddings": False,
75
+ "text_embeddings": False
76
+ }
77
+
78
+ both_dict = {
79
+ "path": "gs://cml-datalake-dev/fynd_latest.json",
80
+ "row": ["uid", "slug", "brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color", "medias"],
81
+ "multiple_media": True,
82
+ "max_workers": 15,
83
+ "clip_model": "ViT-B/32",
84
+ "token_word": 77,
85
+ "text_row": ["brand_name", "category_name", "attributes_gender", "attributes_name", "attributes_color"],
86
+ "req_row": ["uid", "slug"],
87
+ "similarity_fields": ["category_name", "attributes_gender"],
88
+ "text_weightage": [0.2, 0.2, 0.2, 0.2, 0.2],
89
+ "text_image_weightage": [0.1, 0.9],
90
+ "number_recommendations": 50,
91
+ "collection_name": "similar_product_generalize_img_emd",
92
+ "mongo_url": "",
93
+ "mongo_db": "fynd",
94
+ "both_embeddings": True,
95
+ "text_embeddings": False
96
+ }
97
+
98
+
99
+ st.set_page_config(page_title="My App", page_icon=":guardsman:", layout="wide", initial_sidebar_state="auto")
100
+ st.header("Similar Recommendations")
101
+ uid_list = list(uid_name_map)
102
+ uid_name_list = get_mapped_values(uid_list, uid_name_map)
103
+ st.subheader("Choose a Product")
104
+ index = st.selectbox("Product List", range(len(uid_name_list)), format_func=lambda x: uid_name_list[x])
105
+ query_id = uid_list[index]
106
+ print(query_id)
107
+ print()
108
+ query_url = uid_media_map[query_id]
109
+ st.image(query_url, width=200)
110
+ for val in text_rec:
111
+ if val["product_id"] == query_id:
112
+ text_rec_list = val["recommendations"]
113
+ print(text_rec_list)
114
+ if text_rec_list:
115
+ text_rec_url = []
116
+ text_rec_name = []
117
+ for val in text_rec_list:
118
+ text_rec_url.append(uid_media_map[val["product_id"]])
119
+ text_rec_name.append(uid_name_map[val["product_id"]])
120
+ streamlit_carousel("Text Recommendations", text_rec_url, text_rec_name, text_dict)
121
+ else:
122
+ st.write("No text recommendations found")
123
+ for val in img_rec:
124
+ if val["product_id"] == query_id:
125
+ img_rec_list = val["recommendations"]
126
+ if img_rec_list:
127
+ img_rec_url = []
128
+ img_rec_name = []
129
+ for val in img_rec_list:
130
+ img_rec_url.append(uid_media_map[val["product_id"]])
131
+ img_rec_name.append(uid_name_map[val["product_id"]])
132
+ streamlit_carousel("Image Recommendations", img_rec_url, img_rec_name, img_dict)
133
+ else:
134
+ st.write("No both recommendations found")
135
+ for val in both_rec:
136
+ if val["product_id"] == query_id:
137
+ both_rec_list = val["recommendations"]
138
+ if both_rec_list:
139
+ both_rec_url = []
140
+ both_rec_name = []
141
+ for val in both_rec_list:
142
+ both_rec_url.append(uid_media_map[val["product_id"]])
143
+ both_rec_name.append(uid_name_map[val["product_id"]])
144
+ streamlit_carousel("Both Recommendations 0.1 Text 0.9 Image Weightage", both_rec_url, both_rec_name, both_dict)
145
+ else:
146
+ st.write("No both recommendations found")
147
+
148
+
149
+
150
+
both.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0c6f45e6cb7649408b5614f5306f751e78085dcdd8eb2525673b4c50f5210247
3
+ size 12405751
generalize_uid_media_map.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2aaaaeb9ce0bada0ce217245d6d922cee8ac9ccb3aaa2f1274804384ab7404d0
3
+ size 1317791
generalize_uid_name_map.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c5fb8c2fc1814b5a30200a49da01cf8c3d56821ed372d71c56211749556f6bdc
3
+ size 466520
html_information.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html = """
2
+ <style>
3
+ body{
4
+ font-family: sans-serif;
5
+ }
6
+ h1{
7
+ font-weight: 100;
8
+ }
9
+ .container{
10
+ width: 100%;
11
+ display:block;
12
+ overflow:hidden;
13
+ }
14
+ .carousel{
15
+ display:block;
16
+ width: 100%;
17
+ height: 320px;
18
+ background: white;
19
+ overflow-x: scroll;
20
+ padding: 10px;
21
+ margin: 0;
22
+ white-space: nowrap;
23
+ border-top: 2px solid rgba(0, 0, 0, 0.1);
24
+ border-bottom: 2px solid rgba(0, 0, 0, 0.1);
25
+ }
26
+ .item {
27
+ display: inline-block;
28
+ overflow: hidden;
29
+ width: 250px;
30
+ margin: 0 10px;
31
+ height: calc(100%);
32
+ background: rgba(0, 0, 0, 0.05) no-repeat center center;
33
+ background-size: cover;
34
+ position:relative;
35
+ border-radius: 20px;
36
+ box-shadow: 0 0 10px #dfdfdf;
37
+ }
38
+ .item p {
39
+ padding: 20px;
40
+ word-break: break-all;
41
+ white-space: break-spaces;
42
+ overflow: hidden;
43
+ display: -webkit-box;
44
+ -webkit-line-clamp: 4;
45
+ -webkit-box-orient: vertical;
46
+ margin: 0;
47
+ align: center;
48
+ }
49
+ #image-container{
50
+ width: 100%;
51
+ height: 60%;
52
+ text-align:center;
53
+ font-size: 9em;
54
+ color: white;
55
+ overflow: hidden;
56
+ }
57
+ #image-container img{
58
+ width: 100%;
59
+ height: 100%;
60
+ object-fit: contain;
61
+ }
62
+ </style>
63
+ </head>
64
+ <body>
65
+ <div class="container">
66
+ <div class="carousel">
67
+ """
img.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:32ae45f7794ea5203e9f5b82b600736bd9526d2d918b419ff6fc56e6e50d17d9
3
+ size 12405751
text.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:771f1148e7678c8279849df250795a60b272df80a86eba90f64ca5af45b56b17
3
+ size 12405751