DIVYANSHI SINGH commited on
Commit
ee3baf0
·
1 Parent(s): 4fac588

Experience Polish: Upgraded Customer Lookup with searchable selection and random sampling

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -279,11 +279,40 @@ def main():
279
  st.warning("Product affinity data not found. Please run the evaluation pipeline.")
280
 
281
  elif page == "Customer Lookup":
282
- st.subheader("Identify Customer Segment")
283
- customer_id = st.number_input("Enter Customer ID", min_value=int(df.index.min()), max_value=int(df.index.max()), step=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
 
285
  if customer_id in df.index:
286
  cust_data = df.loc[customer_id]
 
 
 
 
 
 
 
287
  st.success(f"Customer {customer_id} is a **{cust_data['Segment']}**")
288
 
289
  c1, c2, c3 = st.columns(3)
 
279
  st.warning("Product affinity data not found. Please run the evaluation pipeline.")
280
 
281
  elif page == "Customer Lookup":
282
+ st.subheader("🔍 Intelligent Customer Lookup")
283
+ st.write("Search for specific customer profiles or explore random segments to understand individual behavior.")
284
+
285
+ # Tool: Random Customer Picker
286
+ if st.button("🎲 Pick a Random Customer"):
287
+ random_id = np.random.choice(df.index)
288
+ st.session_state.customer_search = int(random_id)
289
+
290
+ # Search Box with actual IDs from the dataset
291
+ all_ids = sorted(df.index.unique().tolist())
292
+
293
+ # Initialize session state if not present
294
+ if 'customer_search' not in st.session_state:
295
+ st.session_state.customer_search = all_ids[0]
296
+
297
+ customer_id = st.selectbox(
298
+ "Select or Search Customer ID",
299
+ options=all_ids,
300
+ index=all_ids.index(st.session_state.customer_search) if st.session_state.customer_search in all_ids else 0,
301
+ key="customer_search_box"
302
+ )
303
+
304
+ # Update session state for persistence
305
+ st.session_state.customer_search = customer_id
306
 
307
  if customer_id in df.index:
308
  cust_data = df.loc[customer_id]
309
+
310
+ # Check if filtered out by sidebar
311
+ is_filtered = customer_id not in df_filtered.index
312
+
313
+ if is_filtered:
314
+ st.warning(f"⚠️ Note: Customer {customer_id} is a **{cust_data['Segment']}**, but this segment is currently hidden by your sidebar filters.")
315
+
316
  st.success(f"Customer {customer_id} is a **{cust_data['Segment']}**")
317
 
318
  c1, c2, c3 = st.columns(3)