Spaces:
Sleeping
Sleeping
Credentials added
Browse files- LocalT_ESG_RAG_1.25.py +45 -1
LocalT_ESG_RAG_1.25.py
CHANGED
@@ -104,7 +104,51 @@ css = """
|
|
104 |
"""
|
105 |
|
106 |
st.write(css, unsafe_allow_html=True)
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
#-------------
|
109 |
llm=ChatGroq(groq_api_key=groq_api_key,
|
110 |
model_name="Llama-3.1-70b-Versatile", temperature = 0.0, streaming=True)
|
|
|
104 |
"""
|
105 |
|
106 |
st.write(css, unsafe_allow_html=True)
|
107 |
+
|
108 |
+
def load_credentials(filepath):
|
109 |
+
with open(filepath, 'r') as file:
|
110 |
+
return json.load(file)
|
111 |
+
|
112 |
+
# Load credentials from 'credentials.json'
|
113 |
+
credentials = load_credentials('chroma_db_LT1/credentials.json')
|
114 |
+
|
115 |
+
# Initialize session state if not already done
|
116 |
+
if 'logged_in' not in st.session_state:
|
117 |
+
st.session_state.logged_in = False
|
118 |
+
st.session_state.username = ''
|
119 |
+
|
120 |
+
# Function to handle login
|
121 |
+
def login(username, password):
|
122 |
+
if username in credentials and credentials[username] == password:
|
123 |
+
st.session_state.logged_in = True
|
124 |
+
st.session_state.username = username
|
125 |
+
st.rerun() # Rerun to reflect login state
|
126 |
+
else:
|
127 |
+
st.session_state.logged_in = False
|
128 |
+
st.session_state.username = ''
|
129 |
+
st.error("Invalid username or password.")
|
130 |
+
|
131 |
+
# Function to handle logout
|
132 |
+
def logout():
|
133 |
+
st.session_state.logged_in = False
|
134 |
+
st.session_state.username = ''
|
135 |
+
st.rerun() # Rerun to reflect logout state
|
136 |
+
|
137 |
+
# If not logged in, show login form
|
138 |
+
if not st.session_state.logged_in:
|
139 |
+
st.sidebar.write("Login")
|
140 |
+
username = st.sidebar.text_input('Username')
|
141 |
+
password = st.sidebar.text_input('Password', type='password')
|
142 |
+
if st.sidebar.button('Login'):
|
143 |
+
login(username, password)
|
144 |
+
# Stop the script here if the user is not logged in
|
145 |
+
st.stop()
|
146 |
+
|
147 |
+
# If logged in, show logout button and main content
|
148 |
+
if st.session_state.logged_in:
|
149 |
+
st.sidebar.write(f"Welcome, {st.session_state.username}!")
|
150 |
+
if st.sidebar.button('Logout'):
|
151 |
+
logout()
|
152 |
#-------------
|
153 |
llm=ChatGroq(groq_api_key=groq_api_key,
|
154 |
model_name="Llama-3.1-70b-Versatile", temperature = 0.0, streaming=True)
|