mavinsao commited on
Commit
4f0a2ca
·
verified ·
1 Parent(s): f817a5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -44
app.py CHANGED
@@ -68,14 +68,7 @@ def setup_chatbot_chain():
68
 
69
  chatbot_chain = setup_chatbot_chain()
70
 
71
- def respond(
72
- message,
73
- history,
74
- system_message,
75
- max_tokens,
76
- temperature,
77
- top_p,
78
- ):
79
  chat_history = "\n".join([f"Human: {h[0]}\nAI: {h[1]}" for h in history])
80
 
81
  response = chatbot_chain.run(
@@ -86,41 +79,44 @@ def respond(
86
 
87
  return response
88
 
89
- # Customize the ChatInterface
90
- demo = gr.ChatInterface(
91
- respond,
92
- additional_inputs=[
93
- gr.Textbox(
94
- value="You are an empathetic and supportive mental health chatbot. Provide warm, comforting responses and suggest coping strategies when appropriate. Always encourage seeking professional help for persistent issues.",
95
- label="System message"
96
- ),
97
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
98
- gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
99
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
100
- ],
101
- title="Mental Health Support Chatbot",
102
- description="I'm here to listen and provide support. How are you feeling today?",
103
- examples=[
104
- ["I've been feeling anxious lately"],
105
- ["I'm having trouble sleeping"],
106
- ["I feel overwhelmed with work"],
107
- ["I'm feeling sad and don't know why"]
108
- ],
109
- )
110
-
111
- # Add a disclaimer
112
- disclaimer = gr.Markdown(
113
- """
114
- **Disclaimer:** This chatbot is for informational purposes only and is not a substitute for professional medical advice,
115
- diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider
116
- with any questions you may have regarding a medical condition.
117
- """
118
- )
119
-
120
- # Combine the chat interface and disclaimer
121
- with gr.Blocks() as combined_interface:
122
- demo.render()
123
- disclaimer.render()
 
 
 
124
 
125
  if __name__ == "__main__":
126
- combined_interface.launch()
 
68
 
69
  chatbot_chain = setup_chatbot_chain()
70
 
71
+ def respond(message, history):
 
 
 
 
 
 
 
72
  chat_history = "\n".join([f"Human: {h[0]}\nAI: {h[1]}" for h in history])
73
 
74
  response = chatbot_chain.run(
 
79
 
80
  return response
81
 
82
+ with gr.Blocks() as demo:
83
+ gr.Markdown("# Mental Health Support Chatbot")
84
+ gr.Markdown("I'm here to listen and provide support. How are you feeling today?")
85
+
86
+ chatbot = gr.Chatbot()
87
+ msg = gr.Textbox()
88
+ clear = gr.Button("Clear")
89
+
90
+ def user(user_message, history):
91
+ return "", history + [[user_message, None]]
92
+
93
+ def bot(history):
94
+ bot_message = respond(history[-1][0], history[:-1])
95
+ history[-1][1] = bot_message
96
+ return history
97
+
98
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
99
+ bot, chatbot, chatbot
100
+ )
101
+ clear.click(lambda: None, None, chatbot, queue=False)
102
+
103
+ gr.Examples(
104
+ examples=[
105
+ "I've been feeling anxious lately",
106
+ "I'm having trouble sleeping",
107
+ "I feel overwhelmed with work",
108
+ "I'm feeling sad and don't know why"
109
+ ],
110
+ inputs=msg
111
+ )
112
+
113
+ gr.Markdown(
114
+ """
115
+ **Disclaimer:** This chatbot is for informational purposes only and is not a substitute for professional medical advice,
116
+ diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider
117
+ with any questions you may have regarding a medical condition.
118
+ """
119
+ )
120
 
121
  if __name__ == "__main__":
122
+ demo.launch()