Spaces:
Sleeping
Sleeping
mint UI + mood detection
Browse files
app.py
CHANGED
|
@@ -65,11 +65,29 @@ mental_health_keywords = [ # we implement a list of keywords to ensure chatbot o
|
|
| 65 |
"focus", "concentrate", "concentration"
|
| 66 |
]
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
def respond(message, history):
|
| 69 |
|
| 70 |
if not any(word in message.lower() for word in mental_health_keywords):
|
| 71 |
return "I'm mainly here to support teen mental wellness. Try asking me about stress, anxiety, school pressure, friendships, emotions, sleep, or coping strategies."
|
| 72 |
|
|
|
|
|
|
|
| 73 |
relevant_chunk = get_top_chunk(message)
|
| 74 |
print("Retrieved chunk:", relevant_chunk) # we are using this line to test RAG system (the terminal will show what knowledge chunk chatbot used)
|
| 75 |
|
|
@@ -107,7 +125,7 @@ User question:
|
|
| 107 |
max_tokens=400 # allow longer responses
|
| 108 |
)
|
| 109 |
|
| 110 |
-
return response.choices[0].message.content.strip()
|
| 111 |
|
| 112 |
custom_css = """
|
| 113 |
body {
|
|
|
|
| 65 |
"focus", "concentrate", "concentration"
|
| 66 |
]
|
| 67 |
|
| 68 |
+
def detect_mood(message):
|
| 69 |
+
text = message.lower()
|
| 70 |
+
|
| 71 |
+
if any(word in text for word in ["stress", "stressed", "overwhelmed", "burnout", "pressure", "finals", "exam"]):
|
| 72 |
+
return "π Stressed / Overwhelmed"
|
| 73 |
+
elif any(word in text for word in ["anxiety", "anxious", "panic", "worried", "worry", "nervous", "fear", "scared"]):
|
| 74 |
+
return "π° Anxious"
|
| 75 |
+
elif any(word in text for word in ["sad", "lonely", "depressed", "crying", "numb", "hopeless", "down", "upset"]):
|
| 76 |
+
return "π’ Sad / Low"
|
| 77 |
+
elif any(word in text for word in ["angry", "anger", "mad", "frustrated", "annoyed", "irritated"]):
|
| 78 |
+
return "π Angry / Frustrated"
|
| 79 |
+
elif any(word in text for word in ["happy", "excited", "proud", "grateful", "confident"]):
|
| 80 |
+
return "π Positive"
|
| 81 |
+
else:
|
| 82 |
+
return "π General Support"
|
| 83 |
+
|
| 84 |
def respond(message, history):
|
| 85 |
|
| 86 |
if not any(word in message.lower() for word in mental_health_keywords):
|
| 87 |
return "I'm mainly here to support teen mental wellness. Try asking me about stress, anxiety, school pressure, friendships, emotions, sleep, or coping strategies."
|
| 88 |
|
| 89 |
+
mood = detect_mood(message)
|
| 90 |
+
|
| 91 |
relevant_chunk = get_top_chunk(message)
|
| 92 |
print("Retrieved chunk:", relevant_chunk) # we are using this line to test RAG system (the terminal will show what knowledge chunk chatbot used)
|
| 93 |
|
|
|
|
| 125 |
max_tokens=400 # allow longer responses
|
| 126 |
)
|
| 127 |
|
| 128 |
+
return f"Detected Mood: {mood}\n\n" + response.choices[0].message.content.strip()
|
| 129 |
|
| 130 |
custom_css = """
|
| 131 |
body {
|