Iammcqwory commited on
Commit
1024844
·
verified ·
1 Parent(s): d5c7a44

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from datetime import datetime
3
+ import random
4
+
5
+ # Mock database for user data and resources
6
+ if "mood_history" not in st.session_state:
7
+ st.session_state.mood_history = []
8
+
9
+ if "streak" not in st.session_state:
10
+ st.session_state.streak = 0
11
+
12
+ if "last_login" not in st.session_state:
13
+ st.session_state.last_login = None
14
+
15
+ if "personalized_resources" not in st.session_state:
16
+ st.session_state.personalized_resources = []
17
+
18
+ resources = {
19
+ "stress_management": ["Article: 5 Ways to Manage Stress", "Video: Mindfulness Techniques", "Podcast: Stress Relief Tips"],
20
+ "mindfulness": ["Article: Introduction to Mindfulness", "Video: Guided Meditation", "Podcast: Daily Mindfulness Practices"],
21
+ "emotional_intelligence": ["Article: Understanding Emotions", "Video: Building Emotional Resilience", "Podcast: Emotional Intelligence 101"]
22
+ }
23
+
24
+ # Function to track mood
25
+ def track_mood():
26
+ mood = st.selectbox("How are you feeling today?", ["happy", "sad", "anxious", "angry", "calm"])
27
+ if st.button("Submit Mood"):
28
+ st.session_state.mood_history.append((datetime.now().strftime("%Y-%m-%d %H:%M:%S"), mood))
29
+ st.success(f"Your mood '{mood}' has been recorded. Thank you for sharing!")
30
+
31
+ # Function to provide personalized recommendations
32
+ def recommend_resources():
33
+ if not st.session_state.mood_history:
34
+ st.warning("No mood data available. Please track your mood first.")
35
+ return
36
+
37
+ # Get the latest mood
38
+ latest_mood = st.session_state.mood_history[-1][1]
39
+
40
+ # Simple logic for recommendations based on mood
41
+ if latest_mood in ["sad", "angry"]:
42
+ st.session_state.personalized_resources = resources["stress_management"] + resources["emotional_intelligence"]
43
+ elif latest_mood == "anxious":
44
+ st.session_state.personalized_resources = resources["mindfulness"] + resources["stress_management"]
45
+ else:
46
+ st.session_state.personalized_resources = random.choice(list(resources.values()))
47
+
48
+ st.subheader("Here are some resources tailored for you:")
49
+ for resource in st.session_state.personalized_resources:
50
+ st.write(f"- {resource}")
51
+
52
+ # Function to handle gamification (streaks)
53
+ def check_streak():
54
+ today = datetime.now().date()
55
+ last_login = st.session_state.last_login
56
+
57
+ if last_login and (today - last_login).days == 1:
58
+ st.session_state.streak += 1
59
+ elif not last_login or (today - last_login).days > 1:
60
+ st.session_state.streak = 1
61
+
62
+ st.session_state.last_login = today
63
+ st.success(f"You're on a {st.session_state.streak}-day streak! Keep it up!")
64
+
65
+ # Main app layout
66
+ def main():
67
+ st.title("AfyaMind: Your Mental Health Companion")
68
+ st.sidebar.title("Menu")
69
+ menu_choice = st.sidebar.radio("Choose an option", ["Track Mood", "Get Personalized Resources", "Check Streak"])
70
+
71
+ if menu_choice == "Track Mood":
72
+ st.header("Track Your Mood")
73
+ track_mood()
74
+
75
+ elif menu_choice == "Get Personalized Resources":
76
+ st.header("Personalized Resources")
77
+ recommend_resources()
78
+
79
+ elif menu_choice == "Check Streak":
80
+ st.header("Your Streak")
81
+ check_streak()
82
+
83
+ # Run the app
84
+ if __name__ == "__main__":
85
+ main()