Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
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
|
39 |
-
"I
|
40 |
-
"It
|
41 |
]
|
42 |
|
43 |
# Tailored coping suggestions based on the user's input
|
44 |
activity_suggestions = {
|
45 |
-
"journaling": "Journaling is a
|
46 |
-
"yoga": "Yoga can
|
47 |
-
"meditation": "
|
48 |
-
"exercise": "Physical activity
|
|
|
|
|
|
|
49 |
}
|
50 |
|
51 |
-
#
|
52 |
response = random.choice(empathy_responses)
|
53 |
|
54 |
-
#
|
55 |
-
if "
|
|
|
|
|
|
|
56 |
activity = "journaling"
|
57 |
-
|
58 |
-
activity = "yoga"
|
59 |
else:
|
60 |
activity = random.choice(list(activity_suggestions.keys()))
|
|
|
61 |
|
62 |
-
# Add
|
63 |
-
response += f"\n\nHere's something you could try to help cope with how you're feeling:\n{
|
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. 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
|
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 |
|