Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,59 +74,4 @@ def map_mood_to_category(mood):
|
|
| 74 |
return "POSITIVE"
|
| 75 |
elif mood in ["Dull", "Neutral", "Tired", "Bored", "Lonely"]:
|
| 76 |
return "NEUTRAL"
|
| 77 |
-
elif mood in ["Angry", "Frustrated", "Anxious",
|
| 78 |
-
return "NEGATIVE"
|
| 79 |
-
else:
|
| 80 |
-
return "STRESSED"
|
| 81 |
-
|
| 82 |
-
# Function to suggest activities based on the mood
|
| 83 |
-
def suggest_activity(mood):
|
| 84 |
-
category = map_mood_to_category(mood)
|
| 85 |
-
resources = suggestion_database.get(category, {})
|
| 86 |
-
return resources
|
| 87 |
-
|
| 88 |
-
# Streamlit app
|
| 89 |
-
def main():
|
| 90 |
-
st.title("Mood Analysis and Suggestions")
|
| 91 |
-
|
| 92 |
-
# Step 1: Display the questions
|
| 93 |
-
st.write("Answer the following 3 questions to help us understand your mood:")
|
| 94 |
-
responses = []
|
| 95 |
-
for i, question in enumerate(questions, start=1):
|
| 96 |
-
response = st.text_input(f"{i}. {question}")
|
| 97 |
-
if response:
|
| 98 |
-
responses.append(response)
|
| 99 |
-
|
| 100 |
-
# Step 2: Analyze responses if all questions are answered
|
| 101 |
-
if len(responses) == len(questions):
|
| 102 |
-
combined_text = " ".join(responses)
|
| 103 |
-
|
| 104 |
-
# Analyze responses to determine mood
|
| 105 |
-
analysis_result = emotion_analyzer(combined_text)
|
| 106 |
-
detected_emotion = analysis_result[0]['label']
|
| 107 |
-
|
| 108 |
-
# Map detected emotion to a mood state
|
| 109 |
-
detected_mood = random.choice(moods) # Mock mapping for demonstration
|
| 110 |
-
st.write(f"Detected Mood: {detected_mood}")
|
| 111 |
-
|
| 112 |
-
# Step 3: Fetch suggestions based on mood
|
| 113 |
-
resources = suggest_activity(detected_mood)
|
| 114 |
-
|
| 115 |
-
# Display suggestions, articles, and videos
|
| 116 |
-
st.write("Suggestions:")
|
| 117 |
-
for suggestion in resources.get("suggestions", []):
|
| 118 |
-
st.write(f"- {suggestion}")
|
| 119 |
-
|
| 120 |
-
st.write("Articles:")
|
| 121 |
-
for article in resources.get("articles", []):
|
| 122 |
-
st.write(f"- [{article['title']}]({article['url']})")
|
| 123 |
-
|
| 124 |
-
st.write("Videos:")
|
| 125 |
-
for video in resources.get("videos", []):
|
| 126 |
-
st.write(f"- [{video['title']}]({video['url']})")
|
| 127 |
-
else:
|
| 128 |
-
st.write("Please answer all questions to receive suggestions.")
|
| 129 |
-
|
| 130 |
-
if __name__ == "__main__":
|
| 131 |
-
main()
|
| 132 |
-
|
|
|
|
| 74 |
return "POSITIVE"
|
| 75 |
elif mood in ["Dull", "Neutral", "Tired", "Bored", "Lonely"]:
|
| 76 |
return "NEUTRAL"
|
| 77 |
+
elif mood in ["Angry", "Frustrated", "Anxious",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|