tarrasyed19472007's picture
Update app.py
2da24f4 verified
raw
history blame
4.06 kB
import streamlit as st
# Suggestion Database
suggestion_database = {
"sadness": {
"suggestions": ["Try a guided meditation", "Take a walk in nature", "Connect with a friend"],
"articles": [
{"title": "Overcoming Sadness", "url": "https://example.com/sadness1"},
{"title": "Understanding Depression", "url": "https://example.com/sadness2"},
],
"videos": [
{"title": "Mindfulness for Sadness", "url": "https://www.youtube.com/watch?v=sadnessvideo1"},
{"title": "Coping with Grief", "url": "https://www.youtube.com/watch?v=sadnessvideo2"},
],
},
"joy": {
"suggestions": ["Practice gratitude", "Engage in a hobby", "Spend time with loved ones"],
"articles": [
{"title": "The Benefits of Joy", "url": "https://example.com/joy1"},
{"title": "Maintaining Positive Emotions", "url": "https://example.com/joy2"},
],
"videos": [
{"title": "Boosting Your Happiness", "url": "https://www.youtube.com/watch?v=joyvideo1"},
{"title": "Practicing Gratitude", "url": "https://www.youtube.com/watch?v=joyvideo2"},
],
},
"neutral": {
"suggestions": ["Take a break", "Engage in a relaxing activity", "Spend time in nature"],
"articles": [
{"title": "Importance of Self-Care", "url": "https://example.com/selfcare1"},
{"title": "Stress Management Techniques", "url": "https://example.com/stress1"},
],
"videos": [
{"title": "Relaxation Techniques", "url": "https://www.youtube.com/watch?v=relaxvideo1"},
{"title": "Mindfulness Exercises", "url": "https://www.youtube.com/watch?v=mindfulnessvideo1"},
],
},
}
# Function to fetch resources
def get_relevant_resources(emotion):
resources = suggestion_database.get(emotion, {})
return resources.get("suggestions", []), resources.get("articles", []), resources.get("videos", [])
# Suggestion Logic
def suggest_activity(emotion_analysis):
max_emotion = max(emotion_analysis, key=emotion_analysis.get) if emotion_analysis else "neutral"
suggestions, articles, videos = get_relevant_resources(max_emotion)
return {
"emotion": max_emotion,
"suggestions": suggestions,
"articles": articles,
"videos": videos,
}
# Streamlit Interface
st.title("Personalized Emotional Wellness Recommendations")
# Questions
st.write("### How are you feeling today?")
emotion_input = st.text_input("Your response (e.g., happy, sad, neutral):", "").lower()
st.write("### Describe your mood in a few words.")
mood_input = st.text_input("Your response (e.g., calm, frustrated, joyful):", "").lower()
st.write("### What was the most significant emotion you felt this week?")
emotion_week_input = st.text_input("Your response (e.g., sadness, joy, anxiety):", "").lower()
# Simulated Emotion Analysis (Here, based on user input; replace with real analysis later)
emotion_analysis = {
"sadness": emotion_input == "sad" or emotion_week_input == "sadness",
"joy": emotion_input == "happy" or emotion_week_input == "joy",
"neutral": emotion_input == "neutral" or emotion_week_input == "calm",
}
# Analyze and Provide Suggestions
if st.button("Get Suggestions"):
analysis_results = {
"sadness": emotion_analysis.get("sadness", 0),
"joy": emotion_analysis.get("joy", 0),
"neutral": emotion_analysis.get("neutral", 0),
}
suggestions = suggest_activity(analysis_results)
st.write(f"### Detected Emotion: {suggestions['emotion'].capitalize()}")
st.write("### Suggestions for You:")
for suggestion in suggestions["suggestions"]:
st.write(f"- {suggestion}")
st.write("### Articles to Explore:")
for article in suggestions["articles"]:
st.markdown(f"[{article['title']}]({article['url']})")
st.write("### Videos to Watch:")
for video in suggestions["videos"]:
st.markdown(f"[{video['title']}]({video['url']})")