Sumayyea commited on
Commit
bd2ab43
·
verified ·
1 Parent(s): f4abe7b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +125 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import anthropic
3
+
4
+ # Set the title and introduction
5
+ st.title('Psychiatric Patient Diagnosis and Treatment App')
6
+ st.write("""
7
+ Welcome to the Psychiatric Patient Diagnosis and Treatment App.
8
+ Please provide the following information to receive a personalized diagnosis and treatment recommendation.
9
+ Your responses will remain confidential.
10
+ """)
11
+
12
+ # Sidebar for inputs
13
+ st.sidebar.header('Patient Information')
14
+
15
+ # Input for Mental Health History
16
+ mental_health_history = st.sidebar.text_area('Mental Health History',
17
+ placeholder="Please describe your past psychiatric history...")
18
+
19
+ # Input for Current Symptoms
20
+ current_symptoms = st.sidebar.multiselect(
21
+ 'Current Symptoms',
22
+ ['Anxiety', 'Depression', 'Insomnia', 'Mood Swings', 'Irritability', 'Fatigue', 'Difficulty Concentrating', 'Panic Attacks', 'Other']
23
+ )
24
+
25
+ # Input for Medication Preferences
26
+ medication_pref = st.sidebar.selectbox(
27
+ 'Medication Preferences',
28
+ ['No Preference', 'Prefer Natural Remedies', 'Prefer Prescription Medication', 'Prefer to Avoid Medication']
29
+ )
30
+
31
+ # Input for Treatment Preferences
32
+ treatment_pref = st.sidebar.radio(
33
+ 'Treatment Preferences',
34
+ ['Cognitive Behavioral Therapy (CBT)', 'Medication Management', 'Therapy & Medication', 'Mindfulness-Based Therapy', 'Other']
35
+ )
36
+
37
+ # Input for Preferred Communication Method
38
+ communication_pref = st.sidebar.selectbox(
39
+ 'Preferred Communication Method',
40
+ ['Text Only', 'Text and Call']
41
+ )
42
+
43
+ # Show additional fields for Text and Call option
44
+ patient_name = None
45
+ patient_contact_number = None
46
+
47
+ if communication_pref == 'Text and Call':
48
+ patient_name = st.sidebar.text_input('Patient Name')
49
+ patient_contact_number = st.sidebar.text_input('Contact Number', help="Please enter your phone number")
50
+
51
+ # Input for Claude AI API key
52
+ api_key = st.secrets["claude_api_key"]
53
+
54
+ # Main section for displaying results
55
+ st.header('Personalized Diagnosis and Treatment Plan')
56
+
57
+ # Button to submit the form
58
+ if st.sidebar.button('Submit'):
59
+ if api_key: # Ensure the API key is provided
60
+ if communication_pref == 'Text and Call' and (not patient_name or not patient_contact_number):
61
+ st.error("Please provide both name and contact number to receive the call.")
62
+ else:
63
+ # Initialize the Claude AI client with the provided API key
64
+ client = anthropic.Anthropic(api_key=api_key)
65
+
66
+ # Prepare the prompt to send to Claude AI
67
+ prompt = (
68
+ f"Mental Health History: {mental_health_history}\n"
69
+ f"Current Symptoms: {', '.join(current_symptoms)}\n"
70
+ f"Medication Preferences: {medication_pref}\n"
71
+ f"Treatment Preferences: {treatment_pref}\n"
72
+ f"Preferred Communication Method: {communication_pref}\n\n"
73
+ "Please provide a personalized diagnosis and treatment plan based on the above information."
74
+ )
75
+
76
+ # Call Claude AI API
77
+ message = client.messages.create(
78
+ model="claude-3-5-sonnet-20240620",
79
+ max_tokens=280,
80
+ temperature=0.7, # Adjust temperature for balanced creativity
81
+ system="You are a world-class psychiatrist who specializes in providing personalized mental health diagnoses and treatment plans.",
82
+ messages=[
83
+ {
84
+ "role": "user",
85
+ "content": prompt
86
+ }
87
+ ]
88
+ )
89
+
90
+ # Extract the response content
91
+ raw_context = message.content
92
+ diagnosis_and_treatment = raw_context[0].text
93
+
94
+ # Display the response in the main section
95
+ st.write(diagnosis_and_treatment)
96
+
97
+ # Inform the patient that a call will be placed soon
98
+ if communication_pref == 'Text and Call':
99
+ st.success(f"Thank you, {patient_name}. A call will be placed to you at {patient_contact_number} within the next 24 hours.")
100
+ else:
101
+ st.error("Please enter your Claude API key to receive a diagnosis and treatment plan.")
102
+ else:
103
+ st.write("Please complete the form in the sidebar and click 'Submit' to receive your personalized plan.")
104
+
105
+ # Additional UI/UX features for a calming experience
106
+ st.markdown("""
107
+ <style>
108
+ body {
109
+ background-color: #f4f7f8;
110
+ font-family: 'Arial', sans-serif;
111
+ }
112
+ .stSidebar {
113
+ background-color: #f0f2f6;
114
+ }
115
+ .stButton > button {
116
+ background-color: #4CAF50;
117
+ color: white;
118
+ }
119
+ </style>
120
+ """, unsafe_allow_html=True)
121
+
122
+ # Footer with copyright and year
123
+ st.markdown("---")
124
+ st.markdown('<div style="text-align: center;">© 2024 PsychGuide by Engr. Sumayyea Salahuddin. All rights reserved.</div>', unsafe_allow_html=True)
125
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ anthropic