Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,6 +48,20 @@ def predict_emotion(text):
|
|
48 |
st.error(f"β οΈ Prediction failed: {e}")
|
49 |
return {"Error": f"Prediction failed: {e}"}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# ---- User Input Section ----
|
52 |
st.write("### πΊ Let's Get Started!")
|
53 |
questions = [
|
@@ -68,8 +82,21 @@ for i, question in enumerate(questions, start=1):
|
|
68 |
if user_response:
|
69 |
with st.spinner("Analyzing emotion... π"):
|
70 |
analysis = predict_emotion(user_response)
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
st.success(f"π― Emotion Analysis: {analysis}")
|
|
|
73 |
|
74 |
# ---- Display Results ----
|
75 |
if st.button("Submit Responses"):
|
@@ -79,6 +106,7 @@ if st.button("Submit Responses"):
|
|
79 |
st.write(f"#### Question {i}: {question}")
|
80 |
st.write(f"**Your Response:** {details['Response']}")
|
81 |
st.write(f"**Emotion Analysis:** {details['Analysis']}")
|
|
|
82 |
else:
|
83 |
st.warning("Please answer at least one question before submitting!")
|
84 |
|
|
|
48 |
st.error(f"β οΈ Prediction failed: {e}")
|
49 |
return {"Error": f"Prediction failed: {e}"}
|
50 |
|
51 |
+
# ---- Remedy Suggestions Based on Emotions ----
|
52 |
+
def get_remedy_suggestion(emotion):
|
53 |
+
"""Suggest activities based on detected emotion."""
|
54 |
+
remedies = {
|
55 |
+
"anger": "π§ββοΈ Try doing a breathing exercise or meditate for a few minutes to calm down.",
|
56 |
+
"fear": "π£ Go for a walk to clear your mind and release tension. Try mindfulness during your walk.",
|
57 |
+
"joy": "π You're feeling great! Keep up the positive energy and spread it to others around you.",
|
58 |
+
"sadness": "π‘ Practice mindfulness or take a short walk outside to refresh your mind.",
|
59 |
+
"surprise": "π€ Take a deep breath and reflect for a moment. Meditation can help bring focus.",
|
60 |
+
"disgust": "π¬οΈ Try a breathing exercise to help ease your thoughts and relax.",
|
61 |
+
"neutral": "πββοΈ Mindfulness practice could help in centering yourself and finding balance.",
|
62 |
+
}
|
63 |
+
return remedies.get(emotion, "πββοΈ Try practicing mindfulness to help center yourself.")
|
64 |
+
|
65 |
# ---- User Input Section ----
|
66 |
st.write("### πΊ Let's Get Started!")
|
67 |
questions = [
|
|
|
82 |
if user_response:
|
83 |
with st.spinner("Analyzing emotion... π"):
|
84 |
analysis = predict_emotion(user_response)
|
85 |
+
|
86 |
+
# Identify the dominant emotion from the analysis result
|
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 |
+
st.write(f"π§ββοΈ Suggested Activity: {remedy_suggestion}")
|
100 |
|
101 |
# ---- Display Results ----
|
102 |
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 |
+
st.write(f"**Suggested Remedy:** {details['Suggested Remedy']}")
|
110 |
else:
|
111 |
st.warning("Please answer at least one question before submitting!")
|
112 |
|