File size: 4,107 Bytes
4c0c8ad
bb770b6
 
 
b2b6d6f
18119f4
596e12a
92e98fb
4c0c8ad
92e98fb
 
 
 
 
4c0c8ad
 
92e98fb
 
 
 
 
 
 
 
 
1426741
18119f4
92e98fb
 
 
 
 
 
 
 
1426741
18119f4
92e98fb
 
 
4c0c8ad
1426741
 
92e98fb
 
 
 
 
 
 
 
1426741
92e98fb
 
 
 
 
1426741
18119f4
 
92e98fb
4c0c8ad
92e98fb
 
 
 
4c0c8ad
 
92e98fb
596e12a
92e98fb
 
 
18119f4
92e98fb
 
 
d1a4559
92e98fb
 
 
d1a4559
92e98fb
 
b2b6d6f
 
d1a4559
92e98fb
d1a4559
 
 
92e98fb
d1a4559
 
 
92e98fb
d1a4559
b2b6d6f
92e98fb
d1a4559
 
 
0900b9b
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
import random
import streamlit as st
from transformers import pipeline

# Emotion classifier (use a pre-trained model from Hugging Face)
emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased")

# Question Database
questions = [
    "How are you feeling right now?",
    "What’s something that’s been on your mind lately?",
    "Do you feel energized or tired at this moment?",
    "What’s the most significant event in your day so far?",
    "If you had to describe your mood in one word, what would it be?",
]

# Expanded Mood States
moods = [
    "Happy", "Excited", "Relaxed", "Grateful", "Calm",
    "Dull", "Neutral", "Tired", "Bored", "Lonely",
    "Angry", "Frustrated", "Anxious", "Stressed", "Overwhelmed",
    "Hopeful", "Confused", "Motivated", "Curious", "Peaceful"
]

# Suggestion Database
suggestion_database = {
    "POSITIVE": {
        "suggestions": ["Celebrate your success!", "Share your happiness with someone.", "Reflect on what makes you feel this way."],
        "articles": [{"title": "Staying Positive", "url": "https://example.com/positivity"}],
        "videos": [{"title": "Boosting Happiness", "url": "https://www.youtube.com/watch?v=happinessboost"}],
    },
    "NEGATIVE": {
        "suggestions": ["Take a break to relax.", "Talk to someone you trust.", "Try mindfulness exercises."],
        "articles": [{"title": "Managing Stress", "url": "https://example.com/stressmanagement"}],
        "videos": [{"title": "Dealing with Stress", "url": "https://www.youtube.com/watch?v=stressrelief"}],
    },
    "NEUTRAL": {
        "suggestions": ["Take a short walk.", "Plan your next task mindfully.", "Enjoy a calming activity like reading."],
        "articles": [{"title": "Finding Balance", "url": "https://example.com/balance"}],
        "videos": [{"title": "Relaxation Techniques", "url": "https://www.youtube.com/watch?v=relaxvideo"}],
    },
}

# Function to map moods to emotion categories
def map_mood_to_category(mood):
    if mood in ["Happy", "Excited", "Relaxed", "Grateful", "Calm", "Hopeful", "Motivated", "Curious", "Peaceful"]:
        return "POSITIVE"
    elif mood in ["Dull", "Neutral", "Tired", "Bored", "Lonely"]:
        return "NEUTRAL"
    else:  # Negative emotions
        return "NEGATIVE"

# Function to suggest activities based on the mood
def suggest_activity(mood):
    category = map_mood_to_category(mood)
    resources = suggestion_database.get(category, {})
    return resources

# Streamlit app
def main():
    st.title("Mood Analysis and Suggestions")
    
    # Step 1: Display the questions
    st.write("Answer the following 5 questions to help us understand your mood:")
    responses = []
    for i, question in enumerate(questions, start=1):
        response = st.text_input(f"{i}. {question}")
        if response:
            responses.append(response)
    
    # Step 2: Analyze responses if all questions are answered
    if len(responses) == len(questions):
        combined_text = " ".join(responses)
        
        # Analyze responses to determine mood
        analysis_result = emotion_analyzer(combined_text)
        detected_emotion = analysis_result[0]['label']
        
        # Map detected emotion to a mood state
        detected_mood = random.choice(moods)  # Mock mapping for demonstration
        st.write(f"Detected Mood: {detected_mood}")
        
        # Step 3: Fetch suggestions based on mood
        resources = suggest_activity(detected_mood)
        
        # Display suggestions, articles, and videos
        st.write("Suggestions:")
        for suggestion in resources.get("suggestions", []):
            st.write(f"- {suggestion}")
        
        st.write("Articles:")
        for article in resources.get("articles", []):
            st.write(f"- [{article['title']}]({article['url']})")
        
        st.write("Videos:")
        for video in resources.get("videos", []):
            st.write(f"- [{video['title']}]({video['url']})")
    else:
        st.write("Please answer all questions to receive suggestions.")

if __name__ == "__main__":
    main()