Bey007 commited on
Commit
629bb99
·
verified ·
1 Parent(s): 89b5988

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -23
app.py CHANGED
@@ -33,36 +33,39 @@ if 'previous_responses' not in st.session_state:
33
 
34
  # Function to generate a more empathetic and focused response
35
  def generate_response(user_input):
36
- # Predefined empathetic responses for cases of sadness and overwhelming stress
37
- empathy_responses = [
38
- "I'm truly sorry you're going through this difficult time. Grief and sadness can weigh heavy, but you're not alone in your feelings. It's important to remember that healing is a process, and it’s okay to take things one step at a time. I'm here to listen, and together we can explore ways to help you cope and find peace.",
39
- "I can only imagine how overwhelming things must feel right now. When we’re grieving or under stress, it can be hard to see the light at the end of the tunnel, but you don’t have to carry the burden alone. I’m here for you, and there are small steps we can take together to help you through this. Your feelings are valid, and it's okay to allow yourself time to process.",
40
- "I'm really sorry you're feeling this way. It's completely understandable to feel sad, and it's okay to let those emotions flow. Grief can be exhausting, and it’s normal to need time to process everything. Please remember, you're not in this alone. Take a moment to breathe, and when you're ready, we can explore some calming activities to help you through this tough time."
41
- ]
 
 
 
 
 
 
 
42
 
43
  # Tailored coping suggestions based on the user's input
44
  activity_suggestions = {
45
- "journaling": "Journaling is a powerful tool to express and understand your emotions. You could start by writing down everything you feel right now no matter how messy or jumbled. Just let the words flow. Sometimes, writing can bring clarity and a sense of relief, helping to untangle those complicated feelings inside.",
46
- "yoga": "Yoga can be a gentle way to calm your mind and body. Simple breathing exercises and stretches can help release tension and promote relaxation. Even just a few minutes of mindful breathing can make a big difference in how you feel.",
47
- "meditation": "Meditation is a great way to reconnect with your inner peace. By focusing on your breath, you can clear your mind and allow yourself to be present in the moment. It’s okay if your mind wanders – just gently guide it back to your breath. Over time, meditation can bring a sense of calm and emotional balance.",
48
- "exercise": "Physical activity is a wonderful way to release built-up tension and boost your mood. Taking a walk in nature or doing some light stretching can help ground you in the present moment. The movement helps not only your body but also your mind, making it easier to cope with difficult emotions.",
49
- "talking to someone": "Sometimes, the best way to relieve the weight of sadness is to talk to someone you trust. Reaching out to a friend or family member can provide you with emotional support. Just expressing your feelings aloud can be a huge relief and allow you to feel understood and supported.",
50
- "art": "Art can be a healing outlet for your emotions. Whether it’s drawing, painting, or even crafting, creating something with your hands allows you to express what might be too difficult to say in words. Try to let go of perfection and simply let your feelings guide your creativity.",
51
- "nature": "Spending time in nature can be incredibly therapeutic. Even a brief walk outside can help refresh your mind and bring clarity. Nature has a way of reminding us that life continues, even when we feel stuck. Try to spend a few minutes listening to the birds or feeling the breeze – it may bring a sense of calm."
52
  }
53
 
54
- # Empathetic response based on the input
55
- response = random.choice(empathy_responses)
56
-
57
- # Tailored activity suggestion based on user's input (e.g., grief, loss of a pet, etc.)
58
- if "cat" in user_input.lower() or "pet" in user_input.lower():
59
- activity = "art"
60
- activity_suggestion = "Creating art can help you express your feelings of loss. You might try drawing or painting something that reminds you of your pet. Art can offer a safe space to express grief when words feel too heavy."
61
- elif "overwhelmed" in user_input.lower() or "stressed" in user_input.lower():
62
- activity = "journaling"
63
- activity_suggestion = "Journaling can be a helpful way to process your thoughts and emotions. Writing down everything you’re feeling can allow you to see things more clearly and release some of the weight you’re carrying."
64
  else:
 
65
  activity = random.choice(list(activity_suggestions.keys()))
 
66
  activity_suggestion = activity_suggestions[activity]
67
 
68
  # Add the tailored coping activity suggestion to the response
 
33
 
34
  # Function to generate a more empathetic and focused response
35
  def generate_response(user_input):
36
+ # Empathy responses categorized by emotion
37
+ emotion_responses = {
38
+ "sadness": [
39
+ "I'm truly sorry you're going through this difficult time. Grief and sadness can weigh heavy, but you're not alone in your feelings. It's okay to take things one step at a time, and together we can explore ways to help you cope and find peace.",
40
+ "I can only imagine how overwhelming things must feel right now. When we’re grieving or under stress, it can be hard to see the light at the end of the tunnel, but you don’t have to carry the burden alone. I’m here for you.",
41
+ "I'm really sorry you're feeling this way. It’s completely understandable to feel sad, and it's okay to let those emotions flow. Grief can be exhausting, and it’s normal to need time to process everything."
42
+ ],
43
+ "anger": [
44
+ "It sounds like you're feeling really frustrated, and that’s totally valid. Sometimes, our anger is a way of protecting us from pain or stress. If you’d like, I’m here to help you work through these feelings and find ways to release some of that tension.",
45
+ "I understand that things may feel frustrating and intense right now. Anger can be a difficult emotion to manage, but it’s completely natural. Sometimes, taking a step back and focusing on deep breathing or a calming activity can help.",
46
+ "It’s okay to feel angry – sometimes it’s our body’s way of telling us that something needs to change or that we need to release pent-up stress. You’re not alone in this, and there are healthy ways we can work through it together."
47
+ ]
48
+ }
49
 
50
  # Tailored coping suggestions based on the user's input
51
  activity_suggestions = {
52
+ "journaling": "Journaling can be a helpful way to process your thoughts and emotions. Writing down everything you’re feeling can allow you to see things more clearly and release some of the weight you’re carrying.",
53
+ "deep breathing": "Deep breathing can help calm your mind and ease tension. Try taking a few slow, deep breaths, focusing on each inhale and exhale. It can help you feel grounded and in control of your emotions.",
54
+ "exercise": "Physical activity is a wonderful way to release built-up tension and boost your mood. Taking a walk in nature or doing some light stretching can help ground you in the present moment and relieve stress.",
55
+ "talking to someone": "Sometimes, sharing how you’re feeling with someone you trust can relieve some of the burden. Talking through your emotions with a friend or loved one can provide comfort and help you feel supported.",
56
+ "art": "Art can be a therapeutic outlet for your emotions. Creating something with your hands, like drawing or painting, allows you to express what might be too difficult to put into words."
 
 
57
  }
58
 
59
+ # Determine emotion based on keywords in user input
60
+ if "angry" in user_input.lower() or "frustrated" in user_input.lower():
61
+ emotion = "anger"
62
+ activity = "deep breathing"
63
+ response = random.choice(emotion_responses[emotion])
64
+ activity_suggestion = activity_suggestions[activity]
 
 
 
 
65
  else:
66
+ emotion = "sadness"
67
  activity = random.choice(list(activity_suggestions.keys()))
68
+ response = random.choice(emotion_responses[emotion])
69
  activity_suggestion = activity_suggestions[activity]
70
 
71
  # Add the tailored coping activity suggestion to the response