Spaces:
Sleeping
Sleeping
Update src/responses.py
Browse files- src/responses.py +61 -9
src/responses.py
CHANGED
|
@@ -1,14 +1,66 @@
|
|
| 1 |
import random
|
| 2 |
|
| 3 |
-
#
|
| 4 |
responses = {
|
| 5 |
-
"
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
}
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import random
|
| 2 |
|
| 3 |
+
# Copied directly from your script’s dictionaries
|
| 4 |
responses = {
|
| 5 |
+
"sadness": [
|
| 6 |
+
"It’s okay to feel down sometimes. I’m here to support you.",
|
| 7 |
+
"I'm really sorry you're going through this. Want to talk more about it?",
|
| 8 |
+
"You're not alone — I’m here for you."
|
| 9 |
+
],
|
| 10 |
+
"anger": [
|
| 11 |
+
"That must have been frustrating. Want to vent about it?",
|
| 12 |
+
"It's okay to feel this way. I'm listening.",
|
| 13 |
+
"Would it help to talk through it?"
|
| 14 |
+
],
|
| 15 |
+
"love": [
|
| 16 |
+
"That’s beautiful to hear! What made you feel that way?",
|
| 17 |
+
"It’s amazing to experience moments like that.",
|
| 18 |
+
"Sounds like something truly meaningful."
|
| 19 |
+
],
|
| 20 |
+
"happiness": [
|
| 21 |
+
"That's awesome! What’s bringing you joy today?",
|
| 22 |
+
"I love hearing good news. 😊",
|
| 23 |
+
"Yay! Want to share more about it?"
|
| 24 |
+
],
|
| 25 |
+
"neutral": [
|
| 26 |
+
"Got it. I’m here if you want to dive deeper.",
|
| 27 |
+
"Thanks for sharing that. Tell me more if you’d like.",
|
| 28 |
+
"I’m listening. How else can I support you?"
|
| 29 |
+
]
|
| 30 |
}
|
| 31 |
|
| 32 |
+
# Tip & goodbye logic copied from your script
|
| 33 |
+
relaxation_resources = {
|
| 34 |
+
"exercise": "Try this 5-4-3-2-1 grounding method: ...",
|
| 35 |
+
"video": "Short calming video: https://youtu.be/O-6f5wQXSu8"
|
| 36 |
+
}
|
| 37 |
+
help_keywords = ["suggest","help","calm","exercise","relax","any tips","can you"]
|
| 38 |
+
negative_inputs = ["not good","feel bad","feel sad","anxious","depressed","upset","stress","worried"]
|
| 39 |
+
thank_you_inputs = ["thank","thanks","thank you"]
|
| 40 |
+
bye_inputs = ["bye","goodbye","exit","quit"]
|
| 41 |
+
|
| 42 |
+
awaiting_tip_type = False
|
| 43 |
+
|
| 44 |
+
def get_response(emotion, user_input):
|
| 45 |
+
global awaiting_tip_type
|
| 46 |
+
ui = user_input.lower()
|
| 47 |
+
# 1) Exit
|
| 48 |
+
if any(b in ui for b in bye_inputs):
|
| 49 |
+
return "Take care! I’m here whenever you want to talk. 🌿", True
|
| 50 |
+
# 2) Thanks
|
| 51 |
+
if any(t in ui for t in thank_you_inputs):
|
| 52 |
+
return "You're most welcome! 💙", False
|
| 53 |
+
# 3) Tip request
|
| 54 |
+
if awaiting_tip_type:
|
| 55 |
+
if "video" in ui:
|
| 56 |
+
awaiting_tip_type = False
|
| 57 |
+
return relaxation_resources["video"], False
|
| 58 |
+
if "exercise" in ui:
|
| 59 |
+
awaiting_tip_type = False
|
| 60 |
+
return relaxation_resources["exercise"], False
|
| 61 |
+
return "Would you prefer a short video or a simple exercise?", False
|
| 62 |
+
if any(k in ui for k in help_keywords):
|
| 63 |
+
awaiting_tip_type = True
|
| 64 |
+
return "Prefer a brief video or an exercise?", False
|
| 65 |
+
# 4) Emotion-based reply
|
| 66 |
+
return random.choice(responses.get(emotion, responses["neutral"])), False
|