update: Implement user authentication with credential loading and session management
Browse files
app.py
CHANGED
@@ -7,6 +7,20 @@ from datasets import Dataset, load_dataset
|
|
7 |
from huggingface_hub import login
|
8 |
import os
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def load_data(database_file):
|
12 |
df = pd.read_parquet(database_file)
|
@@ -55,6 +69,29 @@ def save_reactions_to_dataset(user_type, query, results):
|
|
55 |
def main():
|
56 |
st.title("Semantic Text Retrieval Evaluation Interface")
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# Initialize session state variables
|
59 |
if "search_performed" not in st.session_state:
|
60 |
st.session_state.search_performed = False
|
|
|
7 |
from huggingface_hub import login
|
8 |
import os
|
9 |
|
10 |
+
# Load credentials from environment variables or a secure source
|
11 |
+
def load_credentials():
|
12 |
+
# Example: Load credentials from environment variables
|
13 |
+
credentials = {}
|
14 |
+
for i in range(3): # Assuming you have 40 credentials
|
15 |
+
username = os.environ.get(f"LOGIN_{i}")
|
16 |
+
password = os.environ.get(f"PASSWORD_{i}")
|
17 |
+
if username and password:
|
18 |
+
credentials[username] = password
|
19 |
+
return credentials
|
20 |
+
|
21 |
+
# Authentication function
|
22 |
+
def authenticate(username, password, credentials):
|
23 |
+
return credentials.get(username) == password
|
24 |
|
25 |
def load_data(database_file):
|
26 |
df = pd.read_parquet(database_file)
|
|
|
69 |
def main():
|
70 |
st.title("Semantic Text Retrieval Evaluation Interface")
|
71 |
|
72 |
+
# Load credentials
|
73 |
+
credentials = load_credentials()
|
74 |
+
|
75 |
+
# Check if user is authenticated
|
76 |
+
if 'authenticated' not in st.session_state:
|
77 |
+
st.session_state.authenticated = False
|
78 |
+
|
79 |
+
if not st.session_state.authenticated:
|
80 |
+
st.sidebar.title("Login")
|
81 |
+
username = st.sidebar.text_input("Username")
|
82 |
+
password = st.sidebar.text_input("Password", type="password")
|
83 |
+
|
84 |
+
if st.sidebar.button("Login"):
|
85 |
+
if authenticate(username, password, credentials):
|
86 |
+
st.session_state.authenticated = True
|
87 |
+
st.sidebar.success("Logged in successfully!")
|
88 |
+
else:
|
89 |
+
st.sidebar.error("Invalid username or password")
|
90 |
+
|
91 |
+
if not st.session_state.authenticated:
|
92 |
+
st.warning("Please login to access the application.")
|
93 |
+
return
|
94 |
+
|
95 |
# Initialize session state variables
|
96 |
if "search_performed" not in st.session_state:
|
97 |
st.session_state.search_performed = False
|