Spaces:
Sleeping
Sleeping
File size: 6,436 Bytes
a9f84bd eb3db7c 7649bad cf0b8f7 814c262 5934e01 a9f84bd cf0b8f7 7649bad cf0b8f7 7649bad cb1a4c5 a9f84bd cb1a4c5 a9f84bd cb1a4c5 a9f84bd 088c41c a9f84bd 088c41c a9f84bd 7649bad a9f84bd 7649bad a9f84bd 7649bad a9f84bd 7649bad cb1a4c5 a9f84bd cb1a4c5 a9f84bd cb1a4c5 a9f84bd 7649bad cb1a4c5 a9f84bd cb1a4c5 a9f84bd 5934e01 5d98d9d 5934e01 088c41c 5da8a10 5934e01 cb1a4c5 088c41c cb1a4c5 5934e01 814c262 5934e01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | from datetime import datetime
import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader
from sections.software_engineer_basics import *
st.set_page_config(page_title="SAAS Template App", page_icon="🧊", layout="wide")
with open("config.yaml") as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config["credentials"],
config["cookie"]["name"],
config["cookie"]["key"],
config["cookie"]["expiry_days"],
config["preauthorized"],
)
# Credit: Time
def current_year():
now = datetime.now()
return now.year
with st.sidebar:
if not st.session_state["authentication_status"]:
st.markdown(
"""
# Welcome to **Name of App** 🎶🤖
Introduction / Instruction Manual ...🚀
### 🖱️Press "R" on your keyboard⌨️ to rerun the app for faster loading 🔄.
### 🔒Sample login info - User: "jsmith" | Password: "abc"
"""
)
# Default video
st.write(
"👋 Guide to Data Science, Machine Learning, and Artificial Intelligence!"
)
with st.expander("Login 🔒", expanded=True):
# authenticator.login("Login", "main")
authenticator.login()
if st.session_state["authentication_status"]:
# authenticator.logout("Logout", "main", key="unique_key_login")
authenticator.logout()
st.write(f'Welcome *{st.session_state["name"]}*')
st.title(
"You logged in! You can choose a session in the bottom of the sidebar and view content."
)
elif st.session_state["authentication_status"] is False:
st.error("Username/password is incorrect")
elif st.session_state["authentication_status"] is None:
st.warning("Please enter your username and password")
with st.expander("Reset password 😕"):
if st.session_state["authentication_status"]:
try:
if authenticator.reset_password(
st.session_state["username"], "Reset password"
):
st.success("Password modified successfully")
except Exception as e:
st.error(e)
with st.expander("Forgot password 😕"):
try:
(
username_of_forgotten_password,
email_of_forgotten_password,
new_random_password,
) = authenticator.forgot_password("Forgot password")
if username_of_forgotten_password:
st.success("New password to be sent securely")
# Random password should be transferred to user securely
else:
st.error("Username not found")
except Exception as e:
st.error(e)
with st.expander("Update user 😋"):
if st.session_state["authentication_status"]:
try:
if authenticator.update_user_details(
st.session_state["username"], "Update user details"
):
st.success("Entries updated successfully")
except Exception as e:
st.error(e)
with st.expander("Register user 😋"):
try:
# payment_key = st.text_input("Enter Payment Key:")
if authenticator.register_user("Register user", preauthorization=False):
# if register_user(payment_key):
st.success("User registered successfully")
except Exception as e:
st.error(e)
with open("config.yaml", "w") as file:
yaml.dump(config, file, default_flow_style=False)
with st.expander("Donation💲"):
stripe_payment_link = "https://buy.stripe.com/cN2bLGa0faMp5u8fYZ"
st.markdown(
f"""
Want to support me? 😄 Done here using this [link]({stripe_payment_link}).
"""
)
# Credit:
current_year = current_year() # This will print the current year
st.markdown(
f"""
<h6 style='text-align: left;'>Copyright © 2010-{current_year} Present Yiqiao Yin</h6>
""",
unsafe_allow_html=True,
)
# Main
if st.session_state["authentication_status"]:
st.markdown(
"""
# Homepage 🎶🤖
Content goes here.
"""
)
page_names_to_funcs = {
"Software Engineer Basics": software_engineer_basics
}
demo_name = st.sidebar.radio(
"Choose a topic below:", key="visibility", options=page_names_to_funcs.keys()
)
page_names_to_funcs[demo_name]()
with st.sidebar:
with st.expander("Login 🔒", expanded=True):
# authenticator.login("Login", "main")
authenticator.login()
st.warning(
"If you are running this app on HuggingFace, you'll need to just refresh your screen to log out."
)
if st.session_state["authentication_status"]:
try:
# authenticator.logout("Logout", "main", key="unique_key")
authenticator.logout()
except KeyError:
pass # ignore it
except Exception as err:
st.error(f"Unexpected exception {err}")
raise Exception(err) # but not this, let's crash the app
st.write(f'Welcome *{st.session_state["name"]}*')
st.title(
"You logged in! You can choose a session in the bottom of the sidebar and view content."
)
st.markdown(
"### 🖱️Press "
R" on your keyboard⌨️ to rerun the app for faster loading 🔄."
)
elif st.session_state["authentication_status"] is False:
st.error("Username/password is incorrect")
elif st.session_state["authentication_status"] is None:
st.warning("Please enter your username and password")
|