|
import streamlit as st |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
from transformers import pipeline |
|
|
|
|
|
st.set_page_config(page_title="Emotion Detection and Well-Being Suggestions", layout="wide") |
|
|
|
|
|
@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() |
|
|
|
|
|
st.markdown( |
|
""" |
|
<style> |
|
body { |
|
background: linear-gradient(135deg, #8e2de2, #4a00e0); /* Purple gradient for a calm vibe */ |
|
background-size: cover; |
|
background-attachment: fixed; |
|
color: black; /* Set text color to black */ |
|
} |
|
.stButton button { |
|
background-color: #6c63ff; /* Blue button color to match the calming purple gradient */ |
|
color: white; |
|
font-size: 20px; |
|
} |
|
.stTextInput input { |
|
background-color: rgba(255, 255, 255, 0.2); /* Semi-transparent background for text input */ |
|
color: black; /* Black text for input fields */ |
|
font-size: 16px; |
|
} |
|
.stMarkdown { |
|
color: black; /* Ensure markdown text is black for better readability */ |
|
} |
|
</style> |
|
""", |
|
unsafe_allow_html=True, |
|
) |
|
|
|
|
|
st.title("Emotion Detection and Well-Being Suggestions") |
|
|
|
|
|
user_input = st.text_area("How are you feeling today?", "Enter your thoughts here...") |
|
|
|
|
|
if user_input: |
|
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer) |
|
result = pipe(user_input) |
|
|
|
|
|
emotion = result[0]['label'] |
|
|
|
|
|
st.write(f"**Emotion 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)") |
|
|
|
|
|
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)") |
|
|