Update app.py
Browse files
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 |
-
# β
|
| 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 |
-
|
|
|
|
| 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
|
| 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(
|