File size: 7,170 Bytes
a77dfbc
a9fe7c6
a77dfbc
112c544
bcf7c59
 
 
 
 
 
 
 
a77dfbc
bcf7c59
a77dfbc
bcf7c59
 
a77dfbc
bcf7c59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f3e04d
 
 
 
 
 
 
 
 
 
 
 
 
 
a77dfbc
bcf7c59
 
 
 
 
a77dfbc
bcf7c59
 
05946ab
bcf7c59
a77dfbc
 
052f6c8
a77dfbc
11d653c
05946ab
11d653c
052f6c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174675d
 
 
 
6ba3f8f
 
 
 
 
 
 
 
 
a77dfbc
bcf7c59
 
 
 
 
 
 
 
 
 
 
defadc6
 
112c544
defadc6
 
 
13edd9b
defadc6
 
 
 
 
 
 
 
 
 
 
 
 
5b26654
 
 
 
 
 
 
 
 
 
 
 
 
bcf7c59
5b26654
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Load emotion classification model
@st.cache_resource
def load_model():
    try:
        emotion_classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
        return emotion_classifier
    except Exception as e:
        st.error(f"Error loading model: {str(e)}")
        return None

emotion_classifier = load_model()

# Well-being suggestions based on emotions
def get_well_being_suggestions(emotion):
    suggestions = {
        "joy": {
            "text": "You're feeling joyful! Keep the positivity going.",
            "links": [
                "https://www.nih.gov/health-information/emotional-wellness-toolkit",
                "https://www.health.harvard.edu/health-a-to-z",
                "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"
            ],
            "videos": [
                "https://youtu.be/m1vaUGtyo-A",
                "https://youtu.be/MIc299Flibs"
            ]
        },
        "anger": {
            "text": "You're feeling angry. Take a moment to calm down.",
            "links": [
                "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety",
                "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"
            ],
            "videos": [
                "https://youtu.be/m1vaUGtyo-A",
                "https://www.youtube.com/shorts/fwH8Ygb0K60?feature=share"
            ]
        },
        "sadness": {
            "text": "You're feeling sad. It's okay to take a break.",
            "links": [
                "https://www.nih.gov/health-information/emotional-wellness-toolkit",
                "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"
            ],
            "videos": [
                "https://youtu.be/-e-4Kx5px_I",
                "https://youtu.be/Y8HIFRPU6pM"
            ]
        },
        "fear": {
            "text": "You're feeling fearful. Try some relaxation techniques.",
            "links": [
                "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety",
                "https://www.health.harvard.edu/health-a-to-z"
            ],
            "videos": [
                "https://www.youtube.com/shorts/Tq49ajl7c8Q?feature=share",
                "https://youtu.be/yGKKz185M5o"
            ]
        },
        "disgust": {
            "text": "You're feeling disgusted. Take a deep breath and refocus.",
            "links": [
                "https://www.health.harvard.edu/health-a-to-z",
                "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"
            ],
            "videos": [
                "https://youtu.be/MIc299Flibs",
                "https://youtu.be/-e-4Kx5px_I"
            ]
        },
        # New addition for "Surprise"
        "surprise": {
            "text": "You're feeling surprised. Take a deep breath and ground yourself.",
            "links": [
                "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety",
                "https://www.health.harvard.edu/health-a-to-z",
                "https://www.psychologytoday.com/us/blog/mindful-anger/201908/5-ways-to-deal-with-unexpected-surprises"
            ],
            "videos": [
                "https://youtu.be/MIc299Flibs",
                "https://www.youtube.com/shorts/Tq49ajl7c8Q?feature=share",
                "https://youtu.be/m1vaUGtyo-A"
            ]
        },
    }
    return suggestions.get(emotion, {
        "text": "Feeling neutral? That's okay! Take care of your mental health.",
        "links": [],
        "videos": []
    })

# Streamlit UI
def main():
    # Custom Styling for purple background and white text color
    st.markdown("""
    <style>
    .stApp {
        background-color: #6a0dad;  /* Purple background */
        background-size: cover;
        background-position: center;
        color: white;  /* Set text color to white */
    }
    
    h1, h2, h3 {
        color: white;
        font-family: 'Arial', sans-serif;
    }
    
    .stTextArea textarea {
        background-color: #f2f2f2;  /* Light grey text area */
        border-radius: 8px;
        color: #333333;
    }
    
    .stButton button {
        background-color: #9b4dca;  /* Purple button */
        color: white;
        font-weight: bold;
        border-radius: 5px;
    }

    .stButton button:hover {
        background-color: #7a33a2;  /* Darker purple on hover */
    }

    .stMarkdown, .stWrite {
        color: white !important;
    }

    /* Style for links to make them more visible */
    a {
        color: #ffffff;
        text-decoration: underline;
    }
    a:hover {
        color: #ffccff;  /* Light purple hover effect */
    }
    </style>
    """, unsafe_allow_html=True)
    
    # Title of the app
    st.title("Emotion Prediction and Well-being Suggestions")
    
    # User input for emotional state
    st.header("Tell us how you're feeling today!")
    
    user_input = st.text_area("Enter a short sentence about your current mood:", "")
    
    if user_input:
        # Display Enter button only after user has entered input
        enter_button = st.button("Enter")
        
        if enter_button:
            # Clean the input text (stripping unnecessary spaces, lowercasing)
            clean_input = user_input.strip().lower()
            
            # Use the model to predict emotion
            try:
                result = emotion_classifier(clean_input)
                st.write(f"Raw Model Result: {result}")  # Debug output to see raw result
                
                emotion = result[0]['label'].lower()
                
                st.subheader(f"Emotion Detected: {emotion.capitalize()}")
                
                # Get well-being suggestions based on emotion
                suggestions = get_well_being_suggestions(emotion)
                
                # Display text suggestions
                st.write(suggestions["text"])

                # Display links
                if suggestions["links"]:
                    st.write("Useful Resources:")
                    for link in suggestions["links"]:
                        st.markdown(f"[{link}]({link})", unsafe_allow_html=True)

                # Display video links
                if suggestions["videos"]:
                    st.write("Relaxation Videos:")
                    for video in suggestions["videos"]:
                        st.markdown(f"[Watch here]({video})", unsafe_allow_html=True)
            
                # Add a button for a summary
                if st.button('Summary'):
                    st.write(f"Emotion detected: {emotion.capitalize()}. Here are your well-being suggestions to enhance your mood.")
                    st.write("Explore the links and videos to improve your emotional health!")
            
            except Exception as e:
                st.error(f"Error predicting emotion: {str(e)}")

# Run the Streamlit app
if __name__ == "__main__":
    main()