Spaces:
Sleeping
Sleeping
import streamlit as st | |
import streamlit_authenticator as stauth | |
# Define user authentication | |
users = { | |
"credentials": { | |
"usernames": { | |
"user1": {"name": "User One", "password": "password1"}, | |
"user2": {"name": "User Two", "password": "password2"}, | |
} | |
}, | |
"cookie": { | |
"expiry_days": 30, | |
"key": "my_secret_key", | |
"name": "streamlit_auth", | |
}, | |
} | |
# Initialize the authenticator | |
authenticator = stauth.Authenticate( | |
credentials=users["credentials"], | |
cookie_name=users["cookie"]["name"], | |
key=users["cookie"]["key"], | |
cookie_expiry_days=users["cookie"]["expiry_days"], | |
) | |
# Login/Logout flow | |
name, authentication_status, username = authenticator.login("Login", location="main") | |
if authentication_status: | |
st.success(f"Welcome, {name}!") | |
user_input = st.text_input("Type a message here:") | |
if user_input: | |
st.write(f"Response: hi") | |
authenticator.logout("Logout", "sidebar") | |
elif authentication_status == False: | |
st.error("Username/password is incorrect.") | |
elif authentication_status == None: | |
st.warning("Please enter your username and password.") | |