Spaces:
Sleeping
Sleeping
ogegadavis254
commited on
Commit
β’
36b3a02
1
Parent(s):
b09bd8c
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,36 @@ def reset_conversation():
|
|
14 |
st.session_state.ask_intervention = False
|
15 |
return None
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Define model links for the Addiction Recovery and Mental Health models
|
18 |
model_links = {
|
19 |
"Addiction recovery AI": "NousResearch/Nous-Hermes-2-Yi-34B",
|
@@ -85,6 +115,34 @@ if "messages" not in st.session_state:
|
|
85 |
selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
|
86 |
reset_button = st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
# Accept user input
|
89 |
if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
|
90 |
# Display user message in chat message container
|
@@ -111,4 +169,5 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
|
|
111 |
st.write("You can reach out to a certified therapist at +25493609747.")
|
112 |
|
113 |
# Add assistant response to chat history
|
114 |
-
st.session_state.messages.append(("assistant", assistant_response))
|
|
|
|
14 |
st.session_state.ask_intervention = False
|
15 |
return None
|
16 |
|
17 |
+
def analyze_diagnosis(messages, model_link):
|
18 |
+
# Extract user messages
|
19 |
+
user_messages = [message[1] for message in messages if message[0] == "user"]
|
20 |
+
|
21 |
+
# Define mental conditions and associated keywords
|
22 |
+
mental_conditions = {
|
23 |
+
"Depression": ["depression", "sad", "hopeless", "lonely", "empty", "worthless", "miserable"],
|
24 |
+
"Anxiety": ["anxiety", "nervous", "worried", "fearful", "panicked", "stressed", "tense"],
|
25 |
+
"Panic disorder": ["panic attack", "panic", "scared", "terrified", "frightened", "hyperventilate", "heart racing"],
|
26 |
+
"Bipolar disorder": ["bipolar", "manic", "mania", "euphoric", "energetic", "depressed", "hopeless"],
|
27 |
+
"Schizophrenia": ["schizophrenia", "hallucination", "delusion", "paranoia", "disorganized", "psychotic", "dissociation"],
|
28 |
+
"PTSD": ["ptsd", "trauma", "nightmare", "flashback", "startled", "avoidance", "hypervigilance"],
|
29 |
+
"Obsessive-Compulsive Disorder": ["ocd", "obsession", "compulsion", "intrusive thought", "ritual", "cleaning", "checking"],
|
30 |
+
"Eating disorder": ["eating disorder", "anorexia", "bulimia", "binge eating", "body image", "weight obsession", "purging"],
|
31 |
+
"Substance use disorder": ["substance use", "drug addiction", "alcoholism", "substance abuse", "withdrawal", "craving", "dependency"],
|
32 |
+
"Attention-deficit/hyperactivity disorder (ADHD)": ["adhd", "attention deficit", "hyperactivity", "impulsivity", "inattention", "restlessness", "fidgeting"],
|
33 |
+
"Borderline personality disorder": ["borderline personality", "emotional instability", "impulsivity", "fear of abandonment", "unstable relationships", "self-harm", "mood swings"],
|
34 |
+
"Postpartum depression": ["postpartum depression", "baby blues", "motherhood depression", "crying spells", "irritability", "hopelessness", "fatigue"],
|
35 |
+
"Social anxiety disorder": ["social anxiety", "fear of social situations", "embarrassment", "humiliation", "avoidance", "self-consciousness", "panic"]
|
36 |
+
}
|
37 |
+
|
38 |
+
# Count occurrences of keywords for each mental condition
|
39 |
+
condition_counts = {condition: sum(message.lower().count(keyword) for message in user_messages for keyword in keywords)
|
40 |
+
for condition, keywords in mental_conditions.items()}
|
41 |
+
|
42 |
+
# Determine the condition with the highest count
|
43 |
+
diagnosis = max(condition_counts, key=condition_counts.get)
|
44 |
+
|
45 |
+
return diagnosis
|
46 |
+
|
47 |
# Define model links for the Addiction Recovery and Mental Health models
|
48 |
model_links = {
|
49 |
"Addiction recovery AI": "NousResearch/Nous-Hermes-2-Yi-34B",
|
|
|
115 |
selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
|
116 |
reset_button = st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
117 |
|
118 |
+
# Add diagnostic feature to the sidebar
|
119 |
+
if st.session_state.messages:
|
120 |
+
with st.sidebar:
|
121 |
+
st.subheader("Diagnosis")
|
122 |
+
st.markdown("<div style='color: #1E90FF; font-size: 16px; font-weight: bold;'>Analyzing...</div>", unsafe_allow_html=True)
|
123 |
+
|
124 |
+
diagnosis = analyze_diagnosis(st.session_state.messages, model_links[selected_model])
|
125 |
+
if diagnosis:
|
126 |
+
st.markdown(f"<div style='color: #FF6347; font-size: 18px; font-weight: bold;'>Diagnosis: {diagnosis}</div>", unsafe_allow_html=True)
|
127 |
+
|
128 |
+
# Add additional features on the sidebar
|
129 |
+
st.sidebar.markdown("---")
|
130 |
+
st.sidebar.subheader("Additional Features")
|
131 |
+
st.sidebar.markdown("π
Schedule Appointment")
|
132 |
+
st.sidebar.markdown("π Take Notes")
|
133 |
+
st.sidebar.markdown("π΅ Relaxing Music")
|
134 |
+
st.sidebar.markdown("π₯ Healthy Recipes")
|
135 |
+
st.sidebar.markdown("π€ Sleep Tracker")
|
136 |
+
|
137 |
+
# Add cautionary message about testing phase at the bottom of the sidebar
|
138 |
+
st.sidebar.markdown("---")
|
139 |
+
st.sidebar.markdown("**Note**: This model is still in the beta phase. Responses may be inaccurate or undesired. Use it cautiously, especially for critical issues.")
|
140 |
+
|
141 |
+
# Add logo and text to the sidebar
|
142 |
+
st.sidebar.markdown("---")
|
143 |
+
st.sidebar.image("https://assets.isu.pub/document-structure/221118065013-a6029cf3d563afaf9b946bb9497d45d4/v1/2841525b232adaef7bd0efe1da81a4c5.jpeg", width=200)
|
144 |
+
st.sidebar.write("A product proudly developed by Kisii University")
|
145 |
+
|
146 |
# Accept user input
|
147 |
if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
|
148 |
# Display user message in chat message container
|
|
|
169 |
st.write("You can reach out to a certified therapist at +25493609747.")
|
170 |
|
171 |
# Add assistant response to chat history
|
172 |
+
st.session_state.messages.append(("assistant", assistant_response))
|
173 |
+
|