Spaces:
Sleeping
Sleeping
Update pages/ai_buddy.py
Browse files- pages/ai_buddy.py +659 -660
pages/ai_buddy.py
CHANGED
@@ -1,661 +1,660 @@
|
|
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 tempfile
|
12 |
-
import time
|
13 |
-
import numpy as np
|
14 |
-
import threading
|
15 |
-
from playsound import playsound
|
16 |
-
import pygame
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
chat
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
system_message
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
response
|
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 |
-
pygame.mixer.music.
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
progress
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
mins
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
pygame.mixer.
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
st.
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
st.
|
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 |
-
|
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 |
-
|
249 |
-
|
250 |
-
stereo_audio
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
b64 =
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
text-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
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 |
-
col3
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
beat_freq
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
temp_filename
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
pygame.mixer.music.
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
st.session_state.
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
st.
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
st.session_state.
|
375 |
-
st.session_state.
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
progress
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
mins
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
st.session_state.
|
389 |
-
st.session_state.
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
st.
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
st.
|
441 |
-
st.session_state.
|
442 |
-
st.session_state.
|
443 |
-
|
444 |
-
|
445 |
-
st.
|
446 |
-
therapy_mode
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
st.
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
st.
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
col1
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
st.
|
475 |
-
|
476 |
-
|
477 |
-
st.
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
st.
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
st.markdown("
|
490 |
-
|
491 |
-
|
492 |
-
st.
|
493 |
-
st.
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
'
|
500 |
-
|
501 |
-
|
502 |
-
st.
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
st.
|
507 |
-
|
508 |
-
st.
|
509 |
-
st.
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
chat_container
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
st.
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
st.
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
"
|
541 |
-
"
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
full_response
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
tool_choice
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
st.sidebar.
|
568 |
-
st.sidebar.
|
569 |
-
|
570 |
-
|
571 |
-
st.
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
st.sidebar.
|
576 |
-
st.sidebar.
|
577 |
-
st.sidebar.
|
578 |
-
st.sidebar.markdown("-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
st.sidebar.
|
583 |
-
st.sidebar.
|
584 |
-
|
585 |
-
|
586 |
-
"
|
587 |
-
"
|
588 |
-
"
|
589 |
-
"
|
590 |
-
"
|
591 |
-
"
|
592 |
-
"
|
593 |
-
"
|
594 |
-
"
|
595 |
-
"
|
596 |
-
"
|
597 |
-
"
|
598 |
-
"
|
599 |
-
"
|
600 |
-
"
|
601 |
-
"
|
602 |
-
"
|
603 |
-
"
|
604 |
-
"
|
605 |
-
"
|
606 |
-
"
|
607 |
-
"
|
608 |
-
"
|
609 |
-
"
|
610 |
-
"
|
611 |
-
"
|
612 |
-
"The
|
613 |
-
"
|
614 |
-
"
|
615 |
-
"
|
616 |
-
"
|
617 |
-
"
|
618 |
-
"
|
619 |
-
"
|
620 |
-
"
|
621 |
-
"
|
622 |
-
"The
|
623 |
-
"
|
624 |
-
"
|
625 |
-
"
|
626 |
-
"
|
627 |
-
"
|
628 |
-
"
|
629 |
-
"
|
630 |
-
"
|
631 |
-
"
|
632 |
-
"
|
633 |
-
"
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
st.sidebar.
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
st.sidebar.
|
656 |
-
st.
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
if __name__ == "__main__":
|
661 |
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 tempfile
|
12 |
+
import time
|
13 |
+
import numpy as np
|
14 |
+
import threading
|
15 |
+
from playsound import playsound
|
16 |
+
import pygame
|
17 |
+
from scipy.io import wavfile
|
18 |
+
|
19 |
+
pygame.mixer.init()
|
20 |
+
|
21 |
+
# Load environment variables
|
22 |
+
load_dotenv()
|
23 |
+
|
24 |
+
AI71_BASE_URL = "https://api.ai71.ai/v1/"
|
25 |
+
AI71_API_KEY = os.getenv('AI71_API_KEY')
|
26 |
+
|
27 |
+
# Initialize the Falcon model
|
28 |
+
chat = ChatOpenAI(
|
29 |
+
model="tiiuae/falcon-180B-chat",
|
30 |
+
api_key=AI71_API_KEY,
|
31 |
+
base_url=AI71_BASE_URL,
|
32 |
+
streaming=True,
|
33 |
+
)
|
34 |
+
|
35 |
+
# Expanded Therapy techniques
|
36 |
+
THERAPY_TECHNIQUES = {
|
37 |
+
"CBT": "Use Cognitive Behavioral Therapy techniques to help the user identify and change negative thought patterns.",
|
38 |
+
"Mindfulness": "Guide the user through mindfulness exercises to promote present-moment awareness and reduce stress.",
|
39 |
+
"Solution-Focused": "Focus on the user's strengths and resources to help them find solutions to their problems.",
|
40 |
+
"Emotion-Focused": "Help the user identify, experience, and regulate their emotions more effectively.",
|
41 |
+
"Psychodynamic": "Explore the user's past experiences and unconscious patterns to gain insight into current issues.",
|
42 |
+
"ACT": "Use Acceptance and Commitment Therapy to help the user accept their thoughts and feelings while committing to positive changes.",
|
43 |
+
"DBT": "Apply Dialectical Behavior Therapy techniques to help the user manage intense emotions and improve relationships.",
|
44 |
+
"Gestalt": "Use Gestalt therapy techniques to focus on the present moment and increase self-awareness.",
|
45 |
+
"Existential": "Explore existential themes such as meaning, freedom, and responsibility to help the user find purpose.",
|
46 |
+
"Narrative": "Use storytelling and narrative techniques to help the user reframe their life experiences and create new meaning.",
|
47 |
+
}
|
48 |
+
|
49 |
+
def get_ai_response(user_input, buddy_config, therapy_technique=None):
|
50 |
+
system_message = f"You are {buddy_config['name']}, an AI companion with the following personality: {buddy_config['personality']}. "
|
51 |
+
system_message += f"Additional details about you: {buddy_config['details']}. "
|
52 |
+
|
53 |
+
if therapy_technique:
|
54 |
+
system_message += f"In this conversation, {THERAPY_TECHNIQUES[therapy_technique]}"
|
55 |
+
|
56 |
+
messages = [
|
57 |
+
SystemMessage(content=system_message),
|
58 |
+
HumanMessage(content=user_input)
|
59 |
+
]
|
60 |
+
response = chat.invoke(messages).content
|
61 |
+
return response
|
62 |
+
|
63 |
+
def play_sound_loop(sound_file, stop_event):
|
64 |
+
while not stop_event.is_set():
|
65 |
+
playsound(sound_file)
|
66 |
+
|
67 |
+
def play_sound_for_duration(sound_file, duration):
|
68 |
+
start_time = time.time()
|
69 |
+
while time.time() - start_time < duration:
|
70 |
+
playsound(sound_file, block=False)
|
71 |
+
time.sleep(0.1) # Short sleep to prevent excessive CPU usage
|
72 |
+
# Ensure the sound stops after the duration
|
73 |
+
pygame.mixer.quit()
|
74 |
+
|
75 |
+
def get_sound_files(directory):
|
76 |
+
return [f for f in os.listdir(directory) if f.endswith('.mp3')]
|
77 |
+
|
78 |
+
def get_sound_file_path(sound_name, sound_dir):
|
79 |
+
# Convert the sound name to a filename
|
80 |
+
filename = f"{sound_name.lower().replace(' ', '_')}.mp3"
|
81 |
+
return os.path.join(sound_dir, filename)
|
82 |
+
|
83 |
+
SOUND_OPTIONS = [
|
84 |
+
"Gentle Rain", "Ocean Waves", "Forest Ambience", "Soft Wind Chimes",
|
85 |
+
"Tibetan Singing Bowls", "Humming Song", "Crackling Fireplace",
|
86 |
+
"Birdsong", "White Noise", "Zen River", "Heartbeat", "Deep Space",
|
87 |
+
"Whale Songs", "Bamboo Flute", "Thunderstorm", "Cat Purring",
|
88 |
+
"Campfire", "Windchimes", "Waterfall", "Beach Waves", "Cicadas",
|
89 |
+
"Coffee Shop Ambience", "Grandfather Clock", "Rainstorm on Tent",
|
90 |
+
"Tropical Birds", "Subway Train", "Washing Machine", "Fan White Noise",
|
91 |
+
"Tibetan Bells", "Wind in Trees", "Meditation Bowl", "Meditation Bowl2", "Birds Singing Rainy Day"
|
92 |
+
]
|
93 |
+
|
94 |
+
def show_meditation_timer():
|
95 |
+
st.subheader("π§ββοΈ Enhanced Meditation Timer")
|
96 |
+
|
97 |
+
sound_dir = os.path.join(os.path.dirname(__file__), "..", "sounds")
|
98 |
+
|
99 |
+
col1, col2 = st.columns(2)
|
100 |
+
|
101 |
+
with col1:
|
102 |
+
duration = st.slider("Select duration (minutes)", 1, 60, 5)
|
103 |
+
background_sound = st.selectbox("Background Sound", SOUND_OPTIONS)
|
104 |
+
|
105 |
+
with col2:
|
106 |
+
interval_options = ["None", "Every 5 minutes", "Every 10 minutes"]
|
107 |
+
interval_reminder = st.selectbox("Interval Reminders", interval_options)
|
108 |
+
end_sound = st.selectbox("End of Session Sound", SOUND_OPTIONS)
|
109 |
+
|
110 |
+
if st.button("Start Meditation", key="start_meditation"):
|
111 |
+
progress_bar = st.progress(0)
|
112 |
+
status_text = st.empty()
|
113 |
+
|
114 |
+
# Initialize pygame mixer
|
115 |
+
pygame.mixer.init()
|
116 |
+
|
117 |
+
# Load background sound
|
118 |
+
background_sound_file = get_sound_file_path(background_sound, sound_dir)
|
119 |
+
if not os.path.exists(background_sound_file):
|
120 |
+
st.error(f"Background sound file not found: {background_sound_file}")
|
121 |
+
return
|
122 |
+
|
123 |
+
# Load end of session sound
|
124 |
+
end_sound_file = get_sound_file_path(end_sound, sound_dir)
|
125 |
+
if not os.path.exists(end_sound_file):
|
126 |
+
st.error(f"End sound file not found: {end_sound_file}")
|
127 |
+
return
|
128 |
+
|
129 |
+
# Play background sound on loop
|
130 |
+
pygame.mixer.music.load(background_sound_file)
|
131 |
+
pygame.mixer.music.play(-1) # -1 means loop indefinitely
|
132 |
+
|
133 |
+
start_time = time.time()
|
134 |
+
end_time = start_time + (duration * 60)
|
135 |
+
|
136 |
+
try:
|
137 |
+
while time.time() < end_time:
|
138 |
+
elapsed_time = time.time() - start_time
|
139 |
+
progress = elapsed_time / (duration * 60)
|
140 |
+
progress_bar.progress(progress)
|
141 |
+
|
142 |
+
remaining_time = end_time - time.time()
|
143 |
+
mins, secs = divmod(int(remaining_time), 60)
|
144 |
+
status_text.text(f"Time remaining: {mins:02d}:{secs:02d}")
|
145 |
+
|
146 |
+
if interval_reminder != "None":
|
147 |
+
interval = 5 if interval_reminder == "Every 5 minutes" else 10
|
148 |
+
if int(elapsed_time) > 0 and int(elapsed_time) % (interval * 60) == 0:
|
149 |
+
st.toast(f"{interval} minutes passed", icon="β°")
|
150 |
+
|
151 |
+
# Check if 10 seconds remaining
|
152 |
+
if remaining_time <= 10 and remaining_time > 9:
|
153 |
+
pygame.mixer.music.stop() # Stop background sound
|
154 |
+
pygame.mixer.Sound(end_sound_file).play() # Play end sound
|
155 |
+
|
156 |
+
if remaining_time <= 0:
|
157 |
+
break
|
158 |
+
|
159 |
+
time.sleep(0.1) # Update more frequently for smoother countdown
|
160 |
+
finally:
|
161 |
+
# Stop all sounds
|
162 |
+
pygame.mixer.quit()
|
163 |
+
|
164 |
+
# Ensure the progress bar is full and time remaining shows 00:00
|
165 |
+
progress_bar.progress(1.0)
|
166 |
+
status_text.text("Time remaining: 00:00")
|
167 |
+
|
168 |
+
st.success("Meditation complete!")
|
169 |
+
st.balloons()
|
170 |
+
|
171 |
+
if 'achievements' not in st.session_state:
|
172 |
+
st.session_state.achievements = set()
|
173 |
+
st.session_state.achievements.add("Zen Master")
|
174 |
+
st.success("Achievement Unlocked: Zen Master π§ββοΈ")
|
175 |
+
|
176 |
+
def show_personalized_recommendations():
|
177 |
+
st.subheader("π― Personalized Recommendations")
|
178 |
+
|
179 |
+
recommendation_categories = [
|
180 |
+
"Mental Health",
|
181 |
+
"Physical Health",
|
182 |
+
"Personal Development",
|
183 |
+
"Relationships",
|
184 |
+
"Career",
|
185 |
+
"Hobbies",
|
186 |
+
]
|
187 |
+
|
188 |
+
selected_category = st.selectbox("Choose a category", recommendation_categories)
|
189 |
+
|
190 |
+
recommendations = {
|
191 |
+
"Mental Health": [
|
192 |
+
"Practice daily gratitude journaling",
|
193 |
+
"Try a guided meditation for stress relief",
|
194 |
+
"Explore cognitive behavioral therapy techniques",
|
195 |
+
"Start a mood tracking journal",
|
196 |
+
"Learn about mindfulness practices",
|
197 |
+
],
|
198 |
+
"Physical Health": [
|
199 |
+
"Start a 30-day yoga challenge",
|
200 |
+
"Try intermittent fasting",
|
201 |
+
"Begin a couch to 5K running program",
|
202 |
+
"Experiment with new healthy recipes",
|
203 |
+
"Create a sleep hygiene routine",
|
204 |
+
],
|
205 |
+
"Personal Development": [
|
206 |
+
"Start learning a new language",
|
207 |
+
"Read personal development books",
|
208 |
+
"Take an online course in a subject you're interested in",
|
209 |
+
"Practice public speaking",
|
210 |
+
"Start a daily writing habit",
|
211 |
+
],
|
212 |
+
"Relationships": [
|
213 |
+
"Practice active listening techniques",
|
214 |
+
"Plan regular date nights or friend meetups",
|
215 |
+
"Learn about love languages",
|
216 |
+
"Practice expressing gratitude to loved ones",
|
217 |
+
"Join a local community or interest group",
|
218 |
+
],
|
219 |
+
"Career": [
|
220 |
+
"Update your resume and LinkedIn profile",
|
221 |
+
"Network with professionals in your industry",
|
222 |
+
"Set SMART career goals",
|
223 |
+
"Learn a new skill relevant to your field",
|
224 |
+
"Start a side project or freelance work",
|
225 |
+
],
|
226 |
+
"Hobbies": [
|
227 |
+
"Start a garden or learn about plant care",
|
228 |
+
"Try a new art form like painting or sculpting",
|
229 |
+
"Learn to play a musical instrument",
|
230 |
+
"Start a DIY home improvement project",
|
231 |
+
"Explore photography or videography",
|
232 |
+
],
|
233 |
+
}
|
234 |
+
|
235 |
+
st.write("Here are some personalized recommendations for you:")
|
236 |
+
for recommendation in recommendations[selected_category]:
|
237 |
+
st.markdown(f"- {recommendation}")
|
238 |
+
|
239 |
+
if st.button("Get More Recommendations"):
|
240 |
+
st.write("More tailored recommendations:")
|
241 |
+
additional_recs = random.sample(recommendations[selected_category], 3)
|
242 |
+
for rec in additional_recs:
|
243 |
+
st.markdown(f"- {rec}")
|
244 |
+
|
245 |
+
def generate_binaural_beat(freq1, freq2, duration_seconds, sample_rate=44100):
|
246 |
+
t = np.linspace(0, duration_seconds, int(sample_rate * duration_seconds), False)
|
247 |
+
left_channel = np.sin(2 * np.pi * freq1 * t)
|
248 |
+
right_channel = np.sin(2 * np.pi * freq2 * t)
|
249 |
+
stereo_audio = np.vstack((left_channel, right_channel)).T
|
250 |
+
return (stereo_audio * 32767).astype(np.int16)
|
251 |
+
|
252 |
+
def get_binary_file_downloader_html(bin_file, file_label='File'):
|
253 |
+
b64 = base64.b64encode(bin_file).decode()
|
254 |
+
return f'<a href="data:application/octet-stream;base64,{b64}" download="{file_label}.wav" class="download-link">Download {file_label}</a>'
|
255 |
+
|
256 |
+
def show_binaural_beats():
|
257 |
+
st.subheader("π΅ Binaural Beats Generator")
|
258 |
+
|
259 |
+
st.markdown("""
|
260 |
+
<style>
|
261 |
+
.stButton>button {
|
262 |
+
background-color: #4CAF50;
|
263 |
+
color: white;
|
264 |
+
font-weight: bold;
|
265 |
+
}
|
266 |
+
.download-link {
|
267 |
+
background-color: #008CBA;
|
268 |
+
color: white;
|
269 |
+
padding: 10px 15px;
|
270 |
+
text-align: center;
|
271 |
+
text-decoration: none;
|
272 |
+
display: inline-block;
|
273 |
+
font-size: 16px;
|
274 |
+
margin: 4px 2px;
|
275 |
+
cursor: pointer;
|
276 |
+
border-radius: 4px;
|
277 |
+
}
|
278 |
+
.stop-button {
|
279 |
+
background-color: #f44336;
|
280 |
+
color: white;
|
281 |
+
font-weight: bold;
|
282 |
+
}
|
283 |
+
</style>
|
284 |
+
""", unsafe_allow_html=True)
|
285 |
+
|
286 |
+
st.write("Binaural beats are created when two slightly different frequencies are played in each ear, potentially influencing brainwave activity.")
|
287 |
+
|
288 |
+
preset_beats = {
|
289 |
+
"Deep Relaxation (Delta)": {"base": 100, "beat": 2},
|
290 |
+
"Meditation (Theta)": {"base": 150, "beat": 6},
|
291 |
+
"Relaxation (Alpha)": {"base": 200, "beat": 10},
|
292 |
+
"Light Focus (Low Beta)": {"base": 250, "beat": 14},
|
293 |
+
"High Focus (Mid Beta)": {"base": 300, "beat": 20},
|
294 |
+
"Alertness (High Beta)": {"base": 350, "beat": 30},
|
295 |
+
"Gamma Consciousness": {"base": 400, "beat": 40},
|
296 |
+
"Lucid Dreaming": {"base": 180, "beat": 3},
|
297 |
+
"Memory Enhancement": {"base": 270, "beat": 12},
|
298 |
+
"Creativity Boost": {"base": 220, "beat": 8},
|
299 |
+
"Pain Relief": {"base": 130, "beat": 4},
|
300 |
+
"Mood Elevation": {"base": 315, "beat": 18}
|
301 |
+
}
|
302 |
+
|
303 |
+
col1, col2 = st.columns(2)
|
304 |
+
|
305 |
+
with col1:
|
306 |
+
beat_type = st.selectbox("Choose a preset or custom:", ["Custom"] + list(preset_beats.keys()))
|
307 |
+
|
308 |
+
with col2:
|
309 |
+
duration = st.slider("Duration (minutes):", 1, 60, 15)
|
310 |
+
|
311 |
+
if beat_type == "Custom":
|
312 |
+
col3, col4 = st.columns(2)
|
313 |
+
with col3:
|
314 |
+
base_freq = st.slider("Base Frequency (Hz):", 100, 500, 200)
|
315 |
+
with col4:
|
316 |
+
beat_freq = st.slider("Desired Beat Frequency (Hz):", 1, 40, 10)
|
317 |
+
else:
|
318 |
+
base_freq = preset_beats[beat_type]["base"]
|
319 |
+
beat_freq = preset_beats[beat_type]["beat"]
|
320 |
+
st.info(f"Base Frequency: {base_freq} Hz, Beat Frequency: {beat_freq} Hz")
|
321 |
+
|
322 |
+
if 'audio_playing' not in st.session_state:
|
323 |
+
st.session_state.audio_playing = False
|
324 |
+
|
325 |
+
if 'start_time' not in st.session_state:
|
326 |
+
st.session_state.start_time = None
|
327 |
+
|
328 |
+
if 'end_time' not in st.session_state:
|
329 |
+
st.session_state.end_time = None
|
330 |
+
|
331 |
+
# Create persistent placeholders for UI elements
|
332 |
+
progress_bar = st.empty()
|
333 |
+
status_text = st.empty()
|
334 |
+
stop_button = st.empty()
|
335 |
+
|
336 |
+
generate_button = st.button("Generate and Play Binaural Beat")
|
337 |
+
|
338 |
+
if generate_button:
|
339 |
+
try:
|
340 |
+
# Stop any currently playing audio
|
341 |
+
if st.session_state.audio_playing:
|
342 |
+
pygame.mixer.music.stop()
|
343 |
+
st.session_state.audio_playing = False
|
344 |
+
|
345 |
+
audio_data = generate_binaural_beat(base_freq, base_freq + beat_freq, duration * 60)
|
346 |
+
|
347 |
+
# Save the generated audio to a temporary file
|
348 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
|
349 |
+
temp_filename = temp_file.name
|
350 |
+
wavfile.write(temp_filename, 44100, audio_data)
|
351 |
+
|
352 |
+
# Initialize pygame mixer
|
353 |
+
pygame.mixer.init(frequency=44100, size=-16, channels=2)
|
354 |
+
|
355 |
+
# Load and play the audio
|
356 |
+
pygame.mixer.music.load(temp_filename)
|
357 |
+
pygame.mixer.music.play()
|
358 |
+
st.session_state.audio_playing = True
|
359 |
+
|
360 |
+
st.session_state.start_time = time.time()
|
361 |
+
st.session_state.end_time = st.session_state.start_time + (duration * 60)
|
362 |
+
|
363 |
+
except Exception as e:
|
364 |
+
st.error(f"An error occurred: {str(e)}")
|
365 |
+
st.info("Please try again or contact support if the issue persists.")
|
366 |
+
|
367 |
+
if st.session_state.audio_playing:
|
368 |
+
stop_button_active = stop_button.button("Stop Binaural Beat", key="stop_binaural", type="primary")
|
369 |
+
current_time = time.time()
|
370 |
+
|
371 |
+
if stop_button_active:
|
372 |
+
pygame.mixer.music.stop()
|
373 |
+
st.session_state.audio_playing = False
|
374 |
+
st.session_state.start_time = None
|
375 |
+
st.session_state.end_time = None
|
376 |
+
|
377 |
+
elif current_time < st.session_state.end_time:
|
378 |
+
elapsed_time = current_time - st.session_state.start_time
|
379 |
+
progress = elapsed_time / (st.session_state.end_time - st.session_state.start_time)
|
380 |
+
progress_bar.progress(progress)
|
381 |
+
|
382 |
+
remaining_time = st.session_state.end_time - current_time
|
383 |
+
mins, secs = divmod(int(remaining_time), 60)
|
384 |
+
status_text.text(f"Time remaining: {mins:02d}:{secs:02d}")
|
385 |
+
else:
|
386 |
+
pygame.mixer.music.stop()
|
387 |
+
st.session_state.audio_playing = False
|
388 |
+
st.session_state.start_time = None
|
389 |
+
st.session_state.end_time = None
|
390 |
+
progress_bar.empty()
|
391 |
+
status_text.text("Binaural beat session complete!")
|
392 |
+
|
393 |
+
# Offer download of the generated audio
|
394 |
+
if not st.session_state.audio_playing and 'audio_data' in locals():
|
395 |
+
with io.BytesIO() as buffer:
|
396 |
+
wavfile.write(buffer, 44100, audio_data)
|
397 |
+
st.markdown(get_binary_file_downloader_html(buffer.getvalue(), f"binaural_beat_{base_freq}_{beat_freq}Hz"), unsafe_allow_html=True)
|
398 |
+
|
399 |
+
# Ensure the app updates every second
|
400 |
+
if st.session_state.audio_playing:
|
401 |
+
time.sleep(1)
|
402 |
+
st.experimental_rerun()
|
403 |
+
|
404 |
+
def main():
|
405 |
+
st.set_page_config(page_title="S.H.E.R.L.O.C.K. AI Buddy", page_icon="π΅οΈ", layout="wide")
|
406 |
+
|
407 |
+
# Custom CSS for improved styling
|
408 |
+
st.markdown("""
|
409 |
+
<style>
|
410 |
+
.stApp {
|
411 |
+
background-color: #f0f2f6;
|
412 |
+
}
|
413 |
+
.stButton>button {
|
414 |
+
background-color: #4CAF50;
|
415 |
+
color: white;
|
416 |
+
font-weight: bold;
|
417 |
+
}
|
418 |
+
.stTextInput>div>div>input {
|
419 |
+
background-color: #ffffff;
|
420 |
+
}
|
421 |
+
</style>
|
422 |
+
""", unsafe_allow_html=True)
|
423 |
+
|
424 |
+
st.title("π΅οΈ S.H.E.R.L.O.C.K. AI Buddy")
|
425 |
+
st.markdown("Your personalized AI companion for conversation, therapy, and personal growth.")
|
426 |
+
|
427 |
+
# Initialize session state
|
428 |
+
if 'buddy_name' not in st.session_state:
|
429 |
+
st.session_state.buddy_name = "Sherlock"
|
430 |
+
if 'buddy_personality' not in st.session_state:
|
431 |
+
st.session_state.buddy_personality = "Friendly, empathetic, and insightful"
|
432 |
+
if 'buddy_details' not in st.session_state:
|
433 |
+
st.session_state.buddy_details = "Knowledgeable about various therapy techniques and always ready to listen"
|
434 |
+
if 'messages' not in st.session_state:
|
435 |
+
st.session_state.messages = []
|
436 |
+
|
437 |
+
# Sidebar for AI Buddy configuration and additional features
|
438 |
+
with st.sidebar:
|
439 |
+
st.header("π€ Configure Your AI Buddy")
|
440 |
+
st.session_state.buddy_name = st.text_input("Name your AI Buddy", value=st.session_state.buddy_name)
|
441 |
+
st.session_state.buddy_personality = st.text_area("Describe your buddy's personality", value=st.session_state.buddy_personality)
|
442 |
+
st.session_state.buddy_details = st.text_area("Additional details about your buddy", value=st.session_state.buddy_details)
|
443 |
+
|
444 |
+
st.header("π§ Therapy Session")
|
445 |
+
therapy_mode = st.checkbox("Enable Therapy Mode")
|
446 |
+
if therapy_mode:
|
447 |
+
therapy_technique = st.selectbox("Select Therapy Technique", list(THERAPY_TECHNIQUES.keys()))
|
448 |
+
else:
|
449 |
+
therapy_technique = None
|
450 |
+
|
451 |
+
st.markdown("---")
|
452 |
+
|
453 |
+
st.subheader("π Todo List")
|
454 |
+
if 'todos' not in st.session_state:
|
455 |
+
st.session_state.todos = []
|
456 |
+
|
457 |
+
new_todo = st.text_input("Add a new todo:")
|
458 |
+
if st.button("Add Todo", key="add_todo"):
|
459 |
+
if new_todo:
|
460 |
+
st.session_state.todos.append({"task": new_todo, "completed": False})
|
461 |
+
st.success("Todo added successfully!")
|
462 |
+
else:
|
463 |
+
st.warning("Please enter a todo item.")
|
464 |
+
|
465 |
+
for i, todo in enumerate(st.session_state.todos):
|
466 |
+
col1, col2, col3 = st.columns([0.05, 0.8, 0.15])
|
467 |
+
with col1:
|
468 |
+
todo['completed'] = st.checkbox("", todo['completed'], key=f"todo_{i}")
|
469 |
+
with col2:
|
470 |
+
st.write(todo['task'], key=f"todo_text_{i}")
|
471 |
+
with col3:
|
472 |
+
if st.button("ποΈ", key=f"delete_{i}", help="Delete todo"):
|
473 |
+
st.session_state.todos.pop(i)
|
474 |
+
st.experimental_rerun()
|
475 |
+
|
476 |
+
st.subheader("β±οΈ Pomodoro Timer")
|
477 |
+
pomodoro_duration = st.slider("Pomodoro Duration (minutes)", 1, 60, 25)
|
478 |
+
if st.button("Start Pomodoro"):
|
479 |
+
progress_bar = st.progress(0)
|
480 |
+
for i in range(pomodoro_duration * 60):
|
481 |
+
time.sleep(1)
|
482 |
+
progress_bar.progress((i + 1) / (pomodoro_duration * 60))
|
483 |
+
st.success("Pomodoro completed!")
|
484 |
+
if 'achievements' not in st.session_state:
|
485 |
+
st.session_state.achievements = set()
|
486 |
+
st.session_state.achievements.add("Consistent Learner")
|
487 |
+
|
488 |
+
st.markdown("---")
|
489 |
+
st.markdown("Powered by Falcon-180B and Streamlit")
|
490 |
+
|
491 |
+
st.markdown("---")
|
492 |
+
st.header("π Daily Journal")
|
493 |
+
journal_entry = st.text_area("Write your thoughts for today")
|
494 |
+
if st.button("Save Journal Entry"):
|
495 |
+
if 'journal_entries' not in st.session_state:
|
496 |
+
st.session_state.journal_entries = []
|
497 |
+
st.session_state.journal_entries.append({
|
498 |
+
'date': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
499 |
+
'entry': journal_entry
|
500 |
+
})
|
501 |
+
st.success("Journal entry saved!")
|
502 |
+
st.toast("Journal entry saved successfully!", icon="β
")
|
503 |
+
|
504 |
+
if 'journal_entries' in st.session_state and st.session_state.journal_entries:
|
505 |
+
st.subheader("Previous Entries")
|
506 |
+
for entry in st.session_state.journal_entries[-5:]: # Show last 5 entries
|
507 |
+
st.text(entry['date'])
|
508 |
+
st.write(entry['entry'])
|
509 |
+
st.markdown("---")
|
510 |
+
|
511 |
+
# Main content area
|
512 |
+
tab1, tab2 = st.tabs(["Chat", "Tools"])
|
513 |
+
|
514 |
+
with tab1:
|
515 |
+
# Chat interface
|
516 |
+
st.header("π¨οΈ Chat with Your AI Buddy")
|
517 |
+
|
518 |
+
# Display chat history
|
519 |
+
chat_container = st.container()
|
520 |
+
with chat_container:
|
521 |
+
for message in st.session_state.messages:
|
522 |
+
with st.chat_message(message["role"]):
|
523 |
+
st.markdown(message["content"])
|
524 |
+
|
525 |
+
# User input
|
526 |
+
prompt = st.chat_input("What's on your mind?")
|
527 |
+
|
528 |
+
# Clear chat history button
|
529 |
+
if st.button("Clear Chat History"):
|
530 |
+
st.session_state.messages = []
|
531 |
+
st.experimental_rerun()
|
532 |
+
|
533 |
+
if prompt:
|
534 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
535 |
+
with st.chat_message("user"):
|
536 |
+
st.markdown(prompt)
|
537 |
+
|
538 |
+
buddy_config = {
|
539 |
+
"name": st.session_state.buddy_name,
|
540 |
+
"personality": st.session_state.buddy_personality,
|
541 |
+
"details": st.session_state.buddy_details
|
542 |
+
}
|
543 |
+
|
544 |
+
with st.chat_message("assistant"):
|
545 |
+
message_placeholder = st.empty()
|
546 |
+
full_response = ""
|
547 |
+
for chunk in chat.stream(get_ai_response(prompt, buddy_config, therapy_technique)):
|
548 |
+
full_response += chunk.content
|
549 |
+
message_placeholder.markdown(full_response + "β")
|
550 |
+
message_placeholder.markdown(full_response)
|
551 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
552 |
+
|
553 |
+
# Force a rerun to update the chat history immediately
|
554 |
+
st.experimental_rerun()
|
555 |
+
|
556 |
+
with tab2:
|
557 |
+
tool_choice = st.selectbox("Select a tool", ["Meditation Timer", "Binaural Beats", "Recommendations"])
|
558 |
+
if tool_choice == "Meditation Timer":
|
559 |
+
show_meditation_timer()
|
560 |
+
elif tool_choice == "Recommendations":
|
561 |
+
show_personalized_recommendations()
|
562 |
+
elif tool_choice == "Binaural Beats":
|
563 |
+
show_binaural_beats()
|
564 |
+
|
565 |
+
# Mood tracker
|
566 |
+
st.sidebar.markdown("---")
|
567 |
+
st.sidebar.header("π Mood Tracker")
|
568 |
+
mood = st.sidebar.slider("How are you feeling today?", 1, 10, 5)
|
569 |
+
if st.sidebar.button("Log Mood"):
|
570 |
+
st.sidebar.success(f"Mood logged: {mood}/10")
|
571 |
+
st.balloons()
|
572 |
+
|
573 |
+
# Resources and Emergency Contact
|
574 |
+
st.sidebar.markdown("---")
|
575 |
+
st.sidebar.header("π Resources")
|
576 |
+
st.sidebar.info("If you're in crisis, please reach out for help:")
|
577 |
+
st.sidebar.markdown("- [Mental Health Resources](https://www.mentalhealth.gov/get-help/immediate-help)")
|
578 |
+
st.sidebar.markdown("- Emergency Contact: 911 or your local emergency number")
|
579 |
+
|
580 |
+
# Inspiration Quote
|
581 |
+
st.sidebar.markdown("---")
|
582 |
+
st.sidebar.header("π‘ Daily Inspiration")
|
583 |
+
if st.sidebar.button("Get Inspirational Quote"):
|
584 |
+
quotes = [
|
585 |
+
"The only way to do great work is to love what you do. - Steve Jobs",
|
586 |
+
"Believe you can and you're halfway there. - Theodore Roosevelt",
|
587 |
+
"The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt",
|
588 |
+
"Strive not to be a success, but rather to be of value. - Albert Einstein",
|
589 |
+
"The only limit to our realization of tomorrow will be our doubts of today. - Franklin D. Roosevelt",
|
590 |
+
"Do not wait to strike till the iron is hot; but make it hot by striking. - William Butler Yeats",
|
591 |
+
"What lies behind us and what lies before us are tiny matters compared to what lies within us. - Ralph Waldo Emerson",
|
592 |
+
"Success is not final, failure is not fatal: It is the courage to continue that counts. - Winston Churchill",
|
593 |
+
"Life is what happens when you're busy making other plans. - John Lennon",
|
594 |
+
"You miss 100% of the shots you don't take. - Wayne Gretzky",
|
595 |
+
"The best way to predict the future is to create it. - Peter Drucker",
|
596 |
+
"It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change. - Charles Darwin",
|
597 |
+
"Whether you think you can or you think you can't, you're right. - Henry Ford",
|
598 |
+
"The only place where success comes before work is in the dictionary. - Vidal Sassoon",
|
599 |
+
"Do what you can, with what you have, where you are. - Theodore Roosevelt",
|
600 |
+
"The purpose of our lives is to be happy. - Dalai Lama",
|
601 |
+
"Success usually comes to those who are too busy to be looking for it. - Henry David Thoreau",
|
602 |
+
"Your time is limited, so don't waste it living someone else's life. - Steve Jobs",
|
603 |
+
"Don't be afraid to give up the good to go for the great. - John D. Rockefeller",
|
604 |
+
"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
|
605 |
+
"Success is not the key to happiness. Happiness is the key to success. - Albert Schweitzer",
|
606 |
+
"It does not matter how slowly you go, as long as you do not stop. - Confucius",
|
607 |
+
"If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success. - James Cameron",
|
608 |
+
"Don't watch the clock; do what it does. Keep going. - Sam Levenson",
|
609 |
+
"Hardships often prepare ordinary people for an extraordinary destiny. - C.S. Lewis",
|
610 |
+
"Don't count the days, make the days count. - Muhammad Ali",
|
611 |
+
"The best revenge is massive success. - Frank Sinatra",
|
612 |
+
"The only impossible journey is the one you never begin. - Tony Robbins",
|
613 |
+
"Act as if what you do makes a difference. It does. - William James",
|
614 |
+
"You are never too old to set another goal or to dream a new dream. - C.S. Lewis",
|
615 |
+
"If you're going through hell, keep going. - Winston Churchill",
|
616 |
+
"Dream big and dare to fail. - Norman Vaughan",
|
617 |
+
"In the middle of every difficulty lies opportunity. - Albert Einstein",
|
618 |
+
"What we achieve inwardly will change outer reality. - Plutarch",
|
619 |
+
"I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison",
|
620 |
+
"It always seems impossible until it's done. - Nelson Mandela",
|
621 |
+
"The future depends on what you do today. - Mahatma Gandhi",
|
622 |
+
"Don't wait. The time will never be just right. - Napoleon Hill",
|
623 |
+
"Quality is not an act, it is a habit. - Aristotle",
|
624 |
+
"Your life does not get better by chance, it gets better by change. - Jim Rohn",
|
625 |
+
"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",
|
626 |
+
"Challenges are what make life interesting; overcoming them is what makes life meaningful. - Joshua J. Marine",
|
627 |
+
"Opportunities don't happen, you create them. - Chris Grosser",
|
628 |
+
"I can't change the direction of the wind, but I can adjust my sails to always reach my destination. - Jimmy Dean",
|
629 |
+
"Start where you are. Use what you have. Do what you can. - Arthur Ashe",
|
630 |
+
"The secret of getting ahead is getting started. - Mark Twain",
|
631 |
+
"You donβt have to be great to start, but you have to start to be great. - Zig Ziglar",
|
632 |
+
"Keep your eyes on the stars, and your feet on the ground. - Theodore Roosevelt",
|
633 |
+
"The only way to achieve the impossible is to believe it is possible. - Charles Kingsleigh"
|
634 |
+
]
|
635 |
+
|
636 |
+
random_quote = random.choice(quotes)
|
637 |
+
st.sidebar.success(random_quote)
|
638 |
+
|
639 |
+
# Chat Export
|
640 |
+
st.sidebar.markdown("---")
|
641 |
+
if st.sidebar.button("Export Chat History"):
|
642 |
+
chat_history = "\n".join([f"{msg['role']}: {msg['content']}" for msg in st.session_state.messages])
|
643 |
+
st.sidebar.download_button(
|
644 |
+
label="Download Chat History",
|
645 |
+
data=chat_history,
|
646 |
+
file_name="ai_buddy_chat_history.txt",
|
647 |
+
mime="text/plain"
|
648 |
+
)
|
649 |
+
|
650 |
+
st.sidebar.success("Chat history ready for download!")
|
651 |
+
|
652 |
+
# Display achievements
|
653 |
+
if 'achievements' in st.session_state and st.session_state.achievements:
|
654 |
+
st.sidebar.markdown("---")
|
655 |
+
st.sidebar.header("π Achievements")
|
656 |
+
for achievement in st.session_state.achievements:
|
657 |
+
st.sidebar.success(f"Unlocked: {achievement}")
|
658 |
+
|
659 |
+
if __name__ == "__main__":
|
|
|
660 |
main()
|