Update pages/ai_buddy.py
Browse files- pages/ai_buddy.py +423 -367
pages/ai_buddy.py
CHANGED
@@ -1,368 +1,424 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import random
|
3 |
-
from langchain.chat_models import ChatOpenAI
|
4 |
-
from langchain.schema import HumanMessage, SystemMessage
|
5 |
-
import os
|
6 |
-
from dotenv import load_dotenv
|
7 |
-
import pandas as pd
|
8 |
-
from datetime import datetime
|
9 |
-
import plotly.express as px
|
10 |
-
import json
|
11 |
-
import
|
12 |
-
from
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
"
|
33 |
-
"
|
34 |
-
"
|
35 |
-
"
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"
|
39 |
-
"
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
st.
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
st.
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
st.markdown("
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
st.session_state.
|
278 |
-
|
279 |
-
st.
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
st.
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
st.sidebar.markdown("
|
339 |
-
st.sidebar.
|
340 |
-
|
341 |
-
|
342 |
-
st.sidebar.markdown("
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
"
|
350 |
-
"
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
main()
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
from langchain.chat_models import ChatOpenAI
|
4 |
+
from langchain.schema import HumanMessage, SystemMessage
|
5 |
+
import os
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
import pandas as pd
|
8 |
+
from datetime import datetime
|
9 |
+
import plotly.express as px
|
10 |
+
import json
|
11 |
+
import time
|
12 |
+
from playsound import playsound
|
13 |
+
|
14 |
+
# Load environment variables
|
15 |
+
load_dotenv()
|
16 |
+
|
17 |
+
AI71_BASE_URL = "https://api.ai71.ai/v1/"
|
18 |
+
AI71_API_KEY = "api71-api-92fc2ef9-9f3c-47e5-a019-18e257b04af2"
|
19 |
+
|
20 |
+
# Initialize the Falcon model
|
21 |
+
chat = ChatOpenAI(
|
22 |
+
model="tiiuae/falcon-180B-chat",
|
23 |
+
api_key=AI71_API_KEY,
|
24 |
+
base_url=AI71_BASE_URL,
|
25 |
+
streaming=True,
|
26 |
+
)
|
27 |
+
|
28 |
+
# Expanded Therapy techniques
|
29 |
+
THERAPY_TECHNIQUES = {
|
30 |
+
"CBT": "Use Cognitive Behavioral Therapy techniques to help the user identify and change negative thought patterns.",
|
31 |
+
"Mindfulness": "Guide the user through mindfulness exercises to promote present-moment awareness and reduce stress.",
|
32 |
+
"Solution-Focused": "Focus on the user's strengths and resources to help them find solutions to their problems.",
|
33 |
+
"Emotion-Focused": "Help the user identify, experience, and regulate their emotions more effectively.",
|
34 |
+
"Psychodynamic": "Explore the user's past experiences and unconscious patterns to gain insight into current issues.",
|
35 |
+
"ACT": "Use Acceptance and Commitment Therapy to help the user accept their thoughts and feelings while committing to positive changes.",
|
36 |
+
"DBT": "Apply Dialectical Behavior Therapy techniques to help the user manage intense emotions and improve relationships.",
|
37 |
+
"Gestalt": "Use Gestalt therapy techniques to focus on the present moment and increase self-awareness.",
|
38 |
+
"Existential": "Explore existential themes such as meaning, freedom, and responsibility to help the user find purpose.",
|
39 |
+
"Narrative": "Use storytelling and narrative techniques to help the user reframe their life experiences and create new meaning.",
|
40 |
+
}
|
41 |
+
|
42 |
+
def get_ai_response(user_input, buddy_config, therapy_technique=None):
|
43 |
+
system_message = f"You are {buddy_config['name']}, an AI companion with the following personality: {buddy_config['personality']}. "
|
44 |
+
system_message += f"Additional details about you: {buddy_config['details']}. "
|
45 |
+
|
46 |
+
if therapy_technique:
|
47 |
+
system_message += f"In this conversation, {THERAPY_TECHNIQUES[therapy_technique]}"
|
48 |
+
|
49 |
+
messages = [
|
50 |
+
SystemMessage(content=system_message),
|
51 |
+
HumanMessage(content=user_input)
|
52 |
+
]
|
53 |
+
response = chat.invoke(messages).content
|
54 |
+
return response
|
55 |
+
|
56 |
+
def show_meditation_timer():
|
57 |
+
st.subheader("π§ββοΈ Enhanced Meditation Timer")
|
58 |
+
col1, col2 = st.columns(2)
|
59 |
+
|
60 |
+
with col1:
|
61 |
+
duration = st.slider("Select duration (minutes)", 1, 60, 5)
|
62 |
+
background_options = ["Forest", "Beach", "Rain", "White Noise"]
|
63 |
+
background_sound = st.selectbox("Background Sound", background_options)
|
64 |
+
|
65 |
+
with col2:
|
66 |
+
interval_options = ["None", "Every 5 minutes", "Every 10 minutes"]
|
67 |
+
interval_reminder = st.selectbox("Interval Reminders", interval_options)
|
68 |
+
end_sound_options = ["Gentle Chime", "Tibetan Singing Bowl", "Ocean Wave"]
|
69 |
+
end_sound = st.selectbox("End of Session Sound", end_sound_options)
|
70 |
+
|
71 |
+
if st.button("Start Meditation", key="start_meditation"):
|
72 |
+
progress_bar = st.progress(0)
|
73 |
+
status_text = st.empty()
|
74 |
+
|
75 |
+
# Play background sound
|
76 |
+
background_sound_file = f"sounds/{background_sound.lower().replace(' ', '_')}.mp3"
|
77 |
+
playsound(background_sound_file, block=False)
|
78 |
+
|
79 |
+
for i in range(duration * 60):
|
80 |
+
progress_bar.progress((i + 1) / (duration * 60))
|
81 |
+
mins, secs = divmod(duration * 60 - i - 1, 60)
|
82 |
+
status_text.text(f"Time remaining: {mins:02d}:{secs:02d}")
|
83 |
+
|
84 |
+
if interval_reminder != "None":
|
85 |
+
interval = 5 if interval_reminder == "Every 5 minutes" else 10
|
86 |
+
if i > 0 and i % (interval * 60) == 0:
|
87 |
+
st.toast(f"{interval} minutes passed", icon="β°")
|
88 |
+
|
89 |
+
time.sleep(1)
|
90 |
+
|
91 |
+
# Stop background sound (you may need to implement this depending on how playsound works)
|
92 |
+
# stop_sound(background_sound_file)
|
93 |
+
|
94 |
+
st.success("Meditation complete!")
|
95 |
+
st.balloons()
|
96 |
+
|
97 |
+
# Play end of session sound
|
98 |
+
end_sound_file = f"sounds/{end_sound.lower().replace(' ', '_')}.mp3"
|
99 |
+
playsound(end_sound_file)
|
100 |
+
|
101 |
+
if 'achievements' not in st.session_state:
|
102 |
+
st.session_state.achievements = set()
|
103 |
+
st.session_state.achievements.add("Zen Master")
|
104 |
+
st.success("Achievement Unlocked: Zen Master π§ββοΈ")
|
105 |
+
|
106 |
+
def show_personalized_recommendations():
|
107 |
+
st.subheader("π― Personalized Recommendations")
|
108 |
+
|
109 |
+
recommendation_categories = [
|
110 |
+
"Mental Health",
|
111 |
+
"Physical Health",
|
112 |
+
"Personal Development",
|
113 |
+
"Relationships",
|
114 |
+
"Career",
|
115 |
+
"Hobbies",
|
116 |
+
]
|
117 |
+
|
118 |
+
selected_category = st.selectbox("Choose a category", recommendation_categories)
|
119 |
+
|
120 |
+
recommendations = {
|
121 |
+
"Mental Health": [
|
122 |
+
"Practice daily gratitude journaling",
|
123 |
+
"Try a guided meditation for stress relief",
|
124 |
+
"Explore cognitive behavioral therapy techniques",
|
125 |
+
"Start a mood tracking journal",
|
126 |
+
"Learn about mindfulness practices",
|
127 |
+
],
|
128 |
+
"Physical Health": [
|
129 |
+
"Start a 30-day yoga challenge",
|
130 |
+
"Try intermittent fasting",
|
131 |
+
"Begin a couch to 5K running program",
|
132 |
+
"Experiment with new healthy recipes",
|
133 |
+
"Create a sleep hygiene routine",
|
134 |
+
],
|
135 |
+
"Personal Development": [
|
136 |
+
"Start learning a new language",
|
137 |
+
"Read personal development books",
|
138 |
+
"Take an online course in a subject you're interested in",
|
139 |
+
"Practice public speaking",
|
140 |
+
"Start a daily writing habit",
|
141 |
+
],
|
142 |
+
"Relationships": [
|
143 |
+
"Practice active listening techniques",
|
144 |
+
"Plan regular date nights or friend meetups",
|
145 |
+
"Learn about love languages",
|
146 |
+
"Practice expressing gratitude to loved ones",
|
147 |
+
"Join a local community or interest group",
|
148 |
+
],
|
149 |
+
"Career": [
|
150 |
+
"Update your resume and LinkedIn profile",
|
151 |
+
"Network with professionals in your industry",
|
152 |
+
"Set SMART career goals",
|
153 |
+
"Learn a new skill relevant to your field",
|
154 |
+
"Start a side project or freelance work",
|
155 |
+
],
|
156 |
+
"Hobbies": [
|
157 |
+
"Start a garden or learn about plant care",
|
158 |
+
"Try a new art form like painting or sculpting",
|
159 |
+
"Learn to play a musical instrument",
|
160 |
+
"Start a DIY home improvement project",
|
161 |
+
"Explore photography or videography",
|
162 |
+
],
|
163 |
+
}
|
164 |
+
|
165 |
+
st.write("Here are some personalized recommendations for you:")
|
166 |
+
for recommendation in recommendations[selected_category]:
|
167 |
+
st.markdown(f"- {recommendation}")
|
168 |
+
|
169 |
+
if st.button("Get More Recommendations"):
|
170 |
+
st.write("More tailored recommendations:")
|
171 |
+
additional_recs = random.sample(recommendations[selected_category], 3)
|
172 |
+
for rec in additional_recs:
|
173 |
+
st.markdown(f"- {rec}")
|
174 |
+
|
175 |
+
def main():
|
176 |
+
st.set_page_config(page_title="S.H.E.R.L.O.C.K. AI Buddy", page_icon="π΅οΈ", layout="wide")
|
177 |
+
|
178 |
+
# Custom CSS for improved styling
|
179 |
+
st.markdown("""
|
180 |
+
<style>
|
181 |
+
.stApp {
|
182 |
+
background-color: #f0f2f6;
|
183 |
+
}
|
184 |
+
.stButton>button {
|
185 |
+
background-color: #4CAF50;
|
186 |
+
color: white;
|
187 |
+
font-weight: bold;
|
188 |
+
}
|
189 |
+
.stTextInput>div>div>input {
|
190 |
+
background-color: #ffffff;
|
191 |
+
}
|
192 |
+
</style>
|
193 |
+
""", unsafe_allow_html=True)
|
194 |
+
|
195 |
+
st.title("π΅οΈ S.H.E.R.L.O.C.K. AI Buddy")
|
196 |
+
st.markdown("Your personalized AI companion for conversation, therapy, and personal growth.")
|
197 |
+
|
198 |
+
# Initialize session state
|
199 |
+
if 'buddy_name' not in st.session_state:
|
200 |
+
st.session_state.buddy_name = "Sherlock"
|
201 |
+
if 'buddy_personality' not in st.session_state:
|
202 |
+
st.session_state.buddy_personality = "Friendly, empathetic, and insightful"
|
203 |
+
if 'buddy_details' not in st.session_state:
|
204 |
+
st.session_state.buddy_details = "Knowledgeable about various therapy techniques and always ready to listen"
|
205 |
+
if 'messages' not in st.session_state:
|
206 |
+
st.session_state.messages = []
|
207 |
+
|
208 |
+
# Sidebar for AI Buddy configuration and additional features
|
209 |
+
with st.sidebar:
|
210 |
+
st.header("π€ Configure Your AI Buddy")
|
211 |
+
st.session_state.buddy_name = st.text_input("Name your AI Buddy", value=st.session_state.buddy_name)
|
212 |
+
st.session_state.buddy_personality = st.text_area("Describe your buddy's personality", value=st.session_state.buddy_personality)
|
213 |
+
st.session_state.buddy_details = st.text_area("Additional details about your buddy", value=st.session_state.buddy_details)
|
214 |
+
|
215 |
+
st.header("π§ Therapy Session")
|
216 |
+
therapy_mode = st.checkbox("Enable Therapy Mode")
|
217 |
+
if therapy_mode:
|
218 |
+
therapy_technique = st.selectbox("Select Therapy Technique", list(THERAPY_TECHNIQUES.keys()))
|
219 |
+
else:
|
220 |
+
therapy_technique = None
|
221 |
+
|
222 |
+
st.markdown("---")
|
223 |
+
|
224 |
+
st.subheader("π Todo List")
|
225 |
+
if 'todos' not in st.session_state:
|
226 |
+
st.session_state.todos = []
|
227 |
+
|
228 |
+
new_todo = st.text_input("Add a new todo:")
|
229 |
+
if st.button("Add Todo", key="add_todo"):
|
230 |
+
if new_todo:
|
231 |
+
st.session_state.todos.append({"task": new_todo, "completed": False})
|
232 |
+
st.success("Todo added successfully!")
|
233 |
+
else:
|
234 |
+
st.warning("Please enter a todo item.")
|
235 |
+
|
236 |
+
for i, todo in enumerate(st.session_state.todos):
|
237 |
+
col1, col2, col3 = st.columns([0.05, 0.8, 0.15])
|
238 |
+
with col1:
|
239 |
+
todo['completed'] = st.checkbox("", todo['completed'], key=f"todo_{i}")
|
240 |
+
with col2:
|
241 |
+
st.write(todo['task'], key=f"todo_text_{i}")
|
242 |
+
with col3:
|
243 |
+
if st.button("ποΈ", key=f"delete_{i}", help="Delete todo"):
|
244 |
+
st.session_state.todos.pop(i)
|
245 |
+
st.experimental_rerun()
|
246 |
+
|
247 |
+
st.subheader("β±οΈ Pomodoro Timer")
|
248 |
+
pomodoro_duration = st.slider("Pomodoro Duration (minutes)", 1, 60, 25)
|
249 |
+
if st.button("Start Pomodoro"):
|
250 |
+
progress_bar = st.progress(0)
|
251 |
+
for i in range(pomodoro_duration * 60):
|
252 |
+
time.sleep(1)
|
253 |
+
progress_bar.progress((i + 1) / (pomodoro_duration * 60))
|
254 |
+
st.success("Pomodoro completed!")
|
255 |
+
if 'achievements' not in st.session_state:
|
256 |
+
st.session_state.achievements = set()
|
257 |
+
st.session_state.achievements.add("Consistent Learner")
|
258 |
+
|
259 |
+
st.markdown("---")
|
260 |
+
st.markdown("Powered by Falcon-180B and Streamlit")
|
261 |
+
|
262 |
+
st.markdown("---")
|
263 |
+
st.header("π Daily Journal")
|
264 |
+
journal_entry = st.text_area("Write your thoughts for today")
|
265 |
+
if st.button("Save Journal Entry"):
|
266 |
+
if 'journal_entries' not in st.session_state:
|
267 |
+
st.session_state.journal_entries = []
|
268 |
+
st.session_state.journal_entries.append({
|
269 |
+
'date': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
270 |
+
'entry': journal_entry
|
271 |
+
})
|
272 |
+
st.success("Journal entry saved!")
|
273 |
+
st.toast("Journal entry saved successfully!", icon="β
")
|
274 |
+
|
275 |
+
if 'journal_entries' in st.session_state and st.session_state.journal_entries:
|
276 |
+
st.subheader("Previous Entries")
|
277 |
+
for entry in st.session_state.journal_entries[-5:]: # Show last 5 entries
|
278 |
+
st.text(entry['date'])
|
279 |
+
st.write(entry['entry'])
|
280 |
+
st.markdown("---")
|
281 |
+
|
282 |
+
# Main content area
|
283 |
+
tab1, tab2 = st.tabs(["Chat", "Tools"])
|
284 |
+
|
285 |
+
with tab1:
|
286 |
+
# Chat interface
|
287 |
+
st.header("π¨οΈ Chat with Your AI Buddy")
|
288 |
+
|
289 |
+
# Display chat history
|
290 |
+
chat_container = st.container()
|
291 |
+
with chat_container:
|
292 |
+
for message in st.session_state.messages:
|
293 |
+
with st.chat_message(message["role"]):
|
294 |
+
st.markdown(message["content"])
|
295 |
+
|
296 |
+
# Clear chat history button
|
297 |
+
if st.button("Clear Chat History"):
|
298 |
+
st.session_state.messages = []
|
299 |
+
st.experimental_rerun()
|
300 |
+
|
301 |
+
# User input
|
302 |
+
if prompt := st.chat_input("What's on your mind?"):
|
303 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
304 |
+
with st.chat_message("user"):
|
305 |
+
st.markdown(prompt)
|
306 |
+
|
307 |
+
buddy_config = {
|
308 |
+
"name": st.session_state.buddy_name,
|
309 |
+
"personality": st.session_state.buddy_personality,
|
310 |
+
"details": st.session_state.buddy_details
|
311 |
+
}
|
312 |
+
|
313 |
+
with st.chat_message("assistant"):
|
314 |
+
message_placeholder = st.empty()
|
315 |
+
full_response = ""
|
316 |
+
for chunk in chat.stream(get_ai_response(prompt, buddy_config, therapy_technique)):
|
317 |
+
full_response += chunk.content
|
318 |
+
message_placeholder.markdown(full_response + "β")
|
319 |
+
message_placeholder.markdown(full_response)
|
320 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
321 |
+
|
322 |
+
with tab2:
|
323 |
+
tool_choice = st.selectbox("Select a tool", ["Meditation Timer", "Recommendations"])
|
324 |
+
if tool_choice == "Meditation Timer":
|
325 |
+
show_meditation_timer()
|
326 |
+
elif tool_choice == "Recommendations":
|
327 |
+
show_personalized_recommendations()
|
328 |
+
|
329 |
+
# Mood tracker
|
330 |
+
st.sidebar.markdown("---")
|
331 |
+
st.sidebar.header("π Mood Tracker")
|
332 |
+
mood = st.sidebar.slider("How are you feeling today?", 1, 10, 5)
|
333 |
+
if st.sidebar.button("Log Mood"):
|
334 |
+
st.sidebar.success(f"Mood logged: {mood}/10")
|
335 |
+
st.balloons()
|
336 |
+
|
337 |
+
# Resources and Emergency Contact
|
338 |
+
st.sidebar.markdown("---")
|
339 |
+
st.sidebar.header("π Resources")
|
340 |
+
st.sidebar.info("If you're in crisis, please reach out for help:")
|
341 |
+
st.sidebar.markdown("- [Mental Health Resources](https://www.mentalhealth.gov/get-help/immediate-help)")
|
342 |
+
st.sidebar.markdown("- Emergency Contact: 911 or your local emergency number")
|
343 |
+
|
344 |
+
# Inspiration Quote
|
345 |
+
st.sidebar.markdown("---")
|
346 |
+
st.sidebar.header("π‘ Daily Inspiration")
|
347 |
+
if st.sidebar.button("Get Inspirational Quote"):
|
348 |
+
quotes = [
|
349 |
+
"The only way to do great work is to love what you do. - Steve Jobs",
|
350 |
+
"Believe you can and you're halfway there. - Theodore Roosevelt",
|
351 |
+
"The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt",
|
352 |
+
"Strive not to be a success, but rather to be of value. - Albert Einstein",
|
353 |
+
"The only limit to our realization of tomorrow will be our doubts of today. - Franklin D. Roosevelt",
|
354 |
+
"Do not wait to strike till the iron is hot; but make it hot by striking. - William Butler Yeats",
|
355 |
+
"What lies behind us and what lies before us are tiny matters compared to what lies within us. - Ralph Waldo Emerson",
|
356 |
+
"Success is not final, failure is not fatal: It is the courage to continue that counts. - Winston Churchill",
|
357 |
+
"Life is what happens when you're busy making other plans. - John Lennon",
|
358 |
+
"You miss 100% of the shots you don't take. - Wayne Gretzky",
|
359 |
+
"The best way to predict the future is to create it. - Peter Drucker",
|
360 |
+
"It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change. - Charles Darwin",
|
361 |
+
"Whether you think you can or you think you can't, you're right. - Henry Ford",
|
362 |
+
"The only place where success comes before work is in the dictionary. - Vidal Sassoon",
|
363 |
+
"Do what you can, with what you have, where you are. - Theodore Roosevelt",
|
364 |
+
"The purpose of our lives is to be happy. - Dalai Lama",
|
365 |
+
"Success usually comes to those who are too busy to be looking for it. - Henry David Thoreau",
|
366 |
+
"Your time is limited, so don't waste it living someone else's life. - Steve Jobs",
|
367 |
+
"Don't be afraid to give up the good to go for the great. - John D. Rockefeller",
|
368 |
+
"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
|
369 |
+
"Success is not the key to happiness. Happiness is the key to success. - Albert Schweitzer",
|
370 |
+
"It does not matter how slowly you go, as long as you do not stop. - Confucius",
|
371 |
+
"If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success. - James Cameron",
|
372 |
+
"Don't watch the clock; do what it does. Keep going. - Sam Levenson",
|
373 |
+
"Hardships often prepare ordinary people for an extraordinary destiny. - C.S. Lewis",
|
374 |
+
"Don't count the days, make the days count. - Muhammad Ali",
|
375 |
+
"The best revenge is massive success. - Frank Sinatra",
|
376 |
+
"The only impossible journey is the one you never begin. - Tony Robbins",
|
377 |
+
"Act as if what you do makes a difference. It does. - William James",
|
378 |
+
"You are never too old to set another goal or to dream a new dream. - C.S. Lewis",
|
379 |
+
"If you're going through hell, keep going. - Winston Churchill",
|
380 |
+
"Dream big and dare to fail. - Norman Vaughan",
|
381 |
+
"In the middle of every difficulty lies opportunity. - Albert Einstein",
|
382 |
+
"What we achieve inwardly will change outer reality. - Plutarch",
|
383 |
+
"I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison",
|
384 |
+
"It always seems impossible until it's done. - Nelson Mandela",
|
385 |
+
"The future depends on what you do today. - Mahatma Gandhi",
|
386 |
+
"Don't wait. The time will never be just right. - Napoleon Hill",
|
387 |
+
"Quality is not an act, it is a habit. - Aristotle",
|
388 |
+
"Your life does not get better by chance, it gets better by change. - Jim Rohn",
|
389 |
+
"The only thing standing between you and your goal is the story you keep telling yourself as to why you can't achieve it. - Jordan Belfort",
|
390 |
+
"Challenges are what make life interesting; overcoming them is what makes life meaningful. - Joshua J. Marine",
|
391 |
+
"Opportunities don't happen, you create them. - Chris Grosser",
|
392 |
+
"I can't change the direction of the wind, but I can adjust my sails to always reach my destination. - Jimmy Dean",
|
393 |
+
"Start where you are. Use what you have. Do what you can. - Arthur Ashe",
|
394 |
+
"The secret of getting ahead is getting started. - Mark Twain",
|
395 |
+
"You donβt have to be great to start, but you have to start to be great. - Zig Ziglar",
|
396 |
+
"Keep your eyes on the stars, and your feet on the ground. - Theodore Roosevelt",
|
397 |
+
"The only way to achieve the impossible is to believe it is possible. - Charles Kingsleigh"
|
398 |
+
]
|
399 |
+
|
400 |
+
random_quote = random.choice(quotes)
|
401 |
+
st.sidebar.success(random_quote)
|
402 |
+
|
403 |
+
# Chat Export
|
404 |
+
st.sidebar.markdown("---")
|
405 |
+
if st.sidebar.button("Export Chat History"):
|
406 |
+
chat_history = "\n".join([f"{msg['role']}: {msg['content']}" for msg in st.session_state.messages])
|
407 |
+
st.sidebar.download_button(
|
408 |
+
label="Download Chat History",
|
409 |
+
data=chat_history,
|
410 |
+
file_name="ai_buddy_chat_history.txt",
|
411 |
+
mime="text/plain"
|
412 |
+
)
|
413 |
+
|
414 |
+
st.sidebar.success("Chat history ready for download!")
|
415 |
+
|
416 |
+
# Display achievements
|
417 |
+
if 'achievements' in st.session_state and st.session_state.achievements:
|
418 |
+
st.sidebar.markdown("---")
|
419 |
+
st.sidebar.header("π Achievements")
|
420 |
+
for achievement in st.session_state.achievements:
|
421 |
+
st.sidebar.success(f"Unlocked: {achievement}")
|
422 |
+
|
423 |
+
if __name__ == "__main__":
|
424 |
main()
|