From 8e689f481e7dbe0a68d75dcc0d44206b1f55921b Mon Sep 17 00:00:00 2001 From: Pragnya Khandelwal Date: Thu, 31 Jul 2025 19:29:14 +0530 Subject: [PATCH 1/4] fix: hide sidebar and chat UI on login screen using session_state --- TalkHeal.py | 92 +++++++++++++++++------------------- pink.png => assets/pink.png | Bin components/header.py | 44 ++++------------- components/login_page.py | 72 ++++++++++++++++++++++++++++ users.db | Bin 16384 -> 16384 bytes 5 files changed, 125 insertions(+), 83 deletions(-) rename pink.png => assets/pink.png (100%) create mode 100644 components/login_page.py diff --git a/TalkHeal.py b/TalkHeal.py index ca0d692..98e9c5f 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, 1, 1]) + 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(""" -
-

TalkHeal

-

Your Mental Health Companion πŸ’™

-
- """, unsafe_allow_html=True) - ## Commented out this part of the header because the 'emergency button' functionality is quite similar, hence causing redundancy. ## - - # with st.expander("πŸ“ Find Help Nearby"): - # location_input = st.text_input("Enter your city", key="header_location_search") - # if st.button("πŸ” Search Centers", key="header_search_nearby"): - # if location_input: - # search_url = f"https://www.google.com/maps/search/mental+health+centers+{location_input.replace(' ', '+')}" - # st.markdown(f'πŸ—ΊοΈ View Mental Health Centers Near {location_input}', unsafe_allow_html=True) - # st.success("Opening search results in a new tab...") - # else: - # st.warning("Please enter a city name") + # Only one column for header + column = st.columns(1)[0] + with column: + st.markdown(""" +
+

TalkHeal

+

Your Mental Health Companion πŸ’™

+
+ """, unsafe_allow_html=True) diff --git a/components/login_page.py b/components/login_page.py new file mode 100644 index 0000000..a84e209 --- /dev/null +++ b/components/login_page.py @@ -0,0 +1,72 @@ +import streamlit as st +from auth.auth_utils import register_user, authenticate_user + +def show_login_page(): + st.markdown( + """ + + """, unsafe_allow_html=True + ) + + # Use session state to switch between login and signup + if "show_signup" not in st.session_state: + st.session_state.show_signup = False + + if st.session_state.show_signup: + 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! Welcome.") + st.session_state.authenticated = True + st.session_state.user_email = email + st.session_state.user_name = name + st.session_state.show_signup = False + st.rerun() + else: + st.error(message) + # Only this button for switching to login + if st.button("Already have an account? Login"): + st.session_state.show_signup = False + st.rerun() + else: + 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 + st.session_state.user_email = user["email"] + st.session_state.user_name = user["name"] + st.rerun() + else: + st.warning("Invalid email or password.") + # Only this button for switching to signup + if st.button("Don't have an account? Sign up"): + st.session_state.show_signup = True + st.rerun() \ No newline at end of file diff --git a/users.db b/users.db index 4053dcb89f88865e196f9cd727c98fa1cbddf862..1931765848cb489d53d33d07a6ff7138341f9456 100644 GIT binary patch delta 153 zcmZo@U~Fh$oFL7}Hc`fzm5o8Ktb1e10)8%LzK;z2v-xfLK5iBic+BVH#lprQD%!|u zXk=^x!YW2dDuzZX#sP+Yrs>AT*=fdZX1<30<@yChNqQ9)l@Xcci5XFzxn)j~#$JIT z*`6tW?iGH%mf=+aiIZ*Rk8?5e?`7cM%YTgj(Plw~_57S1%%Y4SgIP8o)3+30WB~xi C)hhA; delta 62 zcmZo@U~Fh$oFL7}JW<+)0)7rAep?3q+5EPf1r-eWC)>&&2Z|hH;6KLy RXtSWfF8 Date: Thu, 31 Jul 2025 19:29:14 +0530 Subject: [PATCH 2/4] fix: hide sidebar and chat UI on login screen using session_state --- TalkHeal.py | 92 +++++++++++++++++------------------- pink.png => assets/pink.png | Bin components/header.py | 44 ++++------------- components/login_page.py | 72 ++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 83 deletions(-) rename pink.png => assets/pink.png (100%) create mode 100644 components/login_page.py diff --git a/TalkHeal.py b/TalkHeal.py index ca0d692..98e9c5f 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, 1, 1]) + 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(""" -
-

TalkHeal

-

Your Mental Health Companion πŸ’™

