Update app.py
Browse files
app.py
CHANGED
@@ -43,21 +43,27 @@ Mental Health Crisis Intervention Strategies:
|
|
43 |
{mental_health_info}
|
44 |
|
45 |
When responding to users:
|
46 |
-
1. Assess the severity of the situation using the ABC's of Assessment.
|
47 |
-
2. Use the 6-Step Model of Crisis Intervention as a guide for your interaction.
|
48 |
-
3. Incorporate relevant strategies from the Strategies of Crisis Intervention section.
|
49 |
4. Be mindful of cultural sensitivities as outlined in the Culturally Sensitive Approaches section.
|
50 |
5. If suicide risk is detected, use guidelines from the Suicide Assessment and Creating a Safety Plan sections.
|
51 |
6. Always prioritize client safety and encourage professional help when needed.
|
52 |
|
|
|
|
|
|
|
|
|
|
|
53 |
Follow these guidelines in your interactions:
|
54 |
1. For the first 2-3 exchanges, focus on understanding the user's situation by asking open-ended questions.
|
55 |
2. After initial exchanges, transition to providing support and gentle suggestions based on what you've learned.
|
56 |
3. Always be empathetic and acknowledge the user's feelings.
|
57 |
4. Offer coping strategies or advice that are relevant to the user's specific situation, drawing from the provided resources.
|
58 |
-
5. Periodically
|
59 |
6. Be flexible - if the user introduces a new topic or concern, be ready to explore that.
|
60 |
7. If you suspect the user is in immediate danger, strongly encourage them to seek professional help or emergency services.
|
|
|
61 |
|
62 |
Remember to keep the tone warm, supportive, and non-judgmental throughout.
|
63 |
|
@@ -65,6 +71,10 @@ Chat History:
|
|
65 |
{chat_history}
|
66 |
|
67 |
Current conversation stage: {stage}
|
|
|
|
|
|
|
|
|
68 |
"""
|
69 |
|
70 |
human_template = "{user_input}"
|
@@ -81,20 +91,22 @@ def setup_chatbot_chain():
|
|
81 |
|
82 |
chatbot_chain = setup_chatbot_chain()
|
83 |
|
84 |
-
def respond(message, history, stage):
|
85 |
chat_history = "\n".join([f"Human: {h[0]}\nAI: {h[1]}" for h in history])
|
86 |
|
87 |
response = chatbot_chain.run(
|
88 |
user_input=message,
|
89 |
mental_health_info=mental_health_resources,
|
90 |
chat_history=chat_history,
|
91 |
-
stage=stage
|
|
|
92 |
)
|
93 |
|
94 |
-
# Update stage
|
95 |
-
new_stage = "
|
|
|
96 |
|
97 |
-
return response, new_stage
|
98 |
|
99 |
def text_to_speech(text):
|
100 |
tts = gTTS(text=text, lang='en')
|
@@ -134,24 +146,25 @@ with gr.Blocks(css=css) as demo:
|
|
134 |
chatbot = gr.Chatbot()
|
135 |
msg = gr.Textbox()
|
136 |
clear = gr.Button("Clear")
|
137 |
-
state = gr.State("
|
|
|
138 |
audio_output = gr.Audio(label="Response Audio", autoplay=True)
|
139 |
|
140 |
-
def user(user_message, history, stage):
|
141 |
-
return "", history + [[user_message, None]], stage
|
142 |
|
143 |
-
def bot(history, stage):
|
144 |
-
bot_message, new_stage = respond(history[-1][0], history[:-1], stage)
|
145 |
history[-1][1] = bot_message
|
146 |
|
147 |
audio_file = text_to_speech(bot_message)
|
148 |
|
149 |
-
return history, new_stage, audio_file
|
150 |
|
151 |
-
msg.submit(user, [msg, chatbot, state], [msg, chatbot, state], queue=False).then(
|
152 |
-
bot, [chatbot, state], [chatbot, state, audio_output]
|
153 |
)
|
154 |
-
clear.click(lambda: ([], "
|
155 |
|
156 |
gr.Examples(
|
157 |
examples=[
|
|
|
43 |
{mental_health_info}
|
44 |
|
45 |
When responding to users:
|
46 |
+
1. Assess the severity of the situation using the ABC's of Assessment (Affective state, Behavioural functioning, Cognitive state).
|
47 |
+
2. Use the 6-Step Model of Crisis Intervention as a guide for your interaction: 1) Define the problem, 2) Ensure client safety, 3) Provide support, 4) Examine alternatives, 5) Make plans, 6) Obtain commitment.
|
48 |
+
3. Incorporate relevant strategies from the Strategies of Crisis Intervention section, adapting them into conversational language.
|
49 |
4. Be mindful of cultural sensitivities as outlined in the Culturally Sensitive Approaches section.
|
50 |
5. If suicide risk is detected, use guidelines from the Suicide Assessment and Creating a Safety Plan sections.
|
51 |
6. Always prioritize client safety and encourage professional help when needed.
|
52 |
|
53 |
+
Customize your approach based on the severity of the crisis:
|
54 |
+
- Low Severity: Focus on coping strategies and emotional support.
|
55 |
+
- Medium Severity: Emphasize problem-solving and resource connection.
|
56 |
+
- High Severity: Prioritize safety planning and immediate professional intervention.
|
57 |
+
|
58 |
Follow these guidelines in your interactions:
|
59 |
1. For the first 2-3 exchanges, focus on understanding the user's situation by asking open-ended questions.
|
60 |
2. After initial exchanges, transition to providing support and gentle suggestions based on what you've learned.
|
61 |
3. Always be empathetic and acknowledge the user's feelings.
|
62 |
4. Offer coping strategies or advice that are relevant to the user's specific situation, drawing from the provided resources.
|
63 |
+
5. Periodically check in on the user's emotional state to gauge any changes in distress levels.
|
64 |
6. Be flexible - if the user introduces a new topic or concern, be ready to explore that.
|
65 |
7. If you suspect the user is in immediate danger, strongly encourage them to seek professional help or emergency services.
|
66 |
+
8. Regularly provide information about professional resources or hotlines, ensuring users are aware of additional support options.
|
67 |
|
68 |
Remember to keep the tone warm, supportive, and non-judgmental throughout.
|
69 |
|
|
|
71 |
{chat_history}
|
72 |
|
73 |
Current conversation stage: {stage}
|
74 |
+
(Stages: initial_assessment, problem_definition, safety_check, support_provision, alternative_exploration, plan_making, commitment_obtaining, follow_up)
|
75 |
+
|
76 |
+
Severity level: {severity}
|
77 |
+
(Levels: low, medium, high)
|
78 |
"""
|
79 |
|
80 |
human_template = "{user_input}"
|
|
|
91 |
|
92 |
chatbot_chain = setup_chatbot_chain()
|
93 |
|
94 |
+
def respond(message, history, stage, severity):
|
95 |
chat_history = "\n".join([f"Human: {h[0]}\nAI: {h[1]}" for h in history])
|
96 |
|
97 |
response = chatbot_chain.run(
|
98 |
user_input=message,
|
99 |
mental_health_info=mental_health_resources,
|
100 |
chat_history=chat_history,
|
101 |
+
stage=stage,
|
102 |
+
severity=severity
|
103 |
)
|
104 |
|
105 |
+
# Update stage and severity (in a real scenario, this would be more sophisticated)
|
106 |
+
new_stage = "support_provision" if stage == "initial_assessment" else "follow_up"
|
107 |
+
new_severity = severity # In a real scenario, this would be reassessed based on the conversation
|
108 |
|
109 |
+
return response, new_stage, new_severity
|
110 |
|
111 |
def text_to_speech(text):
|
112 |
tts = gTTS(text=text, lang='en')
|
|
|
146 |
chatbot = gr.Chatbot()
|
147 |
msg = gr.Textbox()
|
148 |
clear = gr.Button("Clear")
|
149 |
+
state = gr.State("initial_assessment")
|
150 |
+
severity = gr.State("low")
|
151 |
audio_output = gr.Audio(label="Response Audio", autoplay=True)
|
152 |
|
153 |
+
def user(user_message, history, stage, severity):
|
154 |
+
return "", history + [[user_message, None]], stage, severity
|
155 |
|
156 |
+
def bot(history, stage, severity):
|
157 |
+
bot_message, new_stage, new_severity = respond(history[-1][0], history[:-1], stage, severity)
|
158 |
history[-1][1] = bot_message
|
159 |
|
160 |
audio_file = text_to_speech(bot_message)
|
161 |
|
162 |
+
return history, new_stage, new_severity, audio_file
|
163 |
|
164 |
+
msg.submit(user, [msg, chatbot, state, severity], [msg, chatbot, state, severity], queue=False).then(
|
165 |
+
bot, [chatbot, state, severity], [chatbot, state, severity, audio_output]
|
166 |
)
|
167 |
+
clear.click(lambda: ([], "initial_assessment", "low", None), None, [chatbot, state, severity, audio_output], queue=False)
|
168 |
|
169 |
gr.Examples(
|
170 |
examples=[
|