pradeep4321 commited on
Commit
1db10f3
Β·
verified Β·
1 Parent(s): 73ed590

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +61 -2
src/app.py CHANGED
@@ -16,12 +16,46 @@ import nltk
16
  nltk.download('wordnet', quiet=True)
17
  from nltk.corpus import wordnet
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # ==============================
20
  # PAGE CONFIG
21
  # ==============================
22
  st.set_page_config(page_title="Multi Search Engine", layout="wide")
23
  st.title("πŸ” Advanced Multi-Search Product Engine")
24
 
 
 
 
 
25
  # ==============================
26
  # LOAD MODEL
27
  # ==============================
@@ -31,6 +65,12 @@ def load_model():
31
 
32
  model = load_model()
33
 
 
 
 
 
 
 
34
  # ==============================
35
  # SEARCH INFO
36
  # ==============================
@@ -57,7 +97,7 @@ search_info = {
57
  # ==============================
58
  try:
59
  df = pd.read_csv("src/products_10k.csv")
60
- st.success("βœ… Data loaded successfully(10K Products)")
61
  except Exception as e:
62
  st.error(f"❌ Error loading file: {e}")
63
  st.stop()
@@ -252,9 +292,28 @@ if st.button("Search"):
252
  results = func_map[search_type](query)
253
  results = sorted(results, key=lambda x: x[1], reverse=True)[:top_k]
254
 
 
 
 
 
 
 
 
 
255
  indices = [i for i, _ in results]
256
  result_df = df.iloc[indices].copy()
257
  result_df["Score"] = [round(score, 4) for _, score in results]
258
 
259
  st.subheader("πŸ”Ž Results")
260
- st.dataframe(result_df)
 
 
 
 
 
 
 
 
 
 
 
 
16
  nltk.download('wordnet', quiet=True)
17
  from nltk.corpus import wordnet
18
 
19
+ # ==============================
20
+ # AUTHENTICATION
21
+ # ==============================
22
+ def login():
23
+ st.title("πŸ” Login Required")
24
+
25
+ username = st.text_input("Username")
26
+ password = st.text_input("Password", type="password")
27
+
28
+ if st.button("Login"):
29
+ if (
30
+ username == st.secrets["USERNAME"] and
31
+ password == st.secrets["PASSWORD"]
32
+ ):
33
+ st.session_state["authenticated"] = True
34
+ st.session_state["user"] = username
35
+ st.session_state["login_time"] = pd.Timestamp.now()
36
+ st.success("βœ… Login successful")
37
+ st.rerun()
38
+ else:
39
+ st.error("❌ Invalid credentials")
40
+
41
+ # Session control
42
+ if "authenticated" not in st.session_state:
43
+ st.session_state["authenticated"] = False
44
+
45
+ if not st.session_state["authenticated"]:
46
+ login()
47
+ st.stop()
48
+
49
  # ==============================
50
  # PAGE CONFIG
51
  # ==============================
52
  st.set_page_config(page_title="Multi Search Engine", layout="wide")
53
  st.title("πŸ” Advanced Multi-Search Product Engine")
54
 
55
+ # Sidebar user info
56
+ st.sidebar.success(f"πŸ‘€ User: {st.session_state['user']}")
57
+ st.sidebar.info(f"πŸ•’ Login: {st.session_state['login_time']}")
58
+
59
  # ==============================
60
  # LOAD MODEL
61
  # ==============================
 
65
 
66
  model = load_model()
67
 
68
+ # ==============================
69
+ # INIT ACTIVITY LOG
70
+ # ==============================
71
+ if "activity_log" not in st.session_state:
72
+ st.session_state["activity_log"] = []
73
+
74
  # ==============================
75
  # SEARCH INFO
76
  # ==============================
 
97
  # ==============================
98
  try:
99
  df = pd.read_csv("src/products_10k.csv")
100
+ st.success("βœ… Data loaded successfully (10K Products)")
101
  except Exception as e:
102
  st.error(f"❌ Error loading file: {e}")
103
  st.stop()
 
292
  results = func_map[search_type](query)
293
  results = sorted(results, key=lambda x: x[1], reverse=True)[:top_k]
294
 
295
+ # βœ… LOG USER ACTIVITY
296
+ st.session_state["activity_log"].append({
297
+ "User": st.session_state["user"],
298
+ "Query": query,
299
+ "Search Type": search_type,
300
+ "Time": str(pd.Timestamp.now())
301
+ })
302
+
303
  indices = [i for i, _ in results]
304
  result_df = df.iloc[indices].copy()
305
  result_df["Score"] = [round(score, 4) for _, score in results]
306
 
307
  st.subheader("πŸ”Ž Results")
308
+ st.dataframe(result_df)
309
+
310
+ # ==============================
311
+ # SHOW ACTIVITY LOG
312
+ # ==============================
313
+ st.sidebar.subheader("πŸ“Š Activity Log")
314
+
315
+ if st.session_state["activity_log"]:
316
+ log_df = pd.DataFrame(st.session_state["activity_log"])
317
+ st.sidebar.dataframe(log_df.tail(10))
318
+ else:
319
+ st.sidebar.write("No activity yet")