sachithcheruvaturfynd commited on
Commit
d6041d7
·
verified ·
1 Parent(s): dd39632

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -5
app.py CHANGED
@@ -29,6 +29,46 @@ dataset_choice = st.selectbox(
29
  ["Sephora Order Complete Dataset", "Reliance Digital Order Complete Dataset"]
30
  )
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  if dataset_choice == "Sephora Order Complete Dataset":
33
  list_of_products_to_display = {}
34
  for itemid in (list(all_products_with_names_sephora.keys())): #for items in the total list of items in all transactions
@@ -43,10 +83,9 @@ if dataset_choice == "Sephora Order Complete Dataset":
43
  query_id = name_to_id[selected_product_name]
44
  url = "https://www.sephora.com/"
45
  st.write("Created using the clickstream order-completed and catalog data from [Sephora.com](%s)" % url)
 
46
  query_url = images_sephora[int(query_id)]
47
  st.image(query_url, width=500)
48
- st.write("Product Cost:", str(round(item_costs_sephora_data[query_id], 2)))
49
-
50
 
51
 
52
  if dataset_choice == "Reliance Digital Order Complete Dataset":
@@ -64,7 +103,7 @@ if dataset_choice == "Reliance Digital Order Complete Dataset":
64
  url = "https://www.reliancedigital.in/"
65
  st.write("Created using the clickstream order-completed data from [reliancedigital.com](%s)" % url)
66
  st.write("An item is only recommended if it costs less than the chosen item.")
67
- st.write("Product Cost:", str(round(item_costs_digital_data[query_id], 2)))
68
 
69
 
70
 
@@ -151,7 +190,7 @@ with tab2:
151
  count_info = f"Co-purchased {copurchase_count[index]}/{transactions_with_query_item} times"
152
  item_counts_info = f"item-count {item_counts[index]} "
153
  confidence_info = f"Confidence: {round(confidence_list[index], 3)}"
154
- item_cost_info_sephora = f"Product cost: {round(item_costs_sephora[index],2)}"
155
 
156
 
157
  # Use <br> to display each line separately
@@ -174,6 +213,7 @@ with tab2:
174
  item_ids = [item for item in corrected_fp_growth_results[query_id]]
175
  item_counts = [corrected_fp_growth_results[query_id][item] for item in corrected_fp_growth_results[query_id]]
176
  item_costs = [item_costs_digital_data.get(item, "cost missing") for item in corrected_fp_growth_results[query_id]]
 
177
 
178
 
179
  confidence_list = []
@@ -202,10 +242,11 @@ with tab2:
202
  count_info = f"Co-purchased {copurchase_count[index]}/{transactions_with_querry_item} times"
203
  item_counts_info = f"item-count {item_counts[index]} "
204
  confidence_info = f"Confidence: {round(confidence_list[index], 3)}"
205
- item_cost_info = f"Product cost: {round(item_costs[index],3)}"
206
 
207
  # Use <br> to display each line separately
208
  mid_section += f"""<div class="item">
 
209
  <p style="font-size: 16px; font-weight: bold; white-space: normal; word-wrap: break-word;">{str(product_names[index])}</p>
210
  <p>{count_info}<br>{confidence_info}<br>{item_cost_info}</p>
211
  </div>"""
@@ -231,6 +272,7 @@ with tab3: # historical transactions tab
231
  st.markdown(f"**Transaction {i+1}:** Placed on {transaction['event_timestamp']} by {transaction['user_id']}", unsafe_allow_html=True)
232
 
233
  transaction_names = [all_products_with_names_sephora.get(str(item), "Unknown Product") for item in transaction["transaction"]]
 
234
 
235
  item_images = []
236
  for item in corrected_fp_growth_results_sephora.get(query_id, []):
@@ -290,6 +332,7 @@ with tab3: # historical transactions tab
290
  transaction_section = ""
291
  for index, image_url in enumerate(transaction_names):
292
  transaction_section += f"""<div class="item">
 
293
  <p style="font-size: 16px; font-weight: bold; white-space: normal; word-wrap: break-word;">{str(transaction_names[index])}</p>
294
  </div>"""
295
 
 
29
  ["Sephora Order Complete Dataset", "Reliance Digital Order Complete Dataset"]
30
  )
31
 
