mianoemm commited on
Commit
2663344
·
verified ·
1 Parent(s): d7144ea

mindmatters

Browse files
Files changed (1) hide show
  1. app.py +10 -48
app.py CHANGED
@@ -1,62 +1,24 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Replace with your chosen model
5
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
6
 
7
- SYSTEM_PROMPT = """
8
- You are MindMate, a compassionate mental health support chatbot.
9
-
10
- Your role is to:
11
- - Listen empathetically and respectfully.
12
- - Help users explore their feelings and thoughts.
13
- - Suggest healthy coping strategies and self-care techniques.
14
- - Encourage seeking support from trusted friends, family, counselors, therapists, or healthcare professionals when appropriate.
15
- - Never diagnose medical or mental health conditions.
16
- - Never claim to be a licensed therapist or psychologist.
17
- - Avoid judgmental language.
18
- - Be supportive, calm, and encouraging.
19
-
20
- If a user expresses thoughts of self-harm, suicide, or harming others:
21
- - Encourage them to contact emergency services or a crisis hotline immediately.
22
- - Encourage them to reach out to a trusted person nearby.
23
- - Respond with urgency, compassion, and care.
24
- """
25
-
26
  def respond(message, history):
27
- messages = [
28
- {"role": "system", "content": SYSTEM_PROMPT}
29
- ]
30
-
31
- # Add previous conversation
32
  if history:
33
- for user_msg, bot_msg in history:
34
- messages.append({"role": "user", "content": user_msg})
35
- messages.append({"role": "assistant", "content": bot_msg})
36
-
37
  messages.append({"role": "user", "content": message})
38
-
39
  response = client.chat_completion(
40
- messages=messages,
41
- max_tokens=300,
42
- temperature=0.7
43
  )
44
-
45
  return response.choices[0].message.content.strip()
46
 
47
- description = """
48
- # 🧠 MindMate
49
-
50
- A supportive mental health chatbot designed to provide emotional support and coping suggestions.
51
-
52
- ⚠️ **Disclaimer:** This chatbot is not a substitute for professional mental health care, diagnosis, or treatment. If you are experiencing a crisis or are in immediate danger, contact emergency services or a crisis hotline in your area.
53
- """
54
-
55
- chatbot = gr.ChatInterface(
56
- fn=respond,
57
- title="🧠 MindMate",
58
- description=description,
59
- chatbot=gr.Chatbot(height=500)
60
- )
61
 
62
  chatbot.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  def respond(message, history):
7
+
8
+ messages = [{"role": "system", "content": "You are a friendly chatbot."}]
9
+
 
 
10
  if history:
11
+ messages.extend(history)
12
+
 
 
13
  messages.append({"role": "user", "content": message})
14
+
15
  response = client.chat_completion(
16
+ messages,
17
+ max_tokens=100
 
18
  )
19
+
20
  return response.choices[0].message.content.strip()
21
 
22
+ chatbot = gr.ChatInterface(respond)
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  chatbot.launch()