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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from transformers import pipeline, GPT2LMHeadModel, GPT2Tokenizer
3
  from gtts import gTTS
4
  import random
5
 
@@ -35,32 +35,38 @@ if 'previous_responses' not in st.session_state:
35
  def generate_response(user_input):
36
  # Predefined empathetic responses for cases of sadness and overwhelming stress
37
  empathy_responses = [
38
- "I'm really sorry you're going through this. Its okay to feel this way, and Im here to help you process it.",
39
- "I understand how overwhelming things can feel right now. You're not alone. Its important to take things one step at a time.",
40
- "It sounds really tough, but reaching out is a big first step. You’re doing great. Take a deep breath. You're not alone in this."
41
  ]
42
 
43
  # Tailored coping suggestions based on the user's input
44
  activity_suggestions = {
45
- "journaling": "Journaling is a great way to process your emotions. Write down whatever comes to mind to help release the feelings you're carrying.",
46
- "yoga": "Yoga can help you relax and find calm. Simple breathing exercises or gentle stretches might ease the tension you're feeling.",
47
- "meditation": "Mindful meditation can help you center yourself and reduce stress. Even a few minutes can make a big difference.",
48
- "exercise": "Physical activity can lift your mood and clear your mind. A short walk or some light exercise could help you feel better."
 
 
 
49
  }
50
 
51
- # Pick a relevant empathetic response
52
  response = random.choice(empathy_responses)
53
 
54
- # Based on keywords in the input, provide a relevant activity suggestion
55
- if "exam" in user_input.lower() or "study" in user_input.lower():
 
 
 
56
  activity = "journaling"
57
- elif "stress" in user_input.lower() or "overwhelmed" in user_input.lower():
58
- activity = "yoga"
59
  else:
60
  activity = random.choice(list(activity_suggestions.keys()))
 
61
 
62
- # Add a coping activity suggestion to the response
63
- response += f"\n\nHere's something you could try to help cope with how you're feeling:\n{activity_suggestions[activity]}"
64
 
65
  return response
66
 
 
1
  import streamlit as st
2
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
  from gtts import gTTS
4
  import random
5
 
 
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. Im 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 its 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
69
+ response += f"\n\nHere's something you could try to help cope with how you're feeling:\n{activity_suggestion}"
70
 
71
  return response
72