artintel235 commited on
Commit
a6c395e
·
verified ·
1 Parent(s): 02dd88b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -29
app.py CHANGED
@@ -1,39 +1,35 @@
1
  import streamlit as st
2
  import streamlit_authenticator as stauth
 
 
3
 
4
- # Define user authentication
5
- users = {
6
- "credentials": {
7
- "usernames": {
8
- "user1": {"name": "User One", "password": "password1"},
9
- "user2": {"name": "User Two", "password": "password2"},
10
- }
11
- },
12
- "cookie": {
13
- "expiry_days": 30,
14
- "key": "my_secret_key",
15
- "name": "streamlit_auth",
16
- },
17
- }
18
-
19
- # Initialize the authenticator
20
  authenticator = stauth.Authenticate(
21
- credentials=users["credentials"],
22
- cookie_name=users["cookie"]["name"],
23
- key=users["cookie"]["key"],
24
- cookie_expiry_days=users["cookie"]["expiry_days"],
 
25
  )
26
 
27
- # Login/Logout flow
28
- name, authentication_status, username = authenticator.login("Login", location="main")
29
 
30
  if authentication_status:
31
- st.success(f"Welcome, {name}!")
32
- user_input = st.text_input("Type a message here:")
33
- if user_input:
34
- st.write(f"Response: hi")
35
- authenticator.logout("Logout", "sidebar")
 
 
 
36
  elif authentication_status == False:
37
- st.error("Username/password is incorrect.")
38
  elif authentication_status == None:
39
- st.warning("Please enter your username and password.")
 
1
  import streamlit as st
2
  import streamlit_authenticator as stauth
3
+ import yaml
4
+ from yaml.loader import SafeLoader
5
 
6
+
7
+ # --- YAML CONFIG FOR CREDENTIALS ---
8
+ with open('./config.yaml') as file:
9
+ config = yaml.load(file, Loader=SafeLoader)
10
+
11
+
12
+ # Authenticator setup
 
 
 
 
 
 
 
 
 
13
  authenticator = stauth.Authenticate(
14
+ config['credentials'],
15
+ config['cookie']['name'],
16
+ config['cookie']['key'],
17
+ config['cookie']['expiry_days'],
18
+ config['preauthorized']
19
  )
20
 
21
+ name, authentication_status, username = authenticator.login('Login', 'main')
 
22
 
23
  if authentication_status:
24
+ st.write(f'Welcome *{name}*')
25
+ authenticator.logout('Logout', 'main')
26
+
27
+ # --- Text Input and Response ---
28
+ user_text = st.text_input("Enter some text:")
29
+ if user_text:
30
+ st.write("Hi!")
31
+
32
  elif authentication_status == False:
33
+ st.error('Username/password is incorrect')
34
  elif authentication_status == None:
35
+ st.warning('Please enter your username and password')