32
+ # HTML and CSS for a hover tooltip
33
+ tooltip_html = """
34
+ <style>
35
+ .tooltip {
36
+ position: relative;
37
+ display: inline-block;
38
+ border-bottom: 1px dotted black;
39
+ }
40
+
41
+ .tooltip .tooltiptext {
42
+ visibility: hidden;
43
+ width: 120px;
44
+ background-color: black;
45
+ color: #fff;
46
+ text-align: center;
47
+ border-radius: 5px;
48
+ padding: 5px;
49
+ position: absolute;
50
+ z-index: 1;
51
+ bottom: 150%;
52
+ left: 50%;
53
+ margin-left: -60px;
54
+ opacity: 0;
55
+ transition: opacity 0.3s;
56
+ }
57
+
58
+ .tooltip:hover .tooltiptext {
59
+ visibility: visible;
60
+ opacity: 1;
61
+ }
62
+ </style>
63
+
64
+ <div class="tooltip">Hover over me
65
+ <span class="sachith">Tooltip text</span>
66
+ </div>
67
+ """
68
+
69
+ # Inject the custom HTML
70
+ st.markdown(tooltip_html, unsafe_allow_html=True)
71
+
72
  if dataset_choice == "Sephora Order Complete Dataset":
73
  list_of_products_to_display = {}
74
  for itemid in (list(all_products_with_names_sephora.keys())): #for items in the total list of items in all transactions
 
83
  query_id = name_to_id[selected_product_name]
84
  url = "https://www.sephora.com/"
85
  st.write("Created using the clickstream order-completed and catalog data from [Sephora.com](%s)" % url)
86
+ st.write("Cost of chosen item:", str(round(item_costs_sephora_data[query_id], 2)))
87
  query_url = images_sephora[int(query_id)]
88
  st.image(query_url, width=500)
 
 
89
 
90
 
91
  if dataset_choice == "Reliance Digital Order Complete Dataset":
 
103
  url = "https://www.reliancedigital.in/"
104
  st.write("Created using the clickstream order-completed data from [reliancedigital.com](%s)" % url)
105
  st.write("An item is only recommended if it costs less than the chosen item.")
106
+ st.write("Cost of chosen item:", str(round(item_costs_digital_data[query_id], 2)))
107
 
108
 
109
 
 
190
  count_info = f"Co-purchased {copurchase_count[index]}/{transactions_with_query_item} times"
191
  item_counts_info = f"item-count {item_counts[index]} "
192
  confidence_info = f"Confidence: {round(confidence_list[index], 3)}"
193
+ item_cost_info_sephora = f"Cost: {round(item_costs_sephora[index],2)}"
194
 
195
 
196
  # Use <br> to display each line separately
 
213
  item_ids = [item for item in corrected_fp_growth_results[query_id]]
214
  item_counts = [corrected_fp_growth_results[query_id][item] for item in corrected_fp_growth_results[query_id]]
215
  item_costs = [item_costs_digital_data.get(item, "cost missing") for item in corrected_fp_growth_results[query_id]]
216
+ no_image = "https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg"
217
 
218
 
219
  confidence_list = []
 
242
  count_info = f"Co-purchased {copurchase_count[index]}/{transactions_with_querry_item} times"
243
  item_counts_info = f"item-count {item_counts[index]} "
244
  confidence_info = f"Confidence: {round(confidence_list[index], 3)}"
245
+ item_cost_info = f"Cost: {round(item_costs[index],3)}"
246
 
247
  # Use <br> to display each line separately
248
  mid_section += f"""<div class="item">
249
+ <div id="image-container"><img src='{no_image}' /></div>
250
  <p style="font-size: 16px; font-weight: bold; white-space: normal; word-wrap: break-word;">{str(product_names[index])}</p>
251
  <p>{count_info}<br>{confidence_info}<br>{item_cost_info}</p>
252
  </div>"""
 
272
  st.markdown(f"**Transaction {i+1}:** Placed on {transaction['event_timestamp']} by {transaction['user_id']}", unsafe_allow_html=True)
273
 
274
  transaction_names = [all_products_with_names_sephora.get(str(item), "Unknown Product") for item in transaction["transaction"]]
275
+ no_image = "https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg"
276
 
277
  item_images = []
278
  for item in corrected_fp_growth_results_sephora.get(query_id, []):
 
332
  transaction_section = ""
333
  for index, image_url in enumerate(transaction_names):
334
  transaction_section += f"""<div class="item">
335
+ <div id="image-container"><img src='{no_image}' /></div>
336
  <p style="font-size: 16px; font-weight: bold; white-space: normal; word-wrap: break-word;">{str(transaction_names[index])}</p>
337
  </div>"""
338