pradeep4321 commited on
Commit
1bb2d49
Β·
verified Β·
1 Parent(s): 0a50943

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +26 -14
src/app.py CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
3
  import numpy as np
4
  import os
5
  import re
 
6
  import faiss
7
  import nltk
8
 
@@ -40,23 +41,27 @@ def log_activity(user, action, query, search_type):
40
  pass
41
 
42
  # ==============================
43
- # AUTHENTICATION
44
  # ==============================
45
  def login():
46
- st.title("15 Types of AI-Advanced Multisearch")
47
 
48
- HF_USER = os.environ.get("USERNAME") or st.secrets.get("USERNAME")
49
- HF_PASS = os.environ.get("PASSWORD") or st.secrets.get("PASSWORD")
 
 
 
 
 
50
 
51
  username = st.text_input("Username")
52
  password = st.text_input("Password", type="password")
53
 
54
  if st.button("Login"):
55
- if not HF_USER or not HF_PASS:
56
- st.error("⚠️ Secrets not configured!")
57
- elif username == HF_USER and password == HF_PASS:
58
  st.session_state["authenticated"] = True
59
  st.session_state["user"] = username
 
60
  st.session_state["login_time"] = pd.Timestamp.now()
61
 
62
  log_activity(username, "Login Success", "-", "-")
@@ -79,6 +84,7 @@ st.set_page_config(page_title="Multi Search Engine", layout="wide")
79
  st.title("πŸ” Advanced Multi-Search Product Engine")
80
 
81
  st.sidebar.success(f"πŸ‘€ {st.session_state['user']}")
 
82
 
83
  if st.sidebar.button("πŸšͺ Logout"):
84
  log_activity(st.session_state["user"], "Logout", "-", "-")
@@ -159,7 +165,7 @@ def get_synonyms(word):
159
  return list(synonyms)
160
 
161
  # ==============================
162
- # SEARCH ENGINE
163
  # ==============================
164
  def search_engine(query, mode, top_k):
165
 
@@ -284,10 +290,16 @@ if st.button("Search"):
284
  st.info("No results found")
285
 
286
  # ==============================
287
- # SIDEBAR LOGS
288
  # ==============================
289
- st.sidebar.subheader("πŸ“Š Activity Logs")
290
- if os.path.exists(LOG_FILE):
291
- st.sidebar.dataframe(pd.read_csv(LOG_FILE).tail(10))
292
- else:
293
- st.sidebar.write("No logs yet")
 
 
 
 
 
 
 
3
  import numpy as np
4
  import os
5
  import re
6
+ import json
7
  import faiss
8
  import nltk
9
 
 
41
  pass
42
 
43
  # ==============================
44
+ # AUTHENTICATION (MULTI USER)
45
  # ==============================
46
  def login():
47
+ st.title("πŸ” Multi-User Login")
48
 
49
+ users_json = os.environ.get("USERS") or st.secrets.get("USERS")
50
+
51
+ if not users_json:
52
+ st.error("⚠️ USERS not configured in Hugging Face secrets!")
53
+ return
54
+
55
+ users = json.loads(users_json)
56
 
57
  username = st.text_input("Username")
58
  password = st.text_input("Password", type="password")
59
 
60
  if st.button("Login"):
61
+ if username in users and users[username]["password"] == password:
 
 
62
  st.session_state["authenticated"] = True
63
  st.session_state["user"] = username
64
+ st.session_state["role"] = users[username]["role"]
65
  st.session_state["login_time"] = pd.Timestamp.now()
66
 
67
  log_activity(username, "Login Success", "-", "-")
 
84
  st.title("πŸ” Advanced Multi-Search Product Engine")
85
 
86
  st.sidebar.success(f"πŸ‘€ {st.session_state['user']}")
87
+ st.sidebar.info(f"Role: {st.session_state['role']}")
88
 
89
  if st.sidebar.button("πŸšͺ Logout"):
90
  log_activity(st.session_state["user"], "Logout", "-", "-")
 
165
  return list(synonyms)
166
 
167
  # ==============================
168
+ # SEARCH ENGINE (15 TYPES)
169
  # ==============================
170
  def search_engine(query, mode, top_k):
171
 
 
290
  st.info("No results found")
291
 
292
  # ==============================
293
+ # ADMIN LOG VIEW
294
  # ==============================
295
+ if st.session_state["role"] == "admin":
296
+ st.sidebar.subheader("πŸ“Š Activity Logs")
297
+
298
+ if os.path.exists(LOG_FILE):
299
+ log_df = pd.read_csv(LOG_FILE)
300
+ st.sidebar.dataframe(log_df.tail(10))
301
+
302
+ with open(LOG_FILE, "rb") as f:
303
+ st.sidebar.download_button("⬇ Download Logs", f, file_name="logs.csv")
304
+ else:
305
+ st.sidebar.write("No logs yet")