1
- from css .styles import apply_custom_css
2
- apply_custom_css ()
3
-
4
1
import streamlit as st
5
2
import webbrowser
6
3
from datetime import datetime
76
73
}
77
74
}
78
75
76
+
79
77
import streamlit as st
80
78
from core .utils import save_conversations
81
79
from core .config import create_new_conversation
82
- import uuid # Add this at the top of the file if not already imported
83
80
84
81
def render_sidebar ():
85
82
"""Renders the left and right sidebars."""
86
83
87
84
with st .sidebar :
88
85
st .markdown ("### 💬 Conversations" )
89
-
90
- # Initialize session state
91
86
if "show_quick_start_prompts" not in st .session_state :
92
87
st .session_state .show_quick_start_prompts = False
93
88
if "pre_filled_chat_input" not in st .session_state :
94
89
st .session_state .pre_filled_chat_input = ""
95
90
if "send_chat_message" not in st .session_state :
96
91
st .session_state .send_chat_message = False
97
92
98
- # ✅ Fixed unique key — use a constant key only once
99
- # ✅ Unique key fix using session_state
100
-
101
- # Inside render_sidebar()
102
- unique_chat_key = f"sidebar_new_chat_button_{ uuid .uuid4 ()} "
103
-
104
- if st .button ("➕ New Chat" , key = unique_chat_key , use_container_width = True , type = "primary" ):
93
+ if st .button ("➕ New Chat" , key = "new_chat" , use_container_width = True , type = "primary" ):
105
94
create_new_conversation ()
106
95
st .session_state .show_quick_start_prompts = True
107
96
st .rerun ()
108
97
109
-
110
-
111
-
112
98
if st .session_state .show_quick_start_prompts :
113
99
st .markdown ("---" )
114
100
st .markdown ("**Start with a common topic:**" )
@@ -178,12 +164,12 @@ def render_sidebar():
178
164
st .markdown ("**How are you feeling today?**" )
179
165
180
166
mood_options_map = {
181
- "😔 Very Low" : "very_low" ,
182
- "😐 Low" : "low" ,
183
- "😊 Okay" : "okay" ,
184
- "😄 Good" : "good" ,
185
- "🌟 Great" : "great"
186
- }
167
+ "😔 Very Low" : "very_low" ,
168
+ "😐 Low" : "low" ,
169
+ "😊 Okay" : "okay" ,
170
+ "😄 Good" : "good" ,
171
+ "🌟 Great" : "great"
172
+ }
187
173
mood_labels = list (mood_options_map .keys ())
188
174
189
175
selected_mood_label = st .radio (
@@ -195,11 +181,9 @@ def render_sidebar():
195
181
label_visibility = "collapsed"
196
182
)
197
183
198
- # Get mood key from label and save in session
199
184
current_mood_val = mood_options_map [selected_mood_label ]
200
185
st .session_state ["current_mood_val" ] = current_mood_val
201
186
202
- # Prompt based on mood
203
187
journal_prompts = {
204
188
"very_low" : "What's weighing on your mind today?" ,
205
189
"low" : "What are your thoughts right now?" ,
@@ -211,32 +195,35 @@ def render_sidebar():
211
195
st .markdown (f"**📝 { journal_prompts [current_mood_val ]} **" )
212
196
journal_input = st .text_area ("Your thoughts:" , key = "mood_journal_area" , height = 100 )
213
197
214
- # Tips based on mood (using mood *value*, not label)
215
- # Mood-based tips dictionary
198
+ # Initialize states
199
+ if "mood_journal_entry" not in st .session_state :
200
+ st .session_state .mood_journal_entry = ""
201
+ if "mood_tip_display" not in st .session_state :
202
+ st .session_state .mood_tip_display = ""
203
+ if "mood_entry_status" not in st .session_state :
204
+ st .session_state .mood_entry_status = ""
205
+
216
206
tips_for_mood = {
217
207
"very_low" : "Remember, it's okay not to be okay. Consider connecting with a professional." ,
218
208
"low" : "Even small steps help. Try a brief mindful moment or gentle activity." ,
219
209
"okay" : "Keep nurturing your well-being. What's one thing you can do to maintain this?" ,
220
210
"good" : "That's wonderful! Savor this feeling and perhaps share your positivity." ,
221
211
"great" : "Fantastic! How can you carry this energy forward into your day?"
222
- }
223
-
224
- # Get the tip for the selected mood
225
- tip = tips_for_mood .get (current_mood_val , "A general tip for your mood." )
212
+ }.get (current_mood_val , "A general tip for your mood." )
226
213
227
- # Two buttons: Get Tip & Save Entry and Ask TalkHeal
214
+ st . markdown ( "" )
228
215
col1 , col2 = st .columns (2 )
229
216
230
217
with col1 :
231
218
if st .button ("Get Tip & Save Entry" , key = "save_mood_entry" , use_container_width = True ):
232
- st .session_state .mood_tip_display = tip # ✅ show only selected mood tip
219
+ st .session_state .mood_tip_display = tips_for_mood
233
220
st .session_state .mood_entry_status = f"Your mood entry for '{ selected_mood_label } ' has been noted."
234
- st .session_state .mood_journal_entry = journal_input # ✅ store the journal input
221
+ st .session_state .mood_journal_entry = ""
235
222
236
223
with col2 :
237
224
if st .button ("Ask TalkHeal" , key = "ask_peace_pulse_from_mood" , use_container_width = True ):
238
- if journal_input .strip ():
239
- st .session_state .pre_filled_chat_input = journal_input
225
+ if st . session_state . mood_journal_area .strip ():
226
+ st .session_state .pre_filled_chat_input = st . session_state . mood_journal_area
240
227
st .session_state .send_chat_message = True
241
228
st .session_state .mood_journal_entry = ""
242
229
st .session_state .mood_tip_display = ""
@@ -245,11 +232,11 @@ def render_sidebar():
245
232
else :
246
233
st .warning ("Please enter your thoughts before asking TalkHeal." )
247
234
248
- if st .session_state .get ( " mood_tip_display" ) :
235
+ if st .session_state .mood_tip_display :
249
236
st .success (st .session_state .mood_tip_display )
250
237
st .session_state .mood_tip_display = ""
251
238
252
- if st .session_state .get ( " mood_entry_status" ) :
239
+ if st .session_state .mood_entry_status :
253
240
st .info (st .session_state .mood_entry_status )
254
241
st .session_state .mood_entry_status = ""
255
242
@@ -417,4 +404,4 @@ def render_sidebar():
417
404
*"It's absolutely okay not to be okay :)"*
418
405
419
406
📅 Enhanced Version - May 2025
420
- """ )
407
+ """ )
0 commit comments