-
- """, unsafe_allow_html=True) - ## Commented out this part of the header because the 'emergency button' functionality is quite similar, hence causing redundancy. ## - - # with st.expander("πŸ“ Find Help Nearby"): - # location_input = st.text_input("Enter your city", key="header_location_search") - # if st.button("πŸ” Search Centers", key="header_search_nearby"): - # if location_input: - # search_url = f"https://www.google.com/maps/search/mental+health+centers+{location_input.replace(' ', '+')}" - # st.markdown(f'πŸ—ΊοΈ View Mental Health Centers Near {location_input}', unsafe_allow_html=True) - # st.success("Opening search results in a new tab...") - # else: - # st.warning("Please enter a city name") + # Only one column for header + column = st.columns(1)[0] + with column: + st.markdown(""" +
+

TalkHeal

+

Your Mental Health Companion πŸ’™

+
+ """, unsafe_allow_html=True) diff --git a/components/login_page.py b/components/login_page.py new file mode 100644 index 0000000..a84e209 --- /dev/null +++ b/components/login_page.py @@ -0,0 +1,72 @@ +import streamlit as st +from auth.auth_utils import register_user, authenticate_user + +def show_login_page(): + st.markdown( + """ + + """, unsafe_allow_html=True + ) + + # Use session state to switch between login and signup + if "show_signup" not in st.session_state: + st.session_state.show_signup = False + + if st.session_state.show_signup: + 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! Welcome.") + st.session_state.authenticated = True + st.session_state.user_email = email + st.session_state.user_name = name + st.session_state.show_signup = False + st.rerun() + else: + st.error(message) + # Only this button for switching to login + if st.button("Already have an account? Login"): + st.session_state.show_signup = False + st.rerun() + else: + 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 + st.session_state.user_email = user["email"] + st.session_state.user_name = user["name"] + st.rerun() + else: + st.warning("Invalid email or password.") + # Only this button for switching to signup + if st.button("Don't have an account? Sign up"): + st.session_state.show_signup = True + st.rerun() \ No newline at end of file From 9760c95fd69c2d37e8bdd8c86687091d16210cfe Mon Sep 17 00:00:00 2001 From: Pragnya Khandelwal Date: Thu, 31 Jul 2025 21:55:58 +0530 Subject: [PATCH 3/4] update --- TalkHeal.py | 2 +- streamlit.toml | 2 +- users.db | Bin 16384 -> 16384 bytes 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TalkHeal.py b/TalkHeal.py index 98e9c5f..785d7e1 100644 --- a/TalkHeal.py +++ b/TalkHeal.py @@ -22,7 +22,7 @@ # --- TOP RIGHT BUTTONS: THEME TOGGLE & LOGOUT --- if st.session_state.get("authenticated", False): - col_spacer, col_theme, col_logout = st.columns([5, 1, 1]) + 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: diff --git a/streamlit.toml b/streamlit.toml index 0be0cd3..f694a7d 100644 --- a/streamlit.toml +++ b/streamlit.toml @@ -1,2 +1,2 @@ -GEMINI_API_KEY = "AIzaSyDsLJgA58LvgFtnUdVBLFb08GZQV0wXYjQ" +GEMINI_API_KEY = "AIzaSyDFmW-jSijEoql28pUYXTlVJJGxeK-uPyc" diff --git a/users.db b/users.db index 11ed19f17fc26156ad5bbe45e1b921cabaeec243..af1dad59815edd26831379f3c33ec4bca84e7595 100644 GIT binary patch delta 162 zcmZo@U~Fh$oFL7}Hc`fzm5o8Ktb1e10)9SLK6eKG+5EPA*ZC&%xo;K}Fy-^{0?Lbu zHnJKT8JmExicyk^p^=JFR#;-5PgG%EUV(F-w~@13fRnFJsjF*Fv425ES!7UDrCwoV zT3DK+Z&X&kr)g=Zzi~wA=E-t}jC`#8(;4^|@K5Jo%72Xi(Plw~R(?(nW>H3v>8zU< K=*J5%vH}3o1qA>uhAFXRpbrcL4wC>6n-4t>*AA1jAs~Yevy&ci a0R{vQpa2h`vkV}M50Ov{v!E|u5CH^zauS*V From 0283fa52acd3159360cdb7b39384164908100561 Mon Sep 17 00:00:00 2001 From: Pragnya Date: Fri, 1 Aug 2025 23:52:23 +0530 Subject: [PATCH 4/4] Update streamlit.toml --- streamlit.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit.toml b/streamlit.toml index f694a7d..5cdfe5c 100644 --- a/streamlit.toml +++ b/streamlit.toml @@ -1,2 +1,2 @@ -GEMINI_API_KEY = "AIzaSyDFmW-jSijEoql28pUYXTlVJJGxeK-uPyc" +GEMINI_API_KEY = "GEMINI_API_KEY"