File size: 5,303 Bytes
a77dfbc
655bf69
a77dfbc
5023ab3
bcf7c59
 
5023ab3
 
 
 
 
 
 
 
a77dfbc
5023ab3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a77dfbc
5023ab3
 
 
 
a77dfbc
5023ab3
 
a77dfbc
5023ab3
052f6c8
acd8491
5023ab3
8b475fa
5023ab3
 
 
 
 
 
 
 
 
 
 
655bf69
5023ab3
 
 
 
 
 
 
 
 
 
 
 
 
 
acd8491
5023ab3
 
 
 
 
acd8491
5023ab3
 
 
 
 
 
 
 
 
 
 
 
 
5b26654
5023ab3
 
 
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
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"
            ]
        },
    }
    return suggestions.get(emotion, {
        "text": "Feeling neutral? That's okay! Take care of your mental health.",
        "links": [],
        "videos": []
    })

# Streamlit UI
def main():
    # Set the background image
    st.markdown("""
    <style>
    .stApp {
        background-image: url('https://www.example.com/your-image.jpg');
        background-size: cover;
        background-position: center;
    }
    </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:
        # 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})")

            # Display video links
            if suggestions["videos"]:
                st.write("Relaxation Videos:")
                for video in suggestions["videos"]:
                    st.markdown(f"[Watch here]({video})")
            
            # 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()