File size: 5,438 Bytes
a77dfbc
655bf69
 
a77dfbc
655bf69
 
 
 
bcf7c59
 
655bf69
 
 
a77dfbc
655bf69
a77dfbc
655bf69
 
 
a77dfbc
655bf69
 
a77dfbc
655bf69
 
 
 
 
 
 
 
052f6c8
acd8491
655bf69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b475fa
655bf69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b26654
655bf69
 
 
 
 
 
 
 
 
acd8491
655bf69
 
 
 
 
 
 
 
acd8491
655bf69
 
 
 
 
 
 
 
5b26654
655bf69
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import pipeline

# Set page configuration - MUST be the first command
st.set_page_config(page_title="Emotion Detection and Well-Being Suggestions", layout="wide")

# Load pre-trained model and tokenizer
@st.cache_resource
def load_model():
    tokenizer = AutoTokenizer.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
    model = AutoModelForSequenceClassification.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
    return tokenizer, model

tokenizer, model = load_model()

# Add a background image (use your own URL or file path here)
st.markdown(
    """
    <style>
    body {
        background-image: url('https://drive.google.com/uc?export=view&id=1TydbjDRL5fXLMxQgaPkIg9oGOJlU2IWt');
        background-size: cover;
        background-repeat: no-repeat;
        background-attachment: fixed;
        color: white;
    }
    .stButton button {
        background-color: #6c63ff;
        color: white;
        font-size: 20px;
    }
    </style>
    """,
    unsafe_allow_html=True,
)

# Display header
st.title("Emotion Detection and Well-Being Suggestions")

# User input for text (emotion detection)
user_input = st.text_area("How are you feeling today?", "Enter your thoughts here...")

# Model prediction
if user_input:
    pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
    result = pipe(user_input)

    # Extracting the emotion from the model's result
    emotion = result[0]['label']

    # Display emotion
    st.write(f"**Emotion Detected:** {emotion}")
    
    # Provide suggestions based on the detected emotion
    if emotion == 'joy':
        st.write("You're feeling happy! Keep up the great mood!")
        st.write("Useful Resources:")
        st.markdown("[Relaxation Techniques](https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation)")
        st.write("[Dealing with Stress](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)")
        st.write("[Emotional Wellness Toolkit](https://www.nih.gov/health-information/emotional-wellness-toolkit)")
        
        st.write("Relaxation Videos:")
        st.markdown("[Watch on YouTube](https://youtu.be/m1vaUGtyo-A)")

    elif emotion == 'anger':
        st.write("You're feeling angry. It's okay to feel this way. Let's try to calm down.")
        st.write("Useful Resources:")
        st.markdown("[Emotional Wellness Toolkit](https://www.nih.gov/health-information/emotional-wellness-toolkit)")
        st.write("[Stress Management Tips](https://www.health.harvard.edu/health-a-to-z)")
        st.write("[Dealing with Anger](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)")
        
        st.write("Relaxation Videos:")
        st.markdown("[Watch on YouTube](https://youtu.be/MIc299Flibs)")

    elif emotion == 'fear':
        st.write("You're feeling fearful. Take a moment to breathe and relax.")
        st.write("Useful Resources:")
        st.markdown("[Mindfulness Practices](https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation)")
        st.write("[Coping with Anxiety](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)")
        st.write("[Emotional Wellness Toolkit](https://www.nih.gov/health-information/emotional-wellness-toolkit)")
        
        st.write("Relaxation Videos:")
        st.markdown("[Watch on YouTube](https://youtu.be/yGKKz185M5o)")

    elif emotion == 'sadness':
        st.write("You're feeling sad. It's okay to take a break.")
        st.write("Useful Resources:")
        st.markdown("[Emotional Wellness Toolkit](https://www.nih.gov/health-information/emotional-wellness-toolkit)")
        st.write("[Dealing with Anxiety](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)")
        
        st.write("Relaxation Videos:")
        st.markdown("[Watch on YouTube](https://youtu.be/-e-4Kx5px_I)")

    elif emotion == 'surprise':
        st.write("You're feeling surprised. It's okay to feel neutral!")
        st.write("Useful Resources:")
        st.markdown("[Managing Stress](https://www.health.harvard.edu/health-a-to-z)")
        st.write("[Coping Strategies](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)")
        
        st.write("Relaxation Videos:")
        st.markdown("[Watch on YouTube](https://youtu.be/m1vaUGtyo-A)")

    # Add a button for summary
    if st.button("Show Summary"):
        st.write(f"Emotion Detected: {emotion}")
        st.write("Useful Resources based on your mood:")
        if emotion == 'joy':
            st.write("[Relaxation Techniques](https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation)")
        elif emotion == 'anger':
            st.write("[Stress Management Tips](https://www.health.harvard.edu/health-a-to-z)")
        elif emotion == 'fear':
            st.write("[Mindfulness Practices](https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation)")
        elif emotion == 'sadness':
            st.write("[Dealing with Anxiety](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)")
        elif emotion == 'surprise':
            st.write("[Managing Stress](https://www.health.harvard.edu/health-a-to-z)")