artintel235 commited on
Commit
f2d7821
·
verified ·
1 Parent(s): 4e6aa9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -32
app.py CHANGED
@@ -1,42 +1,30 @@
1
  import streamlit as st
2
- import os
3
 
4
- # Load credentials from Hugging Face Secrets
5
- USERNAME = "tester"
6
- PASSWORD = "tester@123"
7
-
8
- # Initialize session state for login status
9
  if "logged_in" not in st.session_state:
10
  st.session_state.logged_in = False
11
 
12
- # Login form
13
- def login_form():
14
- with st.form("Login"):
15
- username = st.text_input("Username")
16
- password = st.text_input("Password", type="password")
17
- submit_button = st.form_submit_button("Login")
18
-
19
- if submit_button:
20
- if username == USERNAME and password == PASSWORD:
21
- st.session_state.logged_in = True
22
- st.success("Logged in successfully!")
23
- else:
24
- st.error("Invalid username or password")
25
 
26
- # Logout button
27
- def logout():
28
  st.session_state.logged_in = False
29
- st.info("Logged out successfully!")
30
 
31
- # Main app logic
32
- def main_app():
33
- st.title("Welcome to the App!")
34
- st.write("You are logged in. Here is your protected content.")
35
- if st.button("Logout"):
36
- logout()
37
 
38
- # Render the app based on login status
39
  if st.session_state.logged_in:
40
- main_app()
41
- else:
42
- login_form()
 
1
  import streamlit as st
 
2
 
3
+ # Initialize session state
 
 
 
 
4
  if "logged_in" not in st.session_state:
5
  st.session_state.logged_in = False
6
 
7
+ # Callback for login
8
+ def login_callback():
9
+ username = st.session_state.username_input
10
+ password = st.session_state.password_input
11
+ if username == "admin" and password == "password": # Replace with your credentials
12
+ st.session_state.logged_in = True
13
+ else:
14
+ st.error("Invalid username or password")
 
 
 
 
 
15
 
16
+ # Callback for logout
17
+ def logout_callback():
18
  st.session_state.logged_in = False
 
19
 
20
+ # Login form
21
+ if not st.session_state.logged_in:
22
+ st.subheader("Login")
23
+ st.text_input("Username", key="username_input")
24
+ st.text_input("Password", type="password", key="password_input")
25
+ st.button("Login", on_click=login_callback)
26
 
27
+ # Logout button
28
  if st.session_state.logged_in:
29
+ st.subheader("Welcome to the App!")
30
+ st.button("Logout", on_click=logout_callback)