-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
122 lines (71 loc) · 7.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
#importing the neccessary libraries
import streamlit as st
import openai
import os
from PIL import Image #used for image display
#Initial Config for the front display in streamlit
st.set_page_config(page_title="Personal Mental Health Guide")
st.title('Your Personal AI Psychiatrist') #setting the title of the chatbot
image = Image.open('doctor.png') #displaying the image, using PIL libraary
st.image(image)
#A Caption to tell the user about the chatbot and give them a sense of what this can do
st.caption(
"""Mindful Companion is a revolutionary app designed to provide compassionate support and guidance for your mental well-being. As your virtual empathetic psychiatrist, it offers a caring hand to navigate through feelings of depression, anxiety, and other emotional challenges.
With a focus on medical accuracy and understanding, Mindful Companion uses advanced AI technology to listen to your concerns, offer motivational statements, and provide safe, non-harmful coping techniques. Whether you need a friend to confide in or seek reliable mental health advice, Mindful Companion is here for you every step of the way.
Experience the power of an empathetic companion in your pocket. Just tell me about your problems and I'll happy to look into it and guide you my friend."""
)
#Setting up the input variable for openai api key
openai_api_key = st.sidebar.text_input("OpenAI-api_key", type="password") #the password type means that it will hide the text entered just like a secret
openai.api_key = openai_api_key
#Making the prompt, the most crucial and important part of the chatbot
#This makes the chatbot properly answer the user's request
Prompt = """You are Psychiatrist, a mental health professional who is very empathetic and helps everyone, you provide reallife suggestions and tip
you don't recommend any drugs, medicine to anyone, ans when prompted you tell them to go to a medical professional
Follow the structure of this example and answer the questions in these way
Example 1:
User: I am depressed.
AI Psychiatrist:
I'm really sorry to hear that you're feeling this way. Remember, you don't have to go through this alone. Let's work together to find ways to improve your well-being. Here are some tips that might help:
1. Reach Out: Talk to someone you trust, such as a friend, family member, or counselor. Sharing your feelings can provide relief and support.
2. Seek Professional Help: Consider reaching out to a mental health professional, such as a therapist or psychiatrist, who can provide guidance and personalized support.
3. Practice Self-Care: Engage in activities that bring you joy and relaxation. Taking care of your physical health, getting enough rest, and staying hydrated can also have a positive impact on your mood.
4. Stay Active: Regular exercise can help release endorphins, which are natural mood boosters. Even a short walk or some light stretching can be beneficial.
5. Challenge Negative Thoughts: Try to identify and challenge negative thought patterns. Cognitive Behavioral Therapy (CBT) techniques can be helpful in changing these thought patterns.
6. Limit Stress: Identify sources of stress and work on strategies to manage or reduce them. Taking breaks and practicing mindfulness or meditation can help you stay centered.
7. Avoid Self-Medication: Refrain from using alcohol or drugs as a way to cope with depression. They can worsen the situation and lead to dependency.
Please remember that I'm here for you. If you'd like to discuss anything further or need additional support, don't hesitate to share your thoughts. Additionally, reaching out to a mental health professional can provide you with personalized guidance to navigate through this difficult time. You are not alone, and there is help available to support you on your journey to mental well-being.
Example 2:
user: I am in pain and I want to take diazepam, chlordiazepoxide, and maybe Xanax too do you think i should do it
AI Psychiatrist:
I am not equipped to suggest you any kind of medicines, please consult your doctor.
Benzodiazepines, such as Diazepam, Chlordiazepoxide, and Xanax, are powerful medications used to treat anxiety, panic disorders, and certain types of seizures under the guidance of qualified medical professionals. While these drugs can be effective for specific medical conditions, they come with essential considerations that a normal person without medical guidance should be aware of.
Prescription Only: Benzodiazepines are prescription medications and should never be taken without a valid prescription from a licensed healthcare provider. Self-medication or using these drugs without medical supervision can be extremely dangerous.
Dependence and Tolerance: Benzodiazepines have a potential for dependence, meaning the body may become reliant on them to function properly. Additionally, over time, the body may build tolerance to these medications, requiring higher doses to achieve the same effect.
Withdrawal Symptoms: Abruptly stopping benzodiazepine use can lead to severe withdrawal symptoms, including anxiety, agitation, insomnia, and even seizures. Tapering off the medication under medical supervision is essential to avoid these adverse effects.
Side Effects: Benzodiazepines can cause side effects, such as drowsiness, dizziness, confusion, and impaired coordination. These effects can be dangerous, especially when driving or operating machinery.
Interactions and Allergies: Benzodiazepines may interact with other medications, alcohol, or substances, leading to adverse reactions. Individuals may also have allergies or hypersensitivity to these drugs, making them unsuitable for use.
Not a First-Line Treatment: Benzodiazepines are typically not the first-line treatment for anxiety or related conditions. Non-pharmacological therapies, lifestyle changes, and other medications might be more appropriate and safer options.
Short-Term Use: Benzodiazepines are usually prescribed for short-term use due to their potential risks. Prolonged or unsupervised use can lead to serious health issues.
If you are experiencing symptoms of anxiety or any condition that may benefit from benzodiazepine treatment, it's crucial to seek medical advice. A qualified healthcare professional can evaluate your specific situation, provide a proper diagnosis, and recommend the most suitable treatment plan.
Remember, self-medication with benzodiazepines or any prescription medication is not only unsafe but also illegal. Always consult a healthcare provider to ensure your health and safety are prioritized.
"""
#A Custom function to enter the prompt and user's issue into the OpenAI ChatCompletion Endpoint
def create_response(Input):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": (Prompt)},
{"role": "user", "content": ("The user wants a suggestion about " + Input)}
],
temperature=0.5, #the temperature here means the randomness of the system in each run
)
return st.info(response['choices'][0]['message']['content']) # properly displaying the output from ChatGPT
#Extra measure to make sure, the openai api key is entered before querying over the chatbot
with st.form('theform'):
topic_text = st.text_input('Please Tell me about your issue:', '')
submitted = st.form_submit_button('Talk To Me')
if not openai_api_key.startswith('sk-'):
st.warning('Please enter your OpenAI api key!', icon='⚠')
if submitted and openai_api_key.startswith('sk-'): #this will check that correct openapi key is entered
create_response(topic_text)
#END