File size: 6,058 Bytes
fd82ba1 a7e3dbd fd82ba1 4955ee3 a7e3dbd fd82ba1 4955ee3 fd82ba1 d8c79f1 a7e3dbd d8c79f1 a7e3dbd fd82ba1 841dbc3 4955ee3 d06adec 841dbc3 d8c79f1 841dbc3 4955ee3 32019ff 79f2af5 841dbc3 79f2af5 32019ff 79f2af5 32019ff 4955ee3 32019ff 4955ee3 841dbc3 4955ee3 d06adec a7e3dbd fd82ba1 4955ee3 841dbc3 fd82ba1 32019ff b18ae3b 4955ee3 841dbc3 32019ff 4955ee3 32019ff 4955ee3 32019ff 4955ee3 | 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 | from datetime import datetime
import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader
from utils.frontend.helper 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 **Llama3 Full Stack** 🎶🤖
This is a full-stack Software-as-a-Service template for a Llama3 backed chatbot with login authentication using Streamlit. 🚀
### 🖱️Press "R" on your keyboard⌨️ to rerun the app for faster loading 🔄.
### 🔒Sample login info - User: "jsmith" | Password: "abc"
"""
)
# Default video
st.write(
"👋 Welcome to use the sample info to log in!"
)
with st.expander("Login 🔒", expanded=True):
authenticator.login("Login", "main")
if st.session_state["authentication_status"]:
authenticator.logout("Logout", "main", key="unique_key_login")
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(
"""
"""
)
# Add Main Content Here
# TODO
main_chatbot_page()
with st.sidebar:
with st.expander("Login 🔒", expanded=True):
authenticator.login("Login", "main")
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")
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")
|