artintel235 commited on
Commit
77d5c10
·
verified ·
1 Parent(s): b75a5c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -3
app.py CHANGED
@@ -1,7 +1,42 @@
1
  import streamlit as st
 
2
 
3
- st.title("Simple Hi App")
 
 
4
 
5
- user_text = st.text_input("Enter some text:")
 
 
6
 
7
- st.write("hi")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import os
3
 
4
+ # Load credentials from Hugging Face Secrets
5
+ USERNAME = os.environ.get("LOGIN_USERNAME")
6
+ PASSWORD = os.environ.get("LOGIN_PASSWORD")
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()