Spaces:
Sleeping
Sleeping
Update src/responses.py
Browse files- src/responses.py +30 -57
src/responses.py
CHANGED
|
@@ -1,66 +1,39 @@
|
|
| 1 |
import random
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
responses = {
|
| 5 |
-
"sadness": [
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 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 |
-
|
| 33 |
-
|
| 34 |
-
"exercise": "Try this 5-4-3-2-1 grounding method: ...",
|
| 35 |
-
"video": "Short calming video: https://youtu.be/O-6f5wQXSu8"
|
| 36 |
}
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
bye_inputs
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
def get_response(emotion, user_input):
|
| 45 |
-
global
|
| 46 |
ui = user_input.lower()
|
| 47 |
-
# 1)
|
| 48 |
-
if any(b in ui for b in bye_inputs):
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
if
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 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
|
|
|
|
| 1 |
import random
|
| 2 |
+
from textblob import TextBlob
|
| 3 |
|
| 4 |
+
# Your response dictionaries
|
| 5 |
responses = {
|
| 6 |
+
"sadness": [...],
|
| 7 |
+
"anger": [...],
|
| 8 |
+
"love": [...],
|
| 9 |
+
"happiness": [...],
|
| 10 |
+
"neutral": [...]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
}
|
| 12 |
+
relax_resources = {
|
| 13 |
+
"exercise": "Try the 5-4-3-2-1 grounding method: ...",
|
| 14 |
+
"video": "https://youtu.be/O-6f5wQXSu8"
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
+
help_kw = [...]
|
| 17 |
+
neg_inputs = [...]
|
| 18 |
+
thx_inputs = [...]
|
| 19 |
+
bye_inputs = [...]
|
| 20 |
+
awaiting = False
|
| 21 |
|
| 22 |
+
def correct_spelling(text):
|
| 23 |
+
return str(TextBlob(text).correct())
|
| 24 |
|
| 25 |
def get_response(emotion, user_input):
|
| 26 |
+
global awaiting
|
| 27 |
ui = user_input.lower()
|
| 28 |
+
# 1) exit
|
| 29 |
+
if any(b in ui for b in bye_inputs): return "Take care!", True
|
| 30 |
+
# 2) thanks
|
| 31 |
+
if any(t in ui for t in thx_inputs): return "You're welcome!", False
|
| 32 |
+
# 3) tip flow
|
| 33 |
+
if awaiting:
|
| 34 |
+
# ...same logic...
|
| 35 |
+
if any(k in ui for k in help_kw):
|
| 36 |
+
awaiting = True
|
| 37 |
+
return "Video or exercise?", False
|
| 38 |
+
# 4) emotion reply
|
| 39 |
+
return random.choice(responses.get(emotion, responses['neutral'])), False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|