Update app.py
Browse files
app.py
CHANGED
@@ -22,83 +22,6 @@ import os
|
|
22 |
|
23 |
|
24 |
|
25 |
-
|
26 |
-
# Authentication
|
27 |
-
import streamlit_authenticator as stauth
|
28 |
-
|
29 |
-
import yaml
|
30 |
-
from yaml.loader import SafeLoader
|
31 |
-
|
32 |
-
with open('config.yaml') as file:
|
33 |
-
config = yaml.load(file, Loader=SafeLoader)
|
34 |
-
authenticator = stauth.Authenticate(
|
35 |
-
config['credentials'],
|
36 |
-
config['cookie']['name'],
|
37 |
-
config['cookie']['key'],
|
38 |
-
config['cookie']['expiry_days'],
|
39 |
-
config['preauthorized']
|
40 |
-
)
|
41 |
-
|
42 |
-
name, authentication_status, username = authenticator.login('Login', 'main')
|
43 |
-
|
44 |
-
if authentication_status:
|
45 |
-
authenticator.logout('Logout', 'main', key='unique_key')
|
46 |
-
st.write(f'Welcome *{name}*')
|
47 |
-
st.title('Some content')
|
48 |
-
elif authentication_status is False:
|
49 |
-
st.error('Username/password is incorrect')
|
50 |
-
elif authentication_status is None:
|
51 |
-
st.warning('Please enter your username and password')
|
52 |
-
|
53 |
-
|
54 |
-
if authentication_status:
|
55 |
-
try:
|
56 |
-
if authenticator.reset_password(username, 'Reset password'):
|
57 |
-
st.success('Password modified successfully')
|
58 |
-
except Exception as e:
|
59 |
-
st.error(e)
|
60 |
-
|
61 |
-
try:
|
62 |
-
if authenticator.register_user('Register user', preauthorization=False):
|
63 |
-
st.success('User registered successfully')
|
64 |
-
except Exception as e:
|
65 |
-
st.error(e)
|
66 |
-
|
67 |
-
|
68 |
-
try:
|
69 |
-
username_forgot_pw, email_forgot_password, random_password = authenticator.forgot_password('Forgot password')
|
70 |
-
if username_forgot_pw:
|
71 |
-
st.success('New password sent securely')
|
72 |
-
# Random password to be transferred to the user securely
|
73 |
-
else:
|
74 |
-
st.error('Username not found')
|
75 |
-
except Exception as e:
|
76 |
-
st.error(e)
|
77 |
-
|
78 |
-
|
79 |
-
try:
|
80 |
-
username_forgot_username, email_forgot_username = authenticator.forgot_username('Forgot username')
|
81 |
-
if username_forgot_username:
|
82 |
-
st.success('Username sent securely')
|
83 |
-
# Username to be transferred to the user securely
|
84 |
-
else:
|
85 |
-
st.error('Email not found')
|
86 |
-
except Exception as e:
|
87 |
-
st.error(e)
|
88 |
-
|
89 |
-
|
90 |
-
if authentication_status:
|
91 |
-
try:
|
92 |
-
if authenticator.update_user_details(username, 'Update user details'):
|
93 |
-
st.success('Entries updated successfully')
|
94 |
-
except Exception as e:
|
95 |
-
st.error(e)
|
96 |
-
|
97 |
-
with open('config.yaml', 'w') as file:
|
98 |
-
yaml.dump(config, file, default_flow_style=False)
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
# set this key as an environment variable
|
103 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
|
104 |
|
|
|
22 |
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# set this key as an environment variable
|
26 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
|
27 |
|