Spaces:
Sleeping
Sleeping
File size: 5,832 Bytes
a77dfbc 5e733eb 655bf69 a77dfbc 5e733eb bcf7c59 5e733eb a77dfbc 5e733eb a77dfbc 25f2b4c 5e733eb a77dfbc 5e733eb 5c21c82 a77dfbc 5e733eb 25f2b4c 5e733eb 5c21c82 5e733eb 052f6c8 5c21c82 25f2b4c 5c21c82 25f2b4c 5c21c82 acd8491 5e733eb 5023ab3 5e733eb 655bf69 5e733eb acd8491 5e733eb acd8491 5e733eb 5b26654 5e733eb |
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 |
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import pipeline
# Set page config as the very first Streamlit 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 an aesthetic background with a soothing gradient for a calming effect and black text
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,
)
# 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)")
|