|
import random |
|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased") |
|
|
|
|
|
questions = [ |
|
"How are you feeling today in one word?", |
|
"What's currently on your mind?", |
|
"Do you feel calm or overwhelmed right now?", |
|
] |
|
|
|
|
|
suggestion_database = { |
|
"NEGATIVE": { |
|
"suggestions": ["Try guided meditation", "Take a walk in nature", "Connect with a loved one"], |
|
"articles": [ |
|
{"title": "Emotional Wellness Toolkit", "url": "https://www.nih.gov/health-information/emotional-wellness-toolkit"}, |
|
{"title": "Understanding Anxiety", "url": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"}, |
|
], |
|
"videos": [ |
|
{"title": "Mindfulness for Calm", "url": "https://youtu.be/m1vaUGtyo-A"}, |
|
{"title": "Relaxation Techniques", "url": "https://www.youtube.com/shorts/Tq49ajl7c8Q?feature=share"}, |
|
], |
|
}, |
|
"POSITIVE": { |
|
"suggestions": ["Practice gratitude", "Engage in a hobby", "Celebrate your wins"], |
|
"articles": [ |
|
{"title": "Benefits of Joy", "url": "https://www.health.harvard.edu/health-a-to-z"}, |
|
{"title": "Gratitude Practices", "url": "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"}, |
|
], |
|
"videos": [ |
|
{"title": "Boosting Happiness", "url": "https://youtu.be/MIc299Flibs"}, |
|
{"title": "Celebrating Wins", "url": "https://www.youtube.com/shorts/fwH8Ygb0K60?feature=share"}, |
|
], |
|
}, |
|
"NEUTRAL": { |
|
"suggestions": ["Take a short break", "Engage in a relaxing activity", "Spend time outdoors"], |
|
"articles": [ |
|
{"title": "Self-Care Practices", "url": "https://www.nih.gov/health-information/emotional-wellness-toolkit"}, |
|
{"title": "Stress Management", "url": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"}, |
|
], |
|
"videos": [ |
|
{"title": "Relaxation Exercises", "url": "https://youtu.be/Y8HIFRPU6pM"}, |
|
{"title": "Mindfulness Tips", "url": "https://youtu.be/-e-4Kx5px_I"}, |
|
], |
|
}, |
|
} |
|
|
|
|
|
def get_relevant_resources(mood): |
|
resources = suggestion_database.get(mood, {}) |
|
return resources.get("suggestions", []), resources.get("articles", []), resources.get("videos", []) |
|
|
|
|
|
def suggest_activity(mood): |
|
suggestions, articles, videos = get_relevant_resources(mood) |
|
return { |
|
"suggestions": suggestions, |
|
"articles": articles, |
|
"videos": videos, |
|
} |
|
|
|
|
|
def main(): |
|
st.title("Mood Analysis and Suggestions") |
|
st.write("Answer the following 3 questions to help us understand your mood:") |
|
|
|
|
|
responses = [] |
|
for i, question in enumerate(questions): |
|
response = st.text_input(f"{i+1}. {question}") |
|
if response: |
|
responses.append(response) |
|
|
|
|
|
if len(responses) == len(questions): |
|
combined_text = " ".join(responses) |
|
analysis_result = emotion_analyzer(combined_text) |
|
detected_emotion = analysis_result[0]['label'] |
|
|
|
|
|
mood_mapping = { |
|
"LABEL_0": "NEGATIVE", |
|
"LABEL_1": "POSITIVE", |
|
"LABEL_2": "NEUTRAL", |
|
} |
|
|
|
|
|
mood = mood_mapping.get(detected_emotion, "NEUTRAL") |
|
|
|
st.write(f"Detected Mood: {mood}") |
|
|
|
|
|
resources = suggest_activity(mood) |
|
|
|
|
|
st.write("### Suggestions") |
|
for suggestion in resources["suggestions"]: |
|
st.write(f"- {suggestion}") |
|
|
|
|
|
st.write("### Articles") |
|
for article in resources["articles"]: |
|
st.write(f"- [{article['title']}]({article['url']})") |
|
|
|
|
|
st.write("### Videos") |
|
for video in resources["videos"]: |
|
st.write(f"- [{video['title']}]({video['url']})") |
|
else: |
|
st.write("Please answer all 3 questions to receive suggestions.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|