Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,165 +1,3 @@
|
|
| 1 |
-
# from datetime import datetime
|
| 2 |
-
|
| 3 |
-
# import streamlit as st
|
| 4 |
-
# import streamlit_authenticator as stauth
|
| 5 |
-
# import yaml
|
| 6 |
-
# from yaml.loader import SafeLoader
|
| 7 |
-
|
| 8 |
-
# from utils.frontend.helper import *
|
| 9 |
-
|
| 10 |
-
# st.set_page_config(page_title="SAAS Template App", page_icon="๐ง", layout="wide")
|
| 11 |
-
|
| 12 |
-
# with open("config.yaml") as file:
|
| 13 |
-
# config = yaml.load(file, Loader=SafeLoader)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# cookie_config = config.get("cookie", {})
|
| 17 |
-
# authenticator = stauth.Authenticate(
|
| 18 |
-
# config.get("credentials"),
|
| 19 |
-
# cookie_config.get("name"),
|
| 20 |
-
# cookie_config.get("key"),
|
| 21 |
-
# cookie_config.get("expiry_days"),
|
| 22 |
-
# config.get("preauthorized"),
|
| 23 |
-
# )
|
| 24 |
-
|
| 25 |
-
# # authenticator = stauth.Authenticate(
|
| 26 |
-
# # config["credentials"],
|
| 27 |
-
# # config["cookie"]["name"],
|
| 28 |
-
# # config["cookie"]["key"],
|
| 29 |
-
# # config["cookie"]["expiry_days"],
|
| 30 |
-
# # config["preauthorized"],
|
| 31 |
-
# # )
|
| 32 |
-
|
| 33 |
-
# with st.sidebar:
|
| 34 |
-
# if not st.session_state["authentication_status"]:
|
| 35 |
-
# st.markdown(
|
| 36 |
-
# """
|
| 37 |
-
# # Welcome to **Name of the App**
|
| 38 |
-
|
| 39 |
-
# """
|
| 40 |
-
# )
|
| 41 |
-
|
| 42 |
-
# # Login
|
| 43 |
-
# with st.expander("Login ๐", expanded=True):
|
| 44 |
-
# authenticator.login("Login", "main")
|
| 45 |
-
|
| 46 |
-
# if st.session_state["authentication_status"]:
|
| 47 |
-
# authenticator.logout("Logout", "main", key="unique_key")
|
| 48 |
-
# st.write(f'Welcome *{st.session_state["name"]}*')
|
| 49 |
-
# st.title(
|
| 50 |
-
# "You logged in! You can choose a session in the bottom of the sidebar and view content."
|
| 51 |
-
# )
|
| 52 |
-
# elif st.session_state["authentication_status"] is False:
|
| 53 |
-
# st.error("Username/password is incorrect")
|
| 54 |
-
# elif st.session_state["authentication_status"] is None:
|
| 55 |
-
# st.warning("Please enter your username and password")
|
| 56 |
-
|
| 57 |
-
# # Reset Password
|
| 58 |
-
# with st.expander("Reset password ๐"):
|
| 59 |
-
# if st.session_state["authentication_status"]:
|
| 60 |
-
# try:
|
| 61 |
-
# if authenticator.reset_password(
|
| 62 |
-
# st.session_state["username"], "Reset password"
|
| 63 |
-
# ):
|
| 64 |
-
# st.success("Password modified successfully")
|
| 65 |
-
# except Exception as e:
|
| 66 |
-
# st.error(e)
|
| 67 |
-
|
| 68 |
-
# # Forgot Password
|
| 69 |
-
# with st.expander("Forgot password ๐"):
|
| 70 |
-
# try:
|
| 71 |
-
# (
|
| 72 |
-
# username_of_forgotten_password,
|
| 73 |
-
# email_of_forgotten_password,
|
| 74 |
-
# new_random_password,
|
| 75 |
-
# ) = authenticator.forgot_password("Forgot password")
|
| 76 |
-
# if username_of_forgotten_password:
|
| 77 |
-
# st.success("New password to be sent securely")
|
| 78 |
-
# # Random password should be transferred to user securely
|
| 79 |
-
# else:
|
| 80 |
-
# st.error("Username not found")
|
| 81 |
-
# except Exception as e:
|
| 82 |
-
# st.error(e)
|
| 83 |
-
|
| 84 |
-
# # Update User
|
| 85 |
-
# with st.expander("Update user ๐"):
|
| 86 |
-
# if st.session_state["authentication_status"]:
|
| 87 |
-
# try:
|
| 88 |
-
# if authenticator.update_user_details(
|
| 89 |
-
# st.session_state["username"], "Update user details"
|
| 90 |
-
# ):
|
| 91 |
-
# st.success("Entries updated successfully")
|
| 92 |
-
# except Exception as e:
|
| 93 |
-
# st.error(e)
|
| 94 |
-
|
| 95 |
-
# # Register User
|
| 96 |
-
# with st.expander("Register user ๐", expanded=False):
|
| 97 |
-
# try:
|
| 98 |
-
# # payment_key = st.text_input("Enter Payment Key:")
|
| 99 |
-
# if authenticator.register_user("Register user", preauthorization=False):
|
| 100 |
-
# # if register_user(payment_key):
|
| 101 |
-
# st.success("User registered successfully")
|
| 102 |
-
# except Exception as e:
|
| 103 |
-
# st.error(e)
|
| 104 |
-
|
| 105 |
-
# with open("config.yaml", "w") as file:
|
| 106 |
-
# yaml.dump(config, file, default_flow_style=False)
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
# # Main
|
| 110 |
-
# if st.session_state["authentication_status"]:
|
| 111 |
-
# st.markdown(
|
| 112 |
-
# """
|
| 113 |
-
# # Content of the App
|
| 114 |
-
|
| 115 |
-
# Welcome!
|
| 116 |
-
# """
|
| 117 |
-
# )
|
| 118 |
-
|
| 119 |
-
# # Add Main Content Here
|
| 120 |
-
# # TODO
|
| 121 |
-
# main_chatbot_page()
|
| 122 |
-
|
| 123 |
-
# # Log out
|
| 124 |
-
# with st.sidebar:
|
| 125 |
-
# with st.expander("Login ๐", expanded=True):
|
| 126 |
-
# authenticator.login("Login", "main")
|
| 127 |
-
|
| 128 |
-
# if st.session_state["authentication_status"]:
|
| 129 |
-
# authenticator.logout("Logout", "main", key="unique_key_to_log_out")
|
| 130 |
-
# st.write(f'Welcome *{st.session_state["name"]}*')
|
| 131 |
-
# st.title(
|
| 132 |
-
# "You logged in! You can choose a session in the bottom of the sidebar and view content."
|
| 133 |
-
# )
|
| 134 |
-
# st.markdown(
|
| 135 |
-
# "### ๐ฑ๏ธPress "
|
| 136 |
-
# R" on your keyboardโจ๏ธ to rerun the app for faster loading ๐."
|
| 137 |
-
# )
|
| 138 |
-
# elif st.session_state["authentication_status"] is False:
|
| 139 |
-
# st.error("Username/password is incorrect")
|
| 140 |
-
# elif st.session_state["authentication_status"] is None:
|
| 141 |
-
# st.warning("Please enter your username and password")
|
| 142 |
-
# else:
|
| 143 |
-
# st.warning("Please login to view content.")
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
# with st.sidebar:
|
| 147 |
-
# # Credit: Time
|
| 148 |
-
# def current_year():
|
| 149 |
-
# now = datetime.now()
|
| 150 |
-
# return now.year
|
| 151 |
-
|
| 152 |
-
# # Credit:
|
| 153 |
-
# current_year = current_year() # This will print the current year
|
| 154 |
-
# st.markdown(
|
| 155 |
-
# f"""
|
| 156 |
-
# <h6 style='text-align: left;'>Copyright ยฉ 2010-{current_year} Present Yiqiao Yin</h6>
|
| 157 |
-
# """,
|
| 158 |
-
# unsafe_allow_html=True,
|
| 159 |
-
# )
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
from datetime import datetime
|
| 164 |
|
| 165 |
import streamlit as st
|
|
@@ -174,6 +12,7 @@ st.set_page_config(page_title="SAAS Template App", page_icon="๐ง", layout="wid
|
|
| 174 |
with open("config.yaml") as file:
|
| 175 |
config = yaml.load(file, Loader=SafeLoader)
|
| 176 |
|
|
|
|
| 177 |
cookie_config = config.get("cookie", {})
|
| 178 |
authenticator = stauth.Authenticate(
|
| 179 |
config.get("credentials"),
|
|
@@ -183,82 +22,92 @@ authenticator = stauth.Authenticate(
|
|
| 183 |
config.get("preauthorized"),
|
| 184 |
)
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
with st.sidebar:
|
| 187 |
-
if not st.session_state
|
| 188 |
st.markdown(
|
| 189 |
"""
|
| 190 |
# Welcome to **Name of the App**
|
| 191 |
-
"""
|
| 192 |
-
)
|
| 193 |
|
| 194 |
-
|
| 195 |
-
with st.expander("Login ๐", expanded=True):
|
| 196 |
-
authenticator.login("Login", "main")
|
| 197 |
-
|
| 198 |
-
if st.session_state.get("authentication_status"):
|
| 199 |
-
authenticator.logout("Logout", "main", key="logout_main")
|
| 200 |
-
st.write(f'Welcome *{st.session_state["name"]}*')
|
| 201 |
-
st.title(
|
| 202 |
-
"You logged in! You can choose a session in the bottom of the sidebar and view content."
|
| 203 |
)
|
| 204 |
-
elif st.session_state.get("authentication_status") is False:
|
| 205 |
-
st.error("Username/password is incorrect")
|
| 206 |
-
elif st.session_state.get("authentication_status") is None:
|
| 207 |
-
st.warning("Please enter your username and password")
|
| 208 |
-
|
| 209 |
-
# Reset Password
|
| 210 |
-
with st.expander("Reset password ๐"):
|
| 211 |
-
if st.session_state.get("authentication_status"):
|
| 212 |
-
try:
|
| 213 |
-
if authenticator.reset_password(
|
| 214 |
-
st.session_state["username"], "Reset password"
|
| 215 |
-
):
|
| 216 |
-
st.success("Password modified successfully")
|
| 217 |
-
except Exception as e:
|
| 218 |
-
st.error(e)
|
| 219 |
|
| 220 |
-
#
|
| 221 |
-
with st.expander("
|
| 222 |
-
|
| 223 |
-
(
|
| 224 |
-
username_of_forgotten_password,
|
| 225 |
-
email_of_forgotten_password,
|
| 226 |
-
new_random_password,
|
| 227 |
-
) = authenticator.forgot_password("Forgot password")
|
| 228 |
-
if username_of_forgotten_password:
|
| 229 |
-
st.success("New password to be sent securely")
|
| 230 |
-
# Random password should be transferred to user securely
|
| 231 |
-
else:
|
| 232 |
-
st.error("Username not found")
|
| 233 |
-
except Exception as e:
|
| 234 |
-
st.error(e)
|
| 235 |
-
|
| 236 |
-
# Update User
|
| 237 |
-
with st.expander("Update user ๐"):
|
| 238 |
-
if st.session_state.get("authentication_status"):
|
| 239 |
-
try:
|
| 240 |
-
if authenticator.update_user_details(
|
| 241 |
-
st.session_state["username"], "Update user details"
|
| 242 |
-
):
|
| 243 |
-
st.success("Entries updated successfully")
|
| 244 |
-
except Exception as e:
|
| 245 |
-
st.error(e)
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
st.
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
-
with open("config.yaml", "w") as file:
|
| 258 |
-
yaml.dump(config, file, default_flow_style=False)
|
| 259 |
|
| 260 |
# Main
|
| 261 |
-
if st.session_state
|
| 262 |
st.markdown(
|
| 263 |
"""
|
| 264 |
# Content of the App
|
|
@@ -276,21 +125,26 @@ if st.session_state.get("authentication_status"):
|
|
| 276 |
with st.expander("Login ๐", expanded=True):
|
| 277 |
authenticator.login("Login", "main")
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
|
| 295 |
with st.sidebar:
|
| 296 |
# Credit: Time
|
|
@@ -302,7 +156,7 @@ with st.sidebar:
|
|
| 302 |
current_year = current_year() # This will print the current year
|
| 303 |
st.markdown(
|
| 304 |
f"""
|
| 305 |
-
|
| 306 |
""",
|
| 307 |
unsafe_allow_html=True,
|
| 308 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from datetime import datetime
|
| 2 |
|
| 3 |
import streamlit as st
|
|
|
|
| 12 |
with open("config.yaml") as file:
|
| 13 |
config = yaml.load(file, Loader=SafeLoader)
|
| 14 |
|
| 15 |
+
|
| 16 |
cookie_config = config.get("cookie", {})
|
| 17 |
authenticator = stauth.Authenticate(
|
| 18 |
config.get("credentials"),
|
|
|
|
| 22 |
config.get("preauthorized"),
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# authenticator = stauth.Authenticate(
|
| 26 |
+
# config["credentials"],
|
| 27 |
+
# config["cookie"]["name"],
|
| 28 |
+
# config["cookie"]["key"],
|
| 29 |
+
# config["cookie"]["expiry_days"],
|
| 30 |
+
# config["preauthorized"],
|
| 31 |
+
# )
|
| 32 |
+
|
| 33 |
with st.sidebar:
|
| 34 |
+
if not st.session_state["authentication_status"]:
|
| 35 |
st.markdown(
|
| 36 |
"""
|
| 37 |
# Welcome to **Name of the App**
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
# Login
|
| 43 |
+
with st.expander("Login ๐", expanded=True):
|
| 44 |
+
authenticator.login("Login", "main")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
if st.session_state["authentication_status"]:
|
| 47 |
+
authenticator.logout("Logout", "main", key="logout_main")
|
| 48 |
+
st.write(f'Welcome *{st.session_state["name"]}*')
|
| 49 |
+
st.title(
|
| 50 |
+
"You logged in! You can choose a session in the bottom of the sidebar and view content."
|
| 51 |
+
)
|
| 52 |
+
elif st.session_state["authentication_status"] is False:
|
| 53 |
+
st.error("Username/password is incorrect")
|
| 54 |
+
elif st.session_state["authentication_status"] is None:
|
| 55 |
+
st.warning("Please enter your username and password")
|
| 56 |
+
|
| 57 |
+
# Reset Password
|
| 58 |
+
with st.expander("Reset password ๐"):
|
| 59 |
+
if st.session_state["authentication_status"]:
|
| 60 |
+
try:
|
| 61 |
+
if authenticator.reset_password(
|
| 62 |
+
st.session_state["username"], "Reset password"
|
| 63 |
+
):
|
| 64 |
+
st.success("Password modified successfully")
|
| 65 |
+
except Exception as e:
|
| 66 |
+
st.error(e)
|
| 67 |
+
|
| 68 |
+
# Forgot Password
|
| 69 |
+
with st.expander("Forgot password ๐"):
|
| 70 |
+
try:
|
| 71 |
+
(
|
| 72 |
+
username_of_forgotten_password,
|
| 73 |
+
email_of_forgotten_password,
|
| 74 |
+
new_random_password,
|
| 75 |
+
) = authenticator.forgot_password("Forgot password")
|
| 76 |
+
if username_of_forgotten_password:
|
| 77 |
+
st.success("New password to be sent securely")
|
| 78 |
+
# Random password should be transferred to user securely
|
| 79 |
+
else:
|
| 80 |
+
st.error("Username not found")
|
| 81 |
+
except Exception as e:
|
| 82 |
+
st.error(e)
|
| 83 |
+
|
| 84 |
+
# Update User
|
| 85 |
+
with st.expander("Update user ๐"):
|
| 86 |
+
if st.session_state["authentication_status"]:
|
| 87 |
+
try:
|
| 88 |
+
if authenticator.update_user_details(
|
| 89 |
+
st.session_state["username"], "Update user details"
|
| 90 |
+
):
|
| 91 |
+
st.success("Entries updated successfully")
|
| 92 |
+
except Exception as e:
|
| 93 |
+
st.error(e)
|
| 94 |
+
|
| 95 |
+
# Register User
|
| 96 |
+
with st.expander("Register user ๐", expanded=False):
|
| 97 |
+
try:
|
| 98 |
+
# payment_key = st.text_input("Enter Payment Key:")
|
| 99 |
+
if authenticator.register_user("Register user", preauthorization=False):
|
| 100 |
+
# if register_user(payment_key):
|
| 101 |
+
st.success("User registered successfully")
|
| 102 |
+
except Exception as e:
|
| 103 |
+
st.error(e)
|
| 104 |
+
|
| 105 |
+
with open("config.yaml", "w") as file:
|
| 106 |
+
yaml.dump(config, file, default_flow_style=False)
|
| 107 |
|
|
|
|
|
|
|
| 108 |
|
| 109 |
# Main
|
| 110 |
+
if st.session_state["authentication_status"]:
|
| 111 |
st.markdown(
|
| 112 |
"""
|
| 113 |
# Content of the App
|
|
|
|
| 125 |
with st.expander("Login ๐", expanded=True):
|
| 126 |
authenticator.login("Login", "main")
|
| 127 |
|
| 128 |
+
if st.session_state["authentication_status"]:
|
| 129 |
+
try:
|
| 130 |
+
authenticator.logout("Logout", "main", key="logout_sidebar")
|
| 131 |
+
except KeyError as e:
|
| 132 |
+
st.warning(f"Logout failed: {str(e)}")
|
| 133 |
+
st.write(f'Welcome *{st.session_state["name"]}*')
|
| 134 |
+
st.title(
|
| 135 |
+
"You logged in! You can choose a session in the bottom of the sidebar and view content."
|
| 136 |
+
)
|
| 137 |
+
st.markdown(
|
| 138 |
+
"### ๐ฑ๏ธPress "
|
| 139 |
+
R" on your keyboardโจ๏ธ to rerun the app for faster loading ๐."
|
| 140 |
+
)
|
| 141 |
+
elif st.session_state["authentication_status"] is False:
|
| 142 |
+
st.error("Username/password is incorrect")
|
| 143 |
+
elif st.session_state["authentication_status"] is None:
|
| 144 |
+
st.warning("Please enter your username and password")
|
| 145 |
+
else:
|
| 146 |
+
st.warning("Please login to view content.")
|
| 147 |
+
|
| 148 |
|
| 149 |
with st.sidebar:
|
| 150 |
# Credit: Time
|
|
|
|
| 156 |
current_year = current_year() # This will print the current year
|
| 157 |
st.markdown(
|
| 158 |
f"""
|
| 159 |
+
<h6 style='text-align: left;'>Copyright ยฉ 2010-{current_year} Present Yiqiao Yin</h6>
|
| 160 |
""",
|
| 161 |
unsafe_allow_html=True,
|
| 162 |
+
)
|