File size: 5,779 Bytes
4c0c8ad
bb770b6
 
 
b2b6d6f
18119f4
596e12a
29ef757
4c0c8ad
29ef757
 
 
4c0c8ad
 
92e98fb
 
 
 
 
 
 
 
 
1426741
18119f4
92e98fb
7b937b1
 
 
 
 
 
 
 
92e98fb
 
 
7b937b1
 
 
 
 
 
 
 
1426741
18119f4
92e98fb
7b937b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c0c8ad
1426741
 
92e98fb
 
 
 
 
 
7b937b1
92e98fb
7b937b1
 
1426741
92e98fb
 
 
 
 
1426741
18119f4
 
92e98fb
4c0c8ad
92e98fb
29ef757
92e98fb
 
4c0c8ad
 
92e98fb
596e12a
92e98fb
 
 
18119f4
92e98fb
 
 
d1a4559
92e98fb
 
 
d1a4559
92e98fb
 
b2b6d6f
 
d1a4559
92e98fb
d1a4559
 
 
92e98fb
d1a4559
 
 
92e98fb
d1a4559
b2b6d6f
92e98fb
d1a4559
 
 
b525e52
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
import random
import streamlit as st
from transformers import pipeline

# Emotion classifier (use a pre-trained model from Hugging Face)
emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased")

# Updated Question Database (Doctor-prescribed questions)
questions = [
    "How are you feeling emotionally right now?",
    "What physical sensations or discomfort are you experiencing?",
    "Is there something specific that's been troubling your thoughts?"
]

# Expanded Mood States
moods = [
    "Happy", "Excited", "Relaxed", "Grateful", "Calm",
    "Dull", "Neutral", "Tired", "Bored", "Lonely",
    "Angry", "Frustrated", "Anxious", "Stressed", "Overwhelmed",
    "Hopeful", "Confused", "Motivated", "Curious", "Peaceful"
]

# Suggestion Database
suggestion_database = {
    "POSITIVE": {
        "suggestions": ["Celebrate your success!", "Share your happiness with someone.", "Reflect on what makes you feel this way."],
        "articles": [
            {"title": "Emotional Wellness Toolkit", "url": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
            {"title": "Health A to Z", "url": "https://www.health.harvard.edu/health-a-to-z"},
        ],
        "videos": [
            {"title": "Boosting Happiness", "url": "https://youtu.be/m1vaUGtyo-A"},
            {"title": "Motivational Short Video", "url": "https://www.youtube.com/shorts/Tq49ajl7c8Q?feature=share"},
        ],
    },
    "NEGATIVE": {
        "suggestions": ["Take a break to relax.", "Talk to someone you trust.", "Try mindfulness exercises."],
        "articles": [
            {"title": "Tips for Dealing with Anxiety", "url": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
            {"title": "Mindful Breathing Meditation", "url": "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"},
        ],
        "videos": [
            {"title": "Coping with Anxiety", "url": "https://youtu.be/MIc299Flibs"},
            {"title": "Relaxation Techniques", "url": "https://www.youtube.com/shorts/fwH8Ygb0K60?feature=share"},
        ],
    },
    "NEUTRAL": {
        "suggestions": ["Take a short walk.", "Plan your next task mindfully.", "Enjoy a calming activity like reading."],
        "articles": [
            {"title": "Finding Balance", "url": "https://www.health.harvard.edu/health-a-to-z"},
            {"title": "Emotional Wellness Toolkit", "url": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
        ],
        "videos": [
            {"title": "Mindfulness for Beginners", "url": "https://youtu.be/Y8HIFRPU6pM"},
            {"title": "Peaceful Mind Short", "url": "https://www.youtube.com/shorts/hTXMi7ZBKdM?feature=share"},
        ],
    },
    "STRESSED": {
        "suggestions": ["Practice deep breathing exercises.", "Write down your thoughts to release stress.", "Spend time in a quiet environment."],
        "articles": [
            {"title": "Mindful Breathing Meditation", "url": "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"},
            {"title": "Tips for Dealing with Anxiety", "url": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
        ],
        "videos": [
            {"title": "Managing Stress", "url": "https://youtu.be/-e-4Kx5px_I"},
            {"title": "Overcoming Overwhelm", "url": "https://www.youtube.com/shorts/fwH8Ygb0K60?feature=share"},
        ],
    },
}

# Function to map moods to emotion categories
def map_mood_to_category(mood):
    if mood in ["Happy", "Excited", "Relaxed", "Grateful", "Calm", "Hopeful", "Motivated", "Curious", "Peaceful"]:
        return "POSITIVE"
    elif mood in ["Dull", "Neutral", "Tired", "Bored", "Lonely"]:
        return "NEUTRAL"
    elif mood in ["Angry", "Frustrated", "Anxious", "Stressed", "Overwhelmed"]:
        return "NEGATIVE"
    else:
        return "STRESSED"

# Function to suggest activities based on the mood
def suggest_activity(mood):
    category = map_mood_to_category(mood)
    resources = suggestion_database.get(category, {})
    return resources

# Streamlit app
def main():
    st.title("Mood Analysis and Suggestions")
    
    # Step 1: Display the questions
    st.write("Answer the following 3 questions to help us understand your mood:")
    responses = []
    for i, question in enumerate(questions, start=1):
        response = st.text_input(f"{i}. {question}")
        if response:
            responses.append(response)
    
    # Step 2: Analyze responses if all questions are answered
    if len(responses) == len(questions):
        combined_text = " ".join(responses)
        
        # Analyze responses to determine mood
        analysis_result = emotion_analyzer(combined_text)
        detected_emotion = analysis_result[0]['label']
        
        # Map detected emotion to a mood state
        detected_mood = random.choice(moods)  # Mock mapping for demonstration
        st.write(f"Detected Mood: {detected_mood}")
        
        # Step 3: Fetch suggestions based on mood
        resources = suggest_activity(detected_mood)
        
        # Display suggestions, articles, and videos
        st.write("Suggestions:")
        for suggestion in resources.get("suggestions", []):
            st.write(f"- {suggestion}")
        
        st.write("Articles:")
        for article in resources.get("articles", []):
            st.write(f"- [{article['title']}]({article['url']})")
        
        st.write("Videos:")
        for video in resources.get("videos", []):
            st.write(f"- [{video['title']}]({video['url']})")
    else:
        st.write("Please answer all questions to receive suggestions.")

if __name__ == "__main__":
    main()