Bndo commited on
Commit
9e08ce6
Β·
verified Β·
1 Parent(s): 112bd19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -4,7 +4,7 @@ from huggingface_hub import InferenceClient
4
  # βœ… Connect to Hugging Face Zephyr-7B API
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
- # βœ… Mental health-specific system message
8
  MENTAL_HEALTH_PROMPT = (
9
  "You are Bandar AI, an empathetic mental health AI assistant. "
10
  "You provide emotional support, self-care advice, and stress management tips. "
@@ -17,7 +17,8 @@ def is_mental_health_related(message):
17
  keywords = [
18
  "anxious", "stress", "depressed", "lonely", "overwhelmed",
19
  "panic", "mental health", "self-care", "therapy", "sad", "burnout",
20
- "emotions", "counseling", "support", "well-being"
 
21
  ]
22
  return any(word in message.lower() for word in keywords)
23
 
@@ -30,9 +31,10 @@ def respond(
30
  temperature,
31
  top_p,
32
  ):
33
- # πŸ”΄ Reject unrelated topics
34
  if not is_mental_health_related(message):
35
- return "❌ Sorry, I can only discuss mental health topics. Please ask about emotions, self-care, or stress management."
 
36
 
37
  messages = [{"role": "system", "content": system_message}]
38
 
@@ -58,7 +60,7 @@ def respond(
58
  ):
59
  token = message.choices[0].delta.content
60
  response += token
61
- yield response # Stream output in real-time
62
 
63
  # βœ… Improved Chatbot UI for Mental Health
64
  demo = gr.ChatInterface(
 
4
  # βœ… Connect to Hugging Face Zephyr-7B API
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
+ # βœ… Define the system message for a mental health chatbot
8
  MENTAL_HEALTH_PROMPT = (
9
  "You are Bandar AI, an empathetic mental health AI assistant. "
10
  "You provide emotional support, self-care advice, and stress management tips. "
 
17
  keywords = [
18
  "anxious", "stress", "depressed", "lonely", "overwhelmed",
19
  "panic", "mental health", "self-care", "therapy", "sad", "burnout",
20
+ "emotions", "counseling", "support", "well-being", "anxiety",
21
+ "depression", "happiness", "relaxation", "coping", "mindfulness"
22
  ]
23
  return any(word in message.lower() for word in keywords)
24
 
 
31
  temperature,
32
  top_p,
33
  ):
34
+ # πŸ”΄ Reject unrelated topics with a streaming response
35
  if not is_mental_health_related(message):
36
+ yield "❌ Sorry, I can only discuss mental health topics. Please ask about emotions, self-care, or stress management."
37
+ return
38
 
39
  messages = [{"role": "system", "content": system_message}]
40
 
 
60
  ):
61
  token = message.choices[0].delta.content
62
  response += token
63
+ yield response # βœ… Stream output correctly
64
 
65
  # βœ… Improved Chatbot UI for Mental Health
66
  demo = gr.ChatInterface(