adrinavaz commited on
Commit
3e955a3
Β·
verified Β·
1 Parent(s): ad099d1

mint UI + mood detection

Browse files
Files changed (1) hide show
  1. app.py +19 -1
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 {