Skip to content

Commit 83be187

Browse files
Resolved merge conflicts, verified mood selector & chat interface integration1
1 parent 88aa436 commit 83be187

File tree

4 files changed

+449
-41
lines changed

4 files changed

+449
-41
lines changed

components/sidebar.py

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from css.styles import apply_custom_css
2-
apply_custom_css()
3-
41
import streamlit as st
52
import webbrowser
63
from datetime import datetime
@@ -76,39 +73,28 @@
7673
}
7774
}
7875

76+
7977
import streamlit as st
8078
from core.utils import save_conversations
8179
from core.config import create_new_conversation
82-
import uuid # Add this at the top of the file if not already imported
8380

8481
def render_sidebar():
8582
"""Renders the left and right sidebars."""
8683

8784
with st.sidebar:
8885
st.markdown("### 💬 Conversations")
89-
90-
# Initialize session state
9186
if "show_quick_start_prompts" not in st.session_state:
9287
st.session_state.show_quick_start_prompts = False
9388
if "pre_filled_chat_input" not in st.session_state:
9489
st.session_state.pre_filled_chat_input = ""
9590
if "send_chat_message" not in st.session_state:
9691
st.session_state.send_chat_message = False
9792

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"):
10594
create_new_conversation()
10695
st.session_state.show_quick_start_prompts = True
10796
st.rerun()
10897

109-
110-
111-
11298
if st.session_state.show_quick_start_prompts:
11399
st.markdown("---")
114100
st.markdown("**Start with a common topic:**")
@@ -178,12 +164,12 @@ def render_sidebar():
178164
st.markdown("**How are you feeling today?**")
179165

180166
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+
}
187173
mood_labels = list(mood_options_map.keys())
188174

189175
selected_mood_label = st.radio(
@@ -195,11 +181,9 @@ def render_sidebar():
195181
label_visibility="collapsed"
196182
)
197183

198-
# Get mood key from label and save in session
199184
current_mood_val = mood_options_map[selected_mood_label]
200185
st.session_state["current_mood_val"] = current_mood_val
201186

202-
# Prompt based on mood
203187
journal_prompts = {
204188
"very_low": "What's weighing on your mind today?",
205189
"low": "What are your thoughts right now?",
@@ -211,32 +195,35 @@ def render_sidebar():
211195
st.markdown(f"**📝 {journal_prompts[current_mood_val]}**")
212196
journal_input = st.text_area("Your thoughts:", key="mood_journal_area", height=100)
213197

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+
216206
tips_for_mood = {
217207
"very_low": "Remember, it's okay not to be okay. Consider connecting with a professional.",
218208
"low": "Even small steps help. Try a brief mindful moment or gentle activity.",
219209
"okay": "Keep nurturing your well-being. What's one thing you can do to maintain this?",
220210
"good": "That's wonderful! Savor this feeling and perhaps share your positivity.",
221211
"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.")
226213

227-
# Two buttons: Get Tip & Save Entry and Ask TalkHeal
214+
st.markdown("")
228215
col1, col2 = st.columns(2)
229216

230217
with col1:
231218
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
233220
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 = ""
235222

236223
with col2:
237224
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
240227
st.session_state.send_chat_message = True
241228
st.session_state.mood_journal_entry = ""
242229
st.session_state.mood_tip_display = ""
@@ -245,11 +232,11 @@ def render_sidebar():
245232
else:
246233
st.warning("Please enter your thoughts before asking TalkHeal.")
247234

248-
if st.session_state.get("mood_tip_display"):
235+
if st.session_state.mood_tip_display:
249236
st.success(st.session_state.mood_tip_display)
250237
st.session_state.mood_tip_display = ""
251238

252-
if st.session_state.get("mood_entry_status"):
239+
if st.session_state.mood_entry_status:
253240
st.info(st.session_state.mood_entry_status)
254241
st.session_state.mood_entry_status = ""
255242

@@ -417,4 +404,4 @@ def render_sidebar():
417404
*"It's absolutely okay not to be okay :)"*
418405
419406
📅 Enhanced Version - May 2025
420-
""")
407+
""")

0 commit comments

Comments
 (0)