Mjlehtim commited on
Commit
d3c4089
1 Parent(s): b7cb49b

Log in functions included

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -106,6 +106,53 @@ css = """
106
  """
107
 
108
  st.write(css, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  st.sidebar.image('StratXcel.png', width=150)
110
  #-------------
111
  llm=ChatGroq(groq_api_key=groq_api_key,
 
106
  """
107
 
108
  st.write(css, unsafe_allow_html=True)
109
+
110
+ #--------------
111
+ def load_credentials(filepath):
112
+ with open(filepath, 'r') as file:
113
+ return json.load(file)
114
+
115
+ # Load credentials from 'credentials.json'
116
+ credentials = load_credentials('credentials.json')
117
+
118
+ # Initialize session state if not already done
119
+ if 'logged_in' not in st.session_state:
120
+ st.session_state.logged_in = False
121
+ st.session_state.username = ''
122
+
123
+ # Function to handle login
124
+ def login(username, password):
125
+ if username in credentials and credentials[username] == password:
126
+ st.session_state.logged_in = True
127
+ st.session_state.username = username
128
+ st.rerun() # Rerun to reflect login state
129
+ else:
130
+ st.session_state.logged_in = False
131
+ st.session_state.username = ''
132
+ st.error("Invalid username or password.")
133
+
134
+ # Function to handle logout
135
+ def logout():
136
+ st.session_state.logged_in = False
137
+ st.session_state.username = ''
138
+ st.rerun() # Rerun to reflect logout state
139
+
140
+ # If not logged in, show login form
141
+ if not st.session_state.logged_in:
142
+ st.sidebar.write("Login")
143
+ username = st.sidebar.text_input('Username')
144
+ password = st.sidebar.text_input('Password', type='password')
145
+ if st.sidebar.button('Login'):
146
+ login(username, password)
147
+ # Stop the script here if the user is not logged in
148
+ st.stop()
149
+
150
+ # If logged in, show logout button and main content
151
+ if st.session_state.logged_in:
152
+ st.sidebar.write(f"Welcome, {st.session_state.username}!")
153
+ if st.sidebar.button('Logout'):
154
+ logout()
155
+
156
  st.sidebar.image('StratXcel.png', width=150)
157
  #-------------
158
  llm=ChatGroq(groq_api_key=groq_api_key,