Spaces:
Sleeping
Sleeping
| import random | |
| from textblob import TextBlob | |
| # Your response dictionaries | |
| responses = { | |
| "sadness": [...], | |
| "anger": [...], | |
| "love": [...], | |
| "happiness": [...], | |
| "neutral": [...] | |
| } | |
| relax_resources = { | |
| "exercise": "Try the 5-4-3-2-1 grounding method: ...", | |
| "video": "https://youtu.be/O-6f5wQXSu8" | |
| } | |
| help_kw = [...] | |
| neg_inputs = [...] | |
| thx_inputs = [...] | |
| bye_inputs = [...] | |
| awaiting = False | |
| def correct_spelling(text): | |
| return str(TextBlob(text).correct()) | |
| def get_response(emotion, user_input): | |
| global awaiting | |
| ui = user_input.lower() | |
| # 1) exit | |
| if any(b in ui for b in bye_inputs): return "Take care!", True | |
| # 2) thanks | |
| if any(t in ui for t in thx_inputs): return "You're welcome!", False | |
| # 3) tip flow | |
| if awaiting: | |
| # ...same logic... | |
| if any(k in ui for k in help_kw): | |
| awaiting = True | |
| return "Video or exercise?", False | |
| # 4) emotion reply | |
| return random.choice(responses.get(emotion, responses['neutral'])), False |