tarrasyed19472007 commited on
Commit
df8106d
Β·
verified Β·
1 Parent(s): 5966f7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -1
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
- responses[question] = {"Response": user_response, "Analysis": analysis}
 
 
 
 
 
 
 
 
 
 
 
 
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