TalkHeal
-Your Mental Health Companion π
-diff --git a/TalkHeal.py b/TalkHeal.py index ca0d692..785d7e1 100644 --- a/TalkHeal.py +++ b/TalkHeal.py @@ -1,69 +1,49 @@ import streamlit as st -from auth.auth_utils import init_db, register_user, authenticate_user +from auth.auth_utils import init_db +from components.login_page import show_login_page st.set_page_config(page_title="TalkHeal", page_icon="π¬", layout="wide") +# --- DB Initialization --- if "db_initialized" not in st.session_state: init_db() st.session_state["db_initialized"] = True +# --- Auth State Initialization --- if "authenticated" not in st.session_state: st.session_state.authenticated = False if "show_signup" not in st.session_state: st.session_state.show_signup = False -def show_login_ui(): - st.subheader("π Login") - email = st.text_input("Email", key="login_email") - password = st.text_input("Password", type="password", key="login_password") - if st.button("Login"): - success, user = authenticate_user(email, password) - if success: - st.session_state.authenticated = True - # Set user_email and user_name separately for journaling page access - st.session_state.user_email = user["email"] - st.session_state.user_name = user["name"] +# --- LOGIN PAGE --- +if not st.session_state.authenticated: + show_login_page() + st.stop() + +# --- TOP RIGHT BUTTONS: THEME TOGGLE & LOGOUT --- +if st.session_state.get("authenticated", False): + col_spacer, col_theme, col_logout = st.columns([5, 0.5, 0.7]) + with col_spacer: + pass # empty spacer to push buttons right + with col_theme: + is_dark = st.session_state.get('dark_mode', False) + if st.button("π" if is_dark else "βοΈ", key="top_theme_toggle", help="Toggle Light/Dark Mode", use_container_width=True): + st.session_state.dark_mode = not is_dark + st.session_state.theme_changed = True st.rerun() - else: - st.warning("Invalid email or password.") - st.markdown("Don't have an account? [Sign up](#)", unsafe_allow_html=True) - if st.button("Go to Sign Up"): - st.session_state.show_signup = True - st.rerun() - -def show_signup_ui(): - st.subheader("π Sign Up") - name = st.text_input("Name", key="signup_name") - email = st.text_input("Email", key="signup_email") - password = st.text_input("Password", type="password", key="signup_password") - if st.button("Sign Up"): - success, message = register_user(name, email, password) - if success: - st.success("Account created! Please log in.") - st.session_state.show_signup = False + with col_logout: + if st.button("Logout", key="logout_btn", use_container_width=True): + for key in ["authenticated", "user_email", "user_name", "show_signup"]: + if key in st.session_state: + del st.session_state[key] st.rerun() - else: - st.error(message) - st.markdown("Already have an account? [Login](#)", unsafe_allow_html=True) - if st.button("Go to Login"): - st.session_state.show_signup = False - st.rerun() -if not st.session_state.authenticated: - if st.session_state.show_signup: - show_signup_ui() - else: - show_login_ui() -else: +# --- MAIN UI (only after login) --- +header_col1, header_col2, header_col3 = st.columns([6, 1, 1]) +with header_col1: st.title(f"Welcome to TalkHeal, {st.session_state.user_name}! π¬") st.markdown("Navigate to other pages from the sidebar.") - if st.button("Logout"): - for key in ["authenticated", "user_email", "user_name", "show_signup"]: - if key in st.session_state: - del st.session_state[key] - st.rerun() - import google.generativeai as genai from core.utils import save_conversations, load_conversations from core.config import configure_gemini, PAGE_CONFIG @@ -170,4 +150,20 @@ def get_tone_prompt(): } setTimeout(scrollToBottom, 100); -""", unsafe_allow_html=True) \ No newline at end of file +""", unsafe_allow_html=True) + +st.markdown(""" + +""", unsafe_allow_html=True) \ No newline at end of file diff --git a/pink.png b/assets/pink.png similarity index 100% rename from pink.png rename to assets/pink.png diff --git a/components/header.py b/components/header.py index 43bd86f..6a1224c 100644 --- a/components/header.py +++ b/components/header.py @@ -2,38 +2,12 @@ def render_header(): with st.container(): - # Top bar with hamburger menu and theme toggle - col1, col2, col3 = st.columns([0.1, 0.8, 0.1]) - - with col1: - if st.button("β°", key="top_hamburger_menu", help="Toggle Sidebar", use_container_width=True): - if st.session_state.sidebar_state == "expanded": - st.session_state.sidebar_state = "collapsed" - else: - st.session_state.sidebar_state = "expanded" - st.rerun() - - with col3: - is_dark = st.session_state.get('dark_mode', False) - if st.button("π" if is_dark else "βοΈ", key="top_theme_toggle", help="Toggle Light/Dark Mode", use_container_width=True): - st.session_state.dark_mode = not is_dark - st.session_state.theme_changed = True - st.rerun() - - st.markdown(""" -
Your Mental Health Companion π
-Your Mental Health Companion π
+