Update app.py
Browse files
app.py
CHANGED
@@ -3,25 +3,54 @@ import gradio as gr
|
|
3 |
from langchain.chat_models import ChatOpenAI
|
4 |
from langchain.chains import LLMChain
|
5 |
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate
|
6 |
-
import hashlib
|
7 |
-
from gtts import gTTS
|
8 |
import tempfile
|
|
|
9 |
|
10 |
# Set up OpenAI API key
|
11 |
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY")
|
12 |
|
13 |
-
# Load mental health resources
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Define prompt template
|
18 |
system_template = """
|
19 |
You are an empathetic and supportive mental health chatbot specialized in crisis intervention. Your goal is to understand the user's situation and provide appropriate support based on established crisis intervention strategies. Use the following guidelines and resources to inform your responses:
|
20 |
|
|
|
21 |
{mental_health_info}
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
|
|
25 |
1. For the first 2-3 exchanges, focus on understanding the user's situation by asking open-ended questions.
|
26 |
2. After initial exchanges, transition to providing support and gentle suggestions based on what you've learned.
|
27 |
3. Always be empathetic and acknowledge the user's feelings.
|
|
|
3 |
from langchain.chat_models import ChatOpenAI
|
4 |
from langchain.chains import LLMChain
|
5 |
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate
|
|
|
|
|
6 |
import tempfile
|
7 |
+
from gtts import gTTS
|
8 |
|
9 |
# Set up OpenAI API key
|
10 |
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY")
|
11 |
|
12 |
+
# Load and structure mental health resources
|
13 |
+
def load_mental_health_resources():
|
14 |
+
with open("mental-health-crisis-strategies.md", "r") as file:
|
15 |
+
content = file.read()
|
16 |
+
|
17 |
+
sections = content.split('\n\n')
|
18 |
+
structured_content = {
|
19 |
+
"Crisis Overview": sections[1],
|
20 |
+
"Principles and Characteristics": sections[2],
|
21 |
+
"Process of Crisis Intervention": sections[3],
|
22 |
+
"6-Step Model": sections[4],
|
23 |
+
"Assessment in Crisis Intervention": sections[5],
|
24 |
+
"ABC's of Assessment": sections[6],
|
25 |
+
"Strategies of Crisis Intervention": sections[7],
|
26 |
+
"Conditions for Client Growth": sections[8],
|
27 |
+
"Suicide Assessment": sections[9],
|
28 |
+
"Creating a Safety Plan": sections[10],
|
29 |
+
"Culturally Sensitive Approaches": sections[11:14],
|
30 |
+
"Enhancing Crisis Intervention": sections[14],
|
31 |
+
"Wrap-Up": sections[15]
|
32 |
+
}
|
33 |
+
|
34 |
+
return structured_content
|
35 |
+
|
36 |
+
mental_health_resources = load_mental_health_resources()
|
37 |
|
38 |
# Define prompt template
|
39 |
system_template = """
|
40 |
You are an empathetic and supportive mental health chatbot specialized in crisis intervention. Your goal is to understand the user's situation and provide appropriate support based on established crisis intervention strategies. Use the following guidelines and resources to inform your responses:
|
41 |
|
42 |
+
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.
|