Update app.py
Browse files
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 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
)
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
124 |
|
125 |
if __name__ == "__main__":
|
126 |
-
|
|
|
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()
|