forked from Amna-Hassan04/Serenity-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
565 lines (437 loc) · 22.6 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
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
314
315
316
317
318
319
320
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
import base64
import datetime
import streamlit as st
import plotly.express as px
import pandas as pd
import requests, random
from streamlit_lottie import st_lottie
from streamlit_option_menu import option_menu
import os
from dotenv import load_dotenv
#AI Integration
import anthropic
import datetime
import datetime
# CSS for Scroll to Top Button
scroll_to_top = """
<style>
#scrollButton {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 99;
font-size: 18px;
border: none;
outline: none;
background-color: rgb(4, 170, 109);
color: white;
cursor: pointer;
padding: 10px;
border-radius: 10px;
opacity: 0.7;
}
#scrollButton:hover {
background-color: rgb(4, 170, 109);
opacity: 1;
}
</style>
"""
#Changes made by --Charvi Arora
#Added security
# Load environment variables from .env file
load_dotenv()
# Retrieve the API key
claude_api_key = os.getenv("CLAUDE_API_KEY")
client = anthropic.Client(api_key=claude_api_key)
def anxiety_management_guide(mood, feeling_description, current_stress_level, recent_events):
# Construct the message for ClaudeAI
message = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=250,
temperature=0.2,
system=f"You are a helpful mental health assistant that helps users manage their anxiety based on their mood, feelings, stress level, and recent events. Provide recommendations for exercises and techniques to reduce anxiety based on the user's mood, {mood}, their feelings described as: {feeling_description}, their current stress level of {current_stress_level}, and recent events: {recent_events}.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"Task: Help me manage my anxiety. I'm feeling {mood}. Here's what I'm experiencing: {feeling_description}. My current stress level is {current_stress_level}, and these are some recent events that might have contributed: {recent_events}\n\nConsiderations:\nProvide tailored anxiety-reduction exercises.\nConsider the user's mood, stress level, feelings, and recent events.\nOffer practical and effective techniques.\nEnsure the suggestions are easy to follow."
}
]
}
]
)
# Set page config (must be the first Streamlit command)
st.set_page_config(page_title="SereniFi", page_icon=":relieved:", layout="centered")
st.markdown(scroll_to_top, unsafe_allow_html=True)
def scroll_to_top_button():
st.markdown('<a id="scrollButton" title="Go to top" href="#top">↑ Top</a>', unsafe_allow_html=True)
st.markdown('<div id="top"></div>', unsafe_allow_html=True)
scroll_to_top_button()
# Data for mental health (sampled)
data = {
'Activity': ['Meditation', 'Yoga', 'Breathing', 'Journaling', 'Music'],
'Calmness_Level': [85, 78, 90, 75, 88]
}
df = px.data.tips() # Use your actual anxiety relief data
@st.cache_data
def get_img_as_base64(file):
with open(file, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
# Animated background
page_bg_img = f"""
<style>
/* Animated background gradient */
[data-testid="stAppViewContainer"] > .main {{
background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
background-size: 400% 400%;
animation: gradientBG 15s ease infinite;
}}
[data-testid="stSidebar"] > div:first-child {{
background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
background-size: 400% 400%;
animation: gradientBG 15s ease infinite;
}}
[data-testid="stHeader"] {{
background: rgba(0,0,0,0);
}}
[data-testid="stToolbar"] {{
right: 2rem;
}}
.main .block-container {{
max-width: 900px; /* Increase the width of the centered section */
padding: 2rem 1rem; /* Adjust padding for a more spacious look */
}}
@keyframes gradientBG {{
0% {{
background-position: 0% 50%;
}}
50% {{
background-position: 100% 50%;
}}
100% {{
background-position: 0% 50%;
}}
}}
</style>
"""
st.markdown(page_bg_img, unsafe_allow_html=True)
def load_lottie_url(url: str):
response = requests.get(url)
if response.status_code == 200:
return response.json()
return None
# Main function to control page navigation
def main():
selected = option_menu(
menu_title=None,
options=["Home", "Calm Space", "About & Feedback"],
icons=["house-door-fill", "cloud-sun-fill", "chat-dots-fill"],
menu_icon="sun",
default_index=0,
orientation="horizontal",
styles={
"container": {"padding": "0!important", "background-color": "#333", "border-radius": "10px", "box-shadow": "0 4px 6px rgba(0, 0, 0, 0.1)"},
"nav-link": {
"font-size": "18px",
"text-align": "center",
"margin": "0px",
"--hover-color": "#ddd",
"border-radius": "10px",
"color": "#fff",
"background-color": "rgba(0, 0, 0, 0.8)", # More opaque background
"transition": "background-color 0.3s ease, transform 0.2s"
},
"nav-link-selected": {"background-color": "#04AA6D", "color": "#fff", "transform": "scale(1.1)"}
}
)
if selected == "Home":
show_main_page()
elif selected == "Calm Space":
show_calm_space()
elif selected == "About & Feedback":
show_about_and_feedback()
def show_main_page():
st.markdown(
"""
<style>
.centered-title {
text-align: center;
font-size: 2.5rem;
font-weight: bold;
}
</style>
<h1 class="centered-title">Welcome to SereniFi</h1>
""", unsafe_allow_html=True
)
st.markdown('<h3 class="pulse" style="text-align: center;">Feel Calm, Centered, and Peaceful</h3>', unsafe_allow_html=True)
st.image("https://images.pexels.com/photos/185801/pexels-photo-185801.jpeg?auto=compress&cs=tinysrgb&w=600", caption="Breathe and Relax", use_column_width=True)
st.write("---")
# Interactive content
st.markdown("""
### Welcome to Your Oasis of Calm
Imagine a sanctuary where you can escape the hustle and bustle of everyday life—this is your space to recharge and rejuvenate. Embracing mental health is not just about addressing issues; it's about nurturing your inner self and fostering a sense of tranquility.
**Discover Your Path to Peace:**
- **Mindful Breathing:** Click below to start a guided breathing exercise that helps calm your mind instantly.
- **Relaxation Techniques:** Explore various methods to integrate relaxation into your daily routine.
- **Personalized Tips:** Answer a quick survey to receive tailored advice for enhancing your well-being.
**Engage with Us:**
- Share your favorite relaxation techniques or feedback on how our platform helps you.
Your path to a serene and fulfilling life starts here. Let’s embark on this journey together—take the first step today!
""")
# Interactive Widgets
if st.button('Start Guided Breathing'):
st.balloons()
st.write("**Guided Breathing Exercise:** Inhale deeply through your nose for 4 seconds, hold for 4 seconds, and exhale slowly through your mouth. Repeat this process a few times to feel the calming effect.")
st.write("---")
# Survey for Personalized Tips
st.subheader("Personalized Tips for You")
with st.form(key='personalized_tips_form'):
mood = st.radio("What's your current anxiety level?", ["Low", "Moderate", "High", "Overwhelmed"])
submit_button = st.form_submit_button("Get Tips")
if submit_button:
tips = {
"Low": "Keep up the great work! Stay consistent with mindfulness techniques.",
"Moderate": "Take a moment to practice deep breathing.",
"High": "Pause and try a guided meditation.",
"Overwhelmed": "It's important to step away and take a break."
}
st.write(f"**Tip:** {tips[mood]}")
st.write("---")
st.markdown("""
### Embrace Your Journey to Wellness
Taking care of your mental health is an ongoing journey that requires attention and effort. It's essential to recognize the value of setting aside time for yourself amidst your busy schedule. Activities such as mindfulness, relaxation exercises, and engaging in hobbies can significantly improve your overall well-being.
Remember, mental health is not just the absence of mental illness but a state of complete emotional, psychological, and social well-being. Incorporating small, positive changes into your daily routine can lead to a more balanced and fulfilling life. Embrace these practices with an open heart and notice the positive impact they have on your day-to-day life.
""")
st.video("https://www.youtube.com/watch?v=inpok4MKVLM", start_time=10)
st.write("---")
st.markdown('<h4 style="text-align: center;">The Importance of Mental Health</h4>', unsafe_allow_html=True)
st.write("Mental health is just as important as physical health, but often overlooked. It affects how we think, feel, and act in our daily lives. Prioritizing mental well-being can help us manage stress, connect with others, and make healthier choices.")
# Interactive section for viewers
st.subheader("Let's Explore How Mental Health Affects You")
# User input on mental health habits
daily_mindfulness = st.radio("How often do you practice mindfulness or self-care?", ["Daily", "Weekly", "Occasionally", "Rarely"])
if daily_mindfulness == "Daily":
st.success("Amazing! Regular self-care routines greatly enhance mental wellness.")
elif daily_mindfulness == "Weekly":
st.info("Great start! Try increasing your self-care sessions to enhance its benefits.")
elif daily_mindfulness == "Occasionally":
st.warning("It's good you're trying! Consistency can help you feel more balanced.")
else:
st.error("Mental health is crucial! Start small by incorporating simple self-care practices.")
st.write("---")
# Tip for improving mental health
st.subheader("Quick Tip for Mental Health")
if st.button("Get a Tip"):
tips = [
"Take a few minutes to practice deep breathing daily.",
"Keep a gratitude journal to focus on the positive.",
"Engage in physical activity to boost your mood.",
"Take breaks when you're feeling overwhelmed.",
"Connect with loved ones and share how you're feeling."
]
st.write(f"Tip: {random.choice(tips)}")
lottie_url_breathing = "https://lottie.host/89b3ab99-b7ee-4764-ac3a-5fe1ef057bde/WaOPmT23PU.json"
lottie_json_breathing = load_lottie_url(lottie_url_breathing)
if lottie_json_breathing:
st.markdown(
"""
<style>
.lottie-container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background: none;
}
.lottie-item {
margin: 0 10px; /* Add space between animations */
}
.lottie-animation {
background: transparent; /* Make the background of the animation transparent */
}
</style>
<div class="lottie-container">
""", unsafe_allow_html=True)
st.markdown('<div class="lottie-item lottie-animation">', unsafe_allow_html=True)
st_lottie(lottie_json_breathing, speed=1, width=300, height=300, key="breathing-animation")
st.markdown('</div>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)
st.write("---")
# Convert data to a DataFrame
df = pd.DataFrame(data)
# Introduction to the Data Visualization
st.markdown("""
### Explore the Impact of Different Activities
Understanding which activities can best help in reducing anxiety is essential for making informed decisions about your mental wellness.
Use this visualization to see which activities might work best for you and consider incorporating them into your daily routine. Remember, what works for one person may differ for another, so it's important to explore and find what resonates with you.
""")
# Interactive Section: Activity Preferences
st.subheader("Which Activities Do You Prefer?")
activities = st.multiselect(
"Select the activities you enjoy or want to try:",
options=df['Activity'],
default=df['Activity']
)
if activities:
st.write("You selected:", ", ".join(activities))
selected_data = df[df['Activity'].isin(activities)]
fig_selected = px.bar(selected_data, x='Activity', y='Calmness_Level', title="Selected Activities Effectiveness")
st.plotly_chart(fig_selected)
st.write("---")
st.markdown('<p style="text-align: center;">© 2024 SereniFi. All rights reserved.</p>', unsafe_allow_html=True)
def soothing_sounds():
st.header("🎵 Calm Down with Soothing Sounds")
#Contributions made by Himanshi-M
sound_options = {
"Rain": "https://cdn.pixabay.com/audio/2022/05/13/audio_257112ce99.mp3",
"Ocean Waves": "https://cdn.pixabay.com/audio/2022/06/07/audio_b9bd4170e4.mp3",
"Forest": "https://cdn.pixabay.com/audio/2022/03/10/audio_4dedf5bf94.mp3",
"Birds Chirping":"https://cdn.pixabay.com/audio/2022/03/09/audio_c610232c26.mp3",
"River Flowing":"https://cdn.pixabay.com/audio/2024/07/30/audio_319893354c.mp3",
"White Noise":"https://cdn.pixabay.com/audio/2022/03/12/audio_b4f7e5a4ff.mp3",
"Pink Noise": "https://cdn.pixabay.com/audio/2023/10/07/audio_df9c190caf.mp3"
}
selected_sound = st.selectbox("Choose a sound to relax:", list(sound_options.keys()))
# Organizing the button, checkbox and volume slider on the same row
col1, col2, col3 = st.columns([1,1,2])
with col1:
playbutton=st.button("Play Sound")
with col2:
# Looping Checkbox
loopcheckbox = st.checkbox("Loop Sound")
if playbutton:
# Rendering the audio player and JS in the app
with col3:
st.audio(sound_options[selected_sound], format="audio/mp3", loop=loopcheckbox)
def interactive_journal():
if 'journal_entries' not in st.session_state:
st.session_state.journal_entries = []
journal_input = st.text_area("📝 Daily Journal", placeholder="Write down your thoughts...")
if st.button("Save Entry"):
st.session_state.journal_entries.append({
"date": datetime.datetime.now(),
"entry": journal_input
})
st.success("Journal entry saved!")
# Display past journal entries
if st.checkbox("Show Past Entries"):
st.write("### Past Journal Entries:")
for entry in st.session_state.journal_entries:
st.write(f"**{entry['date'].strftime('%Y-%m-%d %H:%M:%S')}**: {entry['entry']}")
def mood_boosting_mini_games():
st.markdown("Relax with a fun mini-game to distract your mind. Choose the game yo want:")
st.markdown("[Play Pacman](https://www.google.co.in/search?q=pacman&sca_esv=aaaa9a10aaa1b9d1&sca_upv=1&sxsrf=ADLYWIJzV0yNeS6YptYfZn5AEFUKvBUtSw%3A1725304252827&ei=vA3WZqCaMrLy4-EPiZmBwAw&ved=0ahUKEwig6PmY-6SIAxUy-TgGHYlMAMgQ4dUDCBA&uact=5&oq=pacman&gs_lp=Egxnd3Mtd2l6LXNlcnAiBnBhY21hbjIQEC4YgAQYsQMYQxiDARiKBTIOEC4YgAQYkQIYsQMYigUyEBAAGIAEGLEDGEMYgwEYigUyExAuGIAEGLEDGEMYgwEY1AIYigUyChAuGIAEGEMYigUyChAAGIAEGEMYigUyBRAAGIAEMg0QABiABBixAxhDGIoFMggQABiABBixAzIFEAAYgAQyHxAuGIAEGLEDGEMYgwEYigUYlwUY3AQY3gQY4ATYAQFI3hZQ5A5Y8BRwAXgBkAEAmAHlAaABiwqqAQMyLTa4AQPIAQD4AQGYAgegAp8LwgIKEAAYsAMY1gQYR8ICBBAjGCfCAgoQIxiABBgnGIoFwgILEAAYgAQYkQIYigXCAg4QABiABBixAxiDARiKBcICCxAAGIAEGLEDGIMBwgIOEC4YgAQYkQIY1AIYigXCAhAQLhiABBhDGMcBGIoFGK8BmAMAiAYBkAYGugYGCAEQARgUkgcFMS4wLjagB5Vj&sclient=gws-wiz-serp)")
st.markdown("[Play Thinking Brain](https://kidshelpline.com.au/games/thinking-brain)")
st.markdown("[Play Snake Game](https://www.google.co.in/search?si=ACC90nwm_DCLUGduakF5oU94y1HpDc2j-V_TsJpED11KWNYygOhydoKqqSH9t8iyybygqTEoKMZa&biw=1536&bih=695&dpr=1.25)")
def show_calm_space():
st.title("Calm Space")
st.write("Engage in a breathing exercise to calm your mind.")
st.subheader("Quick Tips for Positivity")
quick_tips = [
"Take a deep breath and count to 5.",
"Focus on what you can control, not on what you can't.",
"Take a moment to reflect on something you're grateful for.",
"Smile at yourself in the mirror."
]
st.write("\n".join(f"- {tip}" for tip in quick_tips))
st.write("---")
# Interactive Section: Daily Challenge Suggestions
st.subheader("Daily Challenge Suggestions")
challenges = {
"Meditation": "Try a 10-minute guided meditation session today. Find a quiet space and focus on your breath.",
"Yoga": "Follow a 15-minute yoga routine to stretch and relax your body. Check out a video for guidance.",
"Breathing": "Engage in deep breathing exercises for 5 minutes. Inhale deeply for 4 seconds, hold for 4 seconds, and exhale slowly.",
"Journaling": "Spend 10 minutes writing down your thoughts and feelings. Reflect on your day and your emotions.",
"Music": "Listen to calming music or nature sounds for 20 minutes. Allow the sounds to help you relax and unwind."
}
selected_challenge = st.selectbox("Choose an activity for your daily challenge:", options=list(challenges.keys()))
if selected_challenge:
st.write(f"**Today's Challenge:** {challenges[selected_challenge]}")
st.write("Set a reminder to complete this challenge today. Remember, consistency is key to building habits and improving your mental well-being.")
st.write("---")
st.subheader("Daily Anxeity Check")
# Sidebar Inputs
st.subheader("📝 Share Your Current State:")
mood = st.selectbox("How are you feeling today?", ["Anxious", "Stressed", "Overwhelmed", "Calm", "Other"])
feeling_description = st.text_area("What exactly are you feeling?", placeholder="Describe your feelings here...")
current_stress_level = st.slider("Current Stress Level (1 to 10)", 1, 10, value=5)
recent_events = st.text_area("Recent Events", placeholder="Describe any recent events that may have contributed to your anxiety or stress...")
if st.button("Submit"):
st.write("Thank you for sharing. Let’s find some exercises to help you.")
guidance = anxiety_management_guide(mood, feeling_description, current_stress_level, recent_events)
st.write(guidance)
st.subheader("Mood-Boosting Mini Games")
st.write("Take a break and play a mini-game to reduce your anxiety.")
if st.button("Start Game"):
st.write("Launching a quick mood-boosting game...")
mood_boosting_mini_games()
st.write("---")
soothing_sounds()
st.write("---")
st.subheader("Interactive Journaling")
if st.button("Submit Journal Entry"):
st.success("Journal entry: It's important to reflect and release your emotions.")
interactive_journal()
st.write("---")
st.markdown('<p style="text-align: center;">© 2024 SereniFi. All rights reserved.</p>', unsafe_allow_html=True)
def show_about_and_feedback():
st.title("About Us & Feedback")
st.write("""
**Welcome to SereniFi!**
We are dedicated to promoting mental wellness through interactive and accessible tools. Our mission is to provide a supportive environment where individuals can explore effective techniques for managing anxiety and improving overall mental well-being.
""")
st.write("""
Our team consists of mental health professionals, wellness coaches, and tech enthusiasts who are passionate about making mental health resources accessible to everyone. We believe that everyone deserves a space to find calm, learn about wellness, and connect with supportive tools and communities.
""")
st.write("""
**Our Vision**
We envision a world where mental wellness is prioritized and accessible to all. Through innovative solutions and a user-centric approach, we aim to create a space where individuals can find the support they need to thrive.
""")
st.write("""
**Meet the Team**
- **Amna Hassan** - Back-end Developer
- **Anushka Pote** - Wellness Coach
- **Madhuri K** - Front-end Developer
- **Pearl Vashishta** - Community Manager
""")
st.write("---")
# Interactive Feedback on Activities
st.subheader("Share Your Experience")
st.write("""
We'd love to hear how these activities are working for you. Your feedback helps others find effective ways to manage anxiety and improve their mental wellness. Feel free to share your thoughts, experiences, or suggestions.
""")
feedback_activity = st.text_area("How have the activities helped you? Share your experience here:")
if st.button("Submit Feedback"):
if feedback_activity:
st.success("Thank you for sharing your experience! Your feedback is valuable and appreciated.")
st.write("---")
# Our Advertising Partners
st.subheader("Our Advertising Partners")
st.write("Check out our partners in mental wellness products and services:")
st.write("- **Mindfulness App**: An app offering guided meditations and mindfulness exercises.")
st.write("- **Relaxation Techniques Guide**: A comprehensive guide to various relaxation techniques and their benefits.")
st.write("---")
# Call to Action
st.subheader("Get Involved")
st.write("""
Interested in supporting our mission? There are several ways you can get involved:
- **Volunteer**: Join our team of volunteers to help others benefit from our platform.
- **Donate**: Support our efforts by contributing to our cause.
- **Share**: Spread the word about our platform to help us reach more people in need.
For more information, visit our [website](#) or contact us at [[email protected]](mailto:[email protected]).
""")
st.write("---")
# Subscribe for Updates
st.subheader("Subscribe for Updates")
st.write("Stay updated with our latest features, activities, and wellness tips.")
email = st.text_input("Enter your email address:")
if st.button("Subscribe"):
if email:
st.success("Thank you for subscribing! You'll receive updates and tips directly to your inbox.")
st.write("---")
st.markdown('<p style="text-align: center;">© 2024 SereniFi. All rights reserved.</p>', unsafe_allow_html=True)
if __name__ == "__main__":
main()