Update app.py
Browse files
app.py
CHANGED
@@ -9,62 +9,7 @@ os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY")
|
|
9 |
|
10 |
# Define mental health resources
|
11 |
mental_health_resources = """
|
12 |
-
|
13 |
-
Coping Strategies:
|
14 |
-
|
15 |
-
1. Mindfulness and Meditation:
|
16 |
-
- Practice focusing on the present moment
|
17 |
-
- Can help reduce anxiety and improve mood
|
18 |
-
- Try apps like Headspace or Calm for guided meditations
|
19 |
-
|
20 |
-
2. Exercise:
|
21 |
-
- Regular physical activity can boost mood and reduce stress
|
22 |
-
- Aim for at least 30 minutes of moderate exercise most days
|
23 |
-
- Activities can include walking, jogging, swimming, or yoga
|
24 |
-
|
25 |
-
3. Healthy Sleep Habits:
|
26 |
-
- Maintain a consistent sleep schedule
|
27 |
-
- Create a relaxing bedtime routine
|
28 |
-
- Avoid screens for at least an hour before bed
|
29 |
-
|
30 |
-
4. Social Connection:
|
31 |
-
- Reach out to friends and family regularly
|
32 |
-
- Join clubs or groups based on your interests
|
33 |
-
- Consider volunteering to meet new people and gain a sense of purpose
|
34 |
-
|
35 |
-
5. Cognitive Behavioral Therapy (CBT) Techniques:
|
36 |
-
- Challenge negative thought patterns
|
37 |
-
- Practice reframing situations in a more balanced way
|
38 |
-
- Keep a thought journal to track and analyze your thoughts
|
39 |
-
|
40 |
-
General Advice:
|
41 |
-
|
42 |
-
1. Seek Professional Help:
|
43 |
-
- If symptoms persist or interfere with daily life, consult a mental health professional
|
44 |
-
- Options include therapists, counselors, and psychiatrists
|
45 |
-
- Many offer telehealth services for convenience
|
46 |
-
|
47 |
-
2. Practice Self-Care:
|
48 |
-
- Engage in activities you enjoy
|
49 |
-
- Set boundaries to protect your mental health
|
50 |
-
- Make time for relaxation and hobbies
|
51 |
-
|
52 |
-
3. Maintain a Healthy Lifestyle:
|
53 |
-
- Eat a balanced diet rich in fruits, vegetables, and whole grains
|
54 |
-
- Stay hydrated
|
55 |
-
- Limit alcohol and avoid recreational drugs
|
56 |
-
|
57 |
-
4. Use Stress Management Techniques:
|
58 |
-
- Try deep breathing exercises or progressive muscle relaxation
|
59 |
-
- Use time management tools to reduce overwhelm
|
60 |
-
- Practice saying "no" to excessive commitments
|
61 |
-
|
62 |
-
5. Build Resilience:
|
63 |
-
- Develop a growth mindset
|
64 |
-
- Set realistic goals and celebrate small victories
|
65 |
-
- Learn from setbacks and view them as opportunities for growth
|
66 |
-
|
67 |
-
Remember, everyone's mental health journey is unique. What works for one person may not work for another. It's important to be patient and kind to yourself as you explore different strategies for maintaining good mental health.
|
68 |
"""
|
69 |
|
70 |
# Define prompt template
|
@@ -98,7 +43,7 @@ chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_mes
|
|
98 |
|
99 |
# Set up main chatbot chain
|
100 |
def setup_chatbot_chain():
|
101 |
-
llm = ChatOpenAI(temperature=0.7, model_name="gpt-
|
102 |
return LLMChain(llm=llm, prompt=chat_prompt)
|
103 |
|
104 |
chatbot_chain = setup_chatbot_chain()
|
@@ -118,8 +63,33 @@ def respond(message, history, stage):
|
|
118 |
|
119 |
return response, new_stage
|
120 |
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
gr.Markdown("I'm here to listen and provide support. How are you feeling today?")
|
124 |
|
125 |
chatbot = gr.Chatbot()
|
|
|
9 |
|
10 |
# Define mental health resources
|
11 |
mental_health_resources = """
|
12 |
+
[Your existing mental health resources here]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
"""
|
14 |
|
15 |
# Define prompt template
|
|
|
43 |
|
44 |
# Set up main chatbot chain
|
45 |
def setup_chatbot_chain():
|
46 |
+
llm = ChatOpenAI(temperature=0.7, model_name="gpt-4-turbo")
|
47 |
return LLMChain(llm=llm, prompt=chat_prompt)
|
48 |
|
49 |
chatbot_chain = setup_chatbot_chain()
|
|
|
63 |
|
64 |
return response, new_stage
|
65 |
|
66 |
+
css = """
|
67 |
+
.chatbot-header {
|
68 |
+
display: flex;
|
69 |
+
align-items: center;
|
70 |
+
justify-content: center;
|
71 |
+
margin-bottom: 20px;
|
72 |
+
}
|
73 |
+
.chatbot-title {
|
74 |
+
font-size: 24px;
|
75 |
+
margin: 0;
|
76 |
+
padding: 0;
|
77 |
+
}
|
78 |
+
.heart-logo {
|
79 |
+
font-size: 28px;
|
80 |
+
margin-right: 10px;
|
81 |
+
}
|
82 |
+
"""
|
83 |
+
|
84 |
+
with gr.Blocks(css=css) as demo:
|
85 |
+
gr.HTML(
|
86 |
+
"""
|
87 |
+
<div class="chatbot-header">
|
88 |
+
<span class="heart-logo">❤️</span>
|
89 |
+
<h1 class="chatbot-title">Mental Health Support Chatbot</h1>
|
90 |
+
</div>
|
91 |
+
"""
|
92 |
+
)
|
93 |
gr.Markdown("I'm here to listen and provide support. How are you feeling today?")
|
94 |
|
95 |
chatbot = gr.Chatbot()
|