Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# PHQ-9 and GAD-7 questions
|
4 |
+
phq9_questions = [
|
5 |
+
"Little interest or pleasure in doing things",
|
6 |
+
"Feeling down, depressed, or hopeless",
|
7 |
+
"Trouble falling or staying asleep, or sleeping too much",
|
8 |
+
"Feeling tired or having little energy",
|
9 |
+
"Poor appetite or overeating",
|
10 |
+
"Feeling bad about yourself — or that you are a failure or have let yourself or your family down",
|
11 |
+
"Trouble concentrating on things, such as reading the newspaper or watching television",
|
12 |
+
"Moving or speaking so slowly that other people could have noticed? Or the opposite — being so fidgety or restless",
|
13 |
+
"Thoughts that you would be better off dead or of hurting yourself"
|
14 |
+
]
|
15 |
+
|
16 |
+
gad7_questions = [
|
17 |
+
"Feeling nervous, anxious, or on edge",
|
18 |
+
"Not being able to stop or control worrying",
|
19 |
+
"Worrying too much about different things",
|
20 |
+
"Trouble relaxing",
|
21 |
+
"Being so restless that it's hard to sit still",
|
22 |
+
"Becoming easily annoyed or irritable",
|
23 |
+
"Feeling afraid as if something awful might happen"
|
24 |
+
]
|
25 |
+
|
26 |
+
# Assessment function
|
27 |
+
def assess(phq9_scores, gad7_scores):
|
28 |
+
phq9_total = sum(phq9_scores)
|
29 |
+
gad7_total = sum(gad7_scores)
|
30 |
+
|
31 |
+
# PHQ-9 Interpretation
|
32 |
+
if phq9_total <= 4:
|
33 |
+
phq9_result = "Minimal or no depression"
|
34 |
+
elif 5 <= phq9_total <= 9:
|
35 |
+
phq9_result = "Mild depression"
|
36 |
+
elif 10 <= phq9_total <= 14:
|
37 |
+
phq9_result = "Moderate depression"
|
38 |
+
elif 15 <= phq9_total <= 19:
|
39 |
+
phq9_result = "Moderately severe depression"
|
40 |
+
else:
|
41 |
+
phq9_result = "Severe depression"
|
42 |
+
|
43 |
+
# GAD-7 Interpretation
|
44 |
+
if gad7_total <= 4:
|
45 |
+
gad7_result = "Minimal anxiety"
|
46 |
+
elif 5 <= gad7_total <= 9:
|
47 |
+
gad7_result = "Mild anxiety"
|
48 |
+
elif 10 <= gad7_total <= 14:
|
49 |
+
gad7_result = "Moderate anxiety"
|
50 |
+
else:
|
51 |
+
gad7_result = "Severe anxiety"
|
52 |
+
|
53 |
+
# Recommendation
|
54 |
+
recommendation = ""
|
55 |
+
if phq9_total >= 10 or gad7_total >= 10:
|
56 |
+
recommendation = "⚠️ We recommend visiting a Psychiatrist or Counselor for a professional evaluation."
|
57 |
+
else:
|
58 |
+
recommendation = "✅ No immediate psychiatric visit required. Monitor your mental health and practice self-care."
|
59 |
+
|
60 |
+
return (
|
61 |
+
f"**PHQ-9 Score:** {phq9_total} ({phq9_result})\n\n"
|
62 |
+
f"**GAD-7 Score:** {gad7_total} ({gad7_result})\n\n"
|
63 |
+
f"**Recommendation:** {recommendation}"
|
64 |
+
)
|
65 |
+
|
66 |
+
# Create inputs
|
67 |
+
phq9_inputs = [gr.Slider(0, 3, step=1, label=q) for q in phq9_questions]
|
68 |
+
gad7_inputs = [gr.Slider(0, 3, step=1, label=q) for q in gad7_questions]
|
69 |
+
|
70 |
+
# Launch the Gradio interface
|
71 |
+
demo = gr.Interface(
|
72 |
+
fn=assess,
|
73 |
+
inputs=phq9_inputs + gad7_inputs,
|
74 |
+
outputs=gr.Markdown(label="Assessment Result"),
|
75 |
+
title="🧠 Mental Health Self-Assessment (PHQ-9 & GAD-7)",
|
76 |
+
description="Answer the following questions to get an initial assessment of your depression and anxiety levels. This is not a diagnosis."
|
77 |
+
)
|
78 |
+
|
79 |
+
if __name__ == "__main__":
|
80 |
+
demo.launch()
|