Spaces:
Sleeping
Sleeping
File size: 6,129 Bytes
a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc 11d653c a77dfbc |
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 |
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Set page config for a clean interface
st.set_page_config(page_title="Emotion Prediction & Well-being Suggestions", page_icon="🌺", layout="centered")
# Title and Introduction
st.title("Emotion Prediction & Well-being Suggestions")
st.markdown("""
This app uses AI to understand your emotions based on your responses. Afterward, you'll receive well-being suggestions to improve your mood, tailored specifically for you and your cultural context in Hawaii.
""")
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
model = AutoModelForSequenceClassification.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
# Define well-being suggestions with URLs for articles and videos based on the emotion
def get_wellbeing_suggestions(emotion):
suggestions = {
"joy": [
"Keep enjoying life! Consider a walk on the beach, or some hula dancing to feel the rhythm of the island.",
"Articles and Resources: [Emotional Wellness Toolkit - NIH](https://www.nih.gov/health-information/emotional-wellness-toolkit)",
"Videos: [Hula Dance for Well-being](https://youtu.be/m1vaUGtyo-A)"
],
"anger": [
"Practice deep breathing and mindfulness exercises. Perhaps try surfing or a peaceful walk in nature.",
"Articles and Resources: [Tips for Dealing with Anxiety - HelpGuide](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)",
"Videos: [Mindful Breathing Meditation](https://www.youtube.com/shorts/Tq49ajl7c8Q?feature=share)"
],
"sadness": [
"Try a short meditation session or call a friend to chat. Hawaii offers stunning sunsets perfect for reflection.",
"Articles and Resources: [Health A-Z - Harvard Health](https://www.health.harvard.edu/health-a-to-z)",
"Videos: [Mindful Breathing Meditation](https://youtu.be/MIc299Flibs)"
],
"fear": [
"Take a calming breath and practice grounding techniques. Explore Hawaiian mindfulness practices to feel centered.",
"Articles and Resources: [Mindful Breathing Meditation - HelpGuide](https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation)",
"Videos: [Relaxing Mindfulness Exercise](https://www.youtube.com/shorts/fwH8Ygb0K60?feature=share)"
],
"surprise": [
"Embrace the feeling and explore new activities like paddleboarding or hiking.",
"Articles and Resources: [Emotional Wellness Toolkit - NIH](https://www.nih.gov/health-information/emotional-wellness-toolkit)",
"Videos: [Surprising Relaxation Tips](https://youtu.be/yGKKz185M5o)"
],
"disgust": [
"Do something relaxing, like yoga or watching the waves crash against the shore.",
"Articles and Resources: [Tips for Dealing with Anxiety - HelpGuide](https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety)",
"Videos: [Hawaiian Mindfulness Practice](https://www.youtube.com/shorts/hTXMi7ZBKdM?feature=share)"
]
}
return suggestions.get(emotion, [
"Try some breathing exercises and give yourself time to relax.",
"Articles and Resources: [Health A-Z - Harvard Health](https://www.health.harvard.edu/health-a-to-z)",
"Videos: [Calming Breath Exercises](https://youtu.be/Y8HIFRPU6pM)"
])
# Emotional Health Questions
questions = [
"How would you describe your mood today? (e.g., happy, stressed, calm)",
"Are there any recent events that might be affecting your emotional state?",
"How do you generally cope with stress or emotional challenges?"
]
responses = []
for question in questions:
response = st.text_input(question)
responses.append(response)
# Process the responses
if all(responses):
user_input = " ".join(responses)
# Tokenize the user input and make predictions
inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding=True)
outputs = model(**inputs)
predictions = torch.argmax(outputs.logits, dim=-1) # Get the index of the predicted class
emotion_label = model.config.id2label[predictions.item()] # Get the label of the predicted class
# Show emotion and well-being suggestions
st.subheader(f"Your Predicted Emotion: {emotion_label.capitalize()}")
st.write(f"Based on your responses, we suggest the following to improve your well-being:")
wellbeing_suggestions = get_wellbeing_suggestions(emotion_label.lower())
for suggestion in wellbeing_suggestions:
st.write(f"- {suggestion}")
# Show Summary Button
if st.button("Show Summary"):
st.subheader("Summary of Well-being Suggestions")
for suggestion in wellbeing_suggestions:
st.write(f"- {suggestion}")
st.markdown("---")
st.write("For more well-being tips and resources, explore the following links:")
st.markdown("[Hawaii Mindfulness Practice](https://www.hawaiimindfulness.org)")
st.markdown("[Hula Dance for Well-being](https://hulahealsthesoul.com)")
else:
st.warning("Please answer all the questions to receive emotional health suggestions.")
# Add custom background image to make it visually appealing
st.markdown("""
<style>
.stApp {
background-image: url('https://images.unsplash.com/photo-1602231353203-b1e5e2191b68');
background-size: cover;
background-position: center;
}
.stButton > button {
background-color: #F57F17;
color: white;
font-size: 18px;
padding: 10px;
}
.stButton > button:hover {
background-color: #FF6F00;
}
.stTextInput > div > input {
background-color: rgba(255, 255, 255, 0.7);
font-size: 16px;
color: #333;
}
.stMarkdown p {
font-size: 16px;
color: white;
}
</style>
""", unsafe_allow_html=True)
|