wellnessv2 / app.py
ombhojane's picture
Update app.py
e61dcd2 verified
import os
import streamlit as st
import google.generativeai as genai
genai.configure(api_key=st.secrets["GEMINI_API_KEY"])
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 40,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
)
st.title("Mental Health Conversation Analyzer")
st.write("Please enter the conversation between the patient and the doctor below:")
conversation_input = st.text_area("Conversation Input", height=300)
if st.button("Analyze Conversation"):
if conversation_input:
chat_session = model.start_chat(
history=[
{
"role": "user",
"parts": [
"Task Introduction:\nYou are an AI assistant tasked with analyzing a conversation between a user and a mental health doctor. The user may have ADHD, bipolar disorder, or neither. Your goal is to assess the conversation, perform diagnostic tests for both disorders, and determine which disorder, if any, the user is likely experiencing.\n\nHere is the Conversation:\nPatient (P):\nI don’t know, Doc. It feels like I’m two different people sometimes.\n\nDoctor (D):\nThat sounds intense. Can you tell me more about what you mean by that?\n\nP:\nWell, some days, I wake up and feel like I can conquer the world. I’ll stay up all night working on projects, I’m talking nonstop, making big plans—it’s like I’m unstoppable.\n\nD:\nThat sounds like a lot of energy. How does that feel for you when you’re in that state?\n\nP:\nIt feels amazing at first. Like, I’m finally myself, you know? But then it gets... too much. My thoughts are racing, I’m spending money I don’t have, and eventually, I just crash.\n\nD:\nWhen you say \"crash,\" what happens?\n\nP:\nIt’s like all that energy is sucked out of me. I can’t get out of bed, I don’t care about anything, and I just feel... empty. It’s the complete opposite.\n\nD:\nThat sounds really difficult. How long do these changes usually last?\n\nP:\nIt’s hard to say. Sometimes it’s a few days, sometimes weeks. It feels unpredictable, and I never know when it’s going to hit.\n\nD:\nI see. How have these shifts been affecting your daily life?\n\nP:\nIt’s a mess. My relationships are strained because one minute I’m super social, and the next I’m avoiding everyone. I can’t hold down a job because I either burn out or mess up when I’m in those high-energy moments.\n\nD:\nThat must be really challenging to manage. Have you noticed anything that triggers these changes, or do they just happen?\n\nP:\nThey just happen, as far as I can tell. I’ve tried keeping a journal, but even that feels overwhelming when I’m in the low periods.\n\nD:\nIt sounds like these shifts are taking a toll on you, but it’s good that you’ve started noticing patterns. Have you talked to anyone else about what you’re experiencing?\n\nP:\nNot really. I’m scared people won’t understand or will think I’m being dramatic.\n\nD:\nIt’s understandable to feel that way, but I want you to know that what you’re describing is very real and valid. There are ways to help manage this, and you don’t have to face it alone.\n\nP:\nI’d like to get some help. I just want to feel... balanced. Like, I don’t need to be overly happy all the time, but I don’t want to feel so low either.\n\nD:\nThat’s a great goal, and there are definitely steps we can take to work toward it. Let’s talk about some options and see what feels right for you.\n\n\nIdentify Symptoms:\nBased on the conversation, identify and list symptoms associated with ADHD and bipolar disorder.\n\nPerform Diagnostic Tests:\nUsing the identified symptoms, perform a diagnostic test for ADHD and bipolar disorder. Score the symptoms based on the DSM-5 criteria for each disorder.\n\nCompare Results:\nCompare the results of the ADHD and bipolar disorder assessments. Which disorder has more symptoms present based on the conversation?\n\nDetermine Diagnosis:\nBased on the comparison, determine which disorder the user is more likely to have. Provide a rationale for your conclusion.\n\nConclusion and Recommendations:\nConclude with a summary of the findings and suggest next steps for the user.",
],
},
{
"role": "model",
"parts": [
"**Identify Symptoms:**\n\n* **Symptoms suggestive of Bipolar Disorder:**\n * Periods of high energy and activity (mania/hypomania): Staying up all night, working on projects, talking nonstop, making big plans, feeling unstoppable.\n * Periods of low energy and mood (depression): Inability to get out of bed, lack of interest, feelings of emptiness.\n * Extreme mood swings: Shifting between high energy and low mood.\n * Impulsive behavior: Spending money excessively.\n * Racing thoughts.\n * Difficulty maintaining relationships and employment.\n\n* **Symptoms suggestive of ADHD:**\n * Difficulty keeping a journal (potential executive dysfunction).\n * Impulsivity (spending money excessively).\n * Racing thoughts.\n * Difficulty maintaining relationships and employment (can be a secondary effect of untreated ADHD).\n\n**Perform Diagnostic Tests:**\n\nIt's important to note that I cannot formally diagnose. This is a simulated diagnostic process based on the provided conversation and DSM-5 criteria.\n\n* **Bipolar Disorder (specifically Bipolar II - hypomania and depression):**\n * Criterion A (Manic/Hypomanic Episode): Meets criteria based on description of elevated mood, increased energy, decreased need for sleep, racing thoughts, increased goal-directed activity, and impulsive spending.\n * Criterion B (Depressive Episode): Meets criteria based on description of low mood, loss of interest, fatigue, and feelings of emptiness.\n * Criterion C: The mood changes are clearly causing significant distress and impairment in social and occupational functioning.\n * Other criteria would need to be assessed to rule out other conditions.\n\n* **ADHD (Inattentive or Combined Type):**\n * While some symptoms like impulsivity and difficulty with sustained effort (journaling) are present, there is not enough information in the dialogue to assess the full range of inattention and/or hyperactivity-impulsivity criteria required for an ADHD diagnosis. Information about childhood onset and pervasiveness of symptoms across settings is missing.\n\n\n**Compare Results:**\n\nThe conversation provides stronger evidence for Bipolar Disorder than ADHD. While some symptoms overlap, the clear descriptions of distinct periods of elevated mood and depressed mood are more characteristic of Bipolar Disorder.\n\n**Determine Diagnosis:**\n\nBased on the provided information, the user's symptoms are more aligned with **Bipolar II Disorder**. The cycling between periods of high energy/activity and low mood/energy, along with the functional impairment, strongly suggests this diagnosis. ADHD is less likely, given the lack of evidence for sufficient inattentive or hyperactive-impulsive symptoms. It's also possible the user has both, as ADHD and Bipolar Disorder can co-occur.\n\n**Conclusion and Recommendations:**\n\nThe user presents symptoms strongly suggesting Bipolar II Disorder. The next steps should involve a comprehensive evaluation by a qualified mental health professional. This should include:\n\n* **Detailed history:** Gathering more information about the frequency, duration, and severity of mood episodes, including any family history of mood disorders.\n* **Symptom rating scales:** Using standardized questionnaires to assess the presence and severity of bipolar and ADHD symptoms.\n* **Differential diagnosis:** Ruling out other potential conditions with overlapping symptoms.\n* **Safety assessment:** Evaluating any potential risk of self-harm or suicide.\n\nIf Bipolar Disorder is confirmed, treatment options may include medication, therapy (such as cognitive-behavioral therapy or interpersonal and social rhythm therapy), and lifestyle changes. If ADHD is also present, it can be addressed alongside the Bipolar Disorder. Early diagnosis and appropriate treatment are crucial for managing Bipolar Disorder and improving quality of life.\n",
],
},
]
)
response = chat_session.send_message(
{
"role": "user",
"parts": [
"Task Introduction: You are an AI assistant tasked with analyzing a conversation between a user and a mental health doctor. The user may have ADHD, bipolar disorder, or neither. Your goal is to assess the conversation, perform diagnostic tests for both disorders, and determine which disorder, if any, the user is likely experiencing." +
conversation_input +
"""
Identified Symptoms:
Based on the conversation, identify and list symptoms associated with ADHD and bipolar disorder.
Diagnostic Test:
Using the identified symptoms, perform a diagnostic test for ADHD and bipolar disorder. Score the symptoms based on the DSM-5 criteria for each disorder.
Comparision Results:
Compare the results of the ADHD and bipolar disorder assessments. Which disorder has more symptoms present based on the conversation?
Determine Diagnosis:
Based on the comparison, determine which disorder the user is more likely to have. Provide a rationale for your conclusion.
Conclusion and Recommendations:
Conclude with a summary of the findings and suggest next steps for the user.
""",
],
}
)
# Display the response from the model
st.subheader("Analysis Results:")
st.write(response.text)
else:
st.warning("Please enter a conversation before analyzing.")