Spaces:
Sleeping
Sleeping
| 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") | |