Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,19 +48,26 @@ def predict_emotion(text):
|
|
48 |
st.error(f"⚠️ Prediction failed: {e}")
|
49 |
return {"Error": f"Prediction failed: {e}"}
|
50 |
|
51 |
-
# ----
|
52 |
-
def
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# ---- User Input Section ----
|
66 |
st.write("### 🌺 Let's Get Started!")
|
@@ -82,21 +89,16 @@ for i, question in enumerate(questions, start=1):
|
|
82 |
if user_response:
|
83 |
with st.spinner("Analyzing emotion... 🎭"):
|
84 |
analysis = predict_emotion(user_response)
|
|
|
85 |
|
86 |
-
#
|
87 |
-
dominant_emotion = max(analysis, key=analysis.get) if analysis else "neutral"
|
88 |
-
|
89 |
-
# Get a remedy suggestion based on the dominant emotion
|
90 |
-
remedy_suggestion = get_remedy_suggestion(dominant_emotion)
|
91 |
-
|
92 |
-
responses[question] = {
|
93 |
-
"Response": user_response,
|
94 |
-
"Analysis": analysis,
|
95 |
-
"Suggested Remedy": remedy_suggestion,
|
96 |
-
}
|
97 |
-
|
98 |
st.success(f"🎯 Emotion Analysis: {analysis}")
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
# ---- Display Results ----
|
102 |
if st.button("Submit Responses"):
|
@@ -106,7 +108,8 @@ if st.button("Submit Responses"):
|
|
106 |
st.write(f"#### Question {i}: {question}")
|
107 |
st.write(f"**Your Response:** {details['Response']}")
|
108 |
st.write(f"**Emotion Analysis:** {details['Analysis']}")
|
109 |
-
|
|
|
110 |
else:
|
111 |
st.warning("Please answer at least one question before submitting!")
|
112 |
|
|
|
48 |
st.error(f"⚠️ Prediction failed: {e}")
|
49 |
return {"Error": f"Prediction failed: {e}"}
|
50 |
|
51 |
+
# ---- Suggesting Activities Based on Emotional State ----
|
52 |
+
def suggest_activity(emotion_analysis):
|
53 |
+
# Suggest activities based on emotional state
|
54 |
+
max_emotion = max(emotion_analysis, key=emotion_analysis.get) if emotion_analysis else None
|
55 |
+
if max_emotion == 'sadness':
|
56 |
+
return "It's okay to feel sad sometimes. Try taking a 5-minute mindfulness break or a short walk outside to clear your mind."
|
57 |
+
elif max_emotion == 'joy':
|
58 |
+
return "You’re feeling happy! Keep that positive energy going. How about practicing some deep breathing exercises to maintain your balance?"
|
59 |
+
elif max_emotion == 'fear':
|
60 |
+
return "Feeling anxious? It might help to do a quick breathing exercise or take a walk to ease your mind."
|
61 |
+
elif max_emotion == 'anger':
|
62 |
+
return "It seems like you're angry. Try taking a few deep breaths, or engage in a relaxing mindfulness exercise to calm your nerves."
|
63 |
+
elif max_emotion == 'surprise':
|
64 |
+
return "You’re surprised! Take a moment to breathe deeply and reflect. A walk might help clear your thoughts."
|
65 |
+
elif max_emotion == 'disgust':
|
66 |
+
return "If you’re feeling disgusted, a change of environment might help. Go for a walk or try a mindfulness technique to relax."
|
67 |
+
elif max_emotion == 'sadness':
|
68 |
+
return "It’s okay to feel sad. Try grounding yourself with some mindfulness or a breathing exercise."
|
69 |
+
else:
|
70 |
+
return "Keep doing great! If you feel overwhelmed, consider taking a deep breath or going for a short walk."
|
71 |
|
72 |
# ---- User Input Section ----
|
73 |
st.write("### 🌺 Let's Get Started!")
|
|
|
89 |
if user_response:
|
90 |
with st.spinner("Analyzing emotion... 🎭"):
|
91 |
analysis = predict_emotion(user_response)
|
92 |
+
responses[question] = {"Response": user_response, "Analysis": analysis}
|
93 |
|
94 |
+
# Display Emotion Analysis
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
st.success(f"🎯 Emotion Analysis: {analysis}")
|
96 |
+
|
97 |
+
# Display Activity Suggestion
|
98 |
+
if analysis:
|
99 |
+
max_emotion = max(analysis, key=analysis.get)
|
100 |
+
activity_suggestion = suggest_activity(analysis)
|
101 |
+
st.write(f"### 🧘 Suggested Activity: {activity_suggestion}")
|
102 |
|
103 |
# ---- Display Results ----
|
104 |
if st.button("Submit Responses"):
|
|
|
108 |
st.write(f"#### Question {i}: {question}")
|
109 |
st.write(f"**Your Response:** {details['Response']}")
|
110 |
st.write(f"**Emotion Analysis:** {details['Analysis']}")
|
111 |
+
activity_suggestion = suggest_activity(details["Analysis"])
|
112 |
+
st.write(f"**Suggested Activity:** {activity_suggestion}")
|
113 |
else:
|
114 |
st.warning("Please answer at least one question before submitting!")
|
115 |
|