rishabh5752 commited on
Commit
876c376
1 Parent(s): c8f10a9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ with gr.Blocks(css=".contain.svelte-1iguv9h.svelte-1iguv9h.svelte-1iguv9h {width:85%} .gradio-container {background-color: #00A0F3} .svelte-zyic3i {width: 100%; margin: auto} .wrap.svelte-1ovntsr {width: 40%; margin: auto} img.svelte-zyic3i {width:40%} .wrap.svelte-3cbf20 {width:40%; margin:auto} .controls.svelte-3cbf20 {width:40%} textarea.svelte-2xzfnp {width:30%; border-color: #00A0F3} select.svelte-1bhvxvb {width: 30%; border-color: #00A0F3} .contain.svelte-1iguv9h.svelte-1iguv9h.svelte-1iguv9h {margin-top:10px; border-radius:15px} .gradio-container-3-18-0 img {margin: auto}") as demo:
4
+
5
+ def map_test_2_phq9(label_text):
6
+ if label_text == 'All the time':
7
+ phq_point = 3
8
+ elif label_text == 'More than half the time':
9
+ phq_point = 2
10
+ elif label_text == 'Some days':
11
+ phq_point = 1
12
+ else:
13
+ phq_point = 0
14
+ return phq_point
15
+
16
+ def get_phq9_result(drop1, drop2, drop3, drop4, drop5, drop6, drop7, drop8, drop9):
17
+ phq_array = (drop1, drop2, drop3, drop4, drop5, drop6, drop7, drop8, drop9)
18
+ phq_number_list = list(map(map_test_2_phq9, phq_array))
19
+ phq9_result = sum(phq_number_list)
20
+ return str(phq9_result)
21
+
22
+ def get_phq9_explanation(final_result):
23
+ if final_result < 5:
24
+ specialist_text = "This means a minimal level of depression is detected. Seek help from loved ones or consult a professional if it persists over time."
25
+ elif final_result < 10:
26
+ specialist_text = "This means a mild level of depression is detected. If this pattern continues over time and affects your daily life, consider consulting with a professional."
27
+ elif final_result < 15:
28
+ specialist_text = "This means a moderate level of depression is detected. There are ways to reduce depression such as exercise, engaging in activities you enjoy, journaling. If these do not work, consider contacting a specialist."
29
+ elif final_result < 19:
30
+ specialist_text = "This means a moderately severe level of depression is detected. Did you know that Üma offers psychologists and psychiatrists who could assist you? Depression can be successfully treated."
31
+ else:
32
+ specialist_text = "This means a severe level of depression is detected. Depression can be successfully treated, and we can help. Did you know that Üma provides psychologists and psychiatrists for these treatments? Contact them and take the test!"
33
+ return specialist_text
34
+
35
+ def get_user_data(name, email, age, gender, drop1, drop2, drop3, drop4, drop5, drop6, drop7, drop8, drop9, checkbox1, checkbox2, checkbox3, checkbox4):
36
+ phq9_result = get_phq9_result(drop1, drop2, drop3, drop4, drop5, drop6, drop7, drop8, drop9)
37
+ specialist_text = get_phq9_explanation(int(phq9_result))
38
+ return "Hello, "+name+". The final score of the PHQ-9 test is "+str(phq9_result)+'. ' +specialist_text
39
+
40
+ options = ['Never', 'Some days', 'More than half the time', 'All the time']
41
+ gender_options = ['Male', 'Female', 'Non-binary', 'Prefer not to specify']
42
+
43
+ with gr.Row():
44
+ gr.Markdown("![logo](https://umasalud.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Flogo.72bd5597.webp&w=64&q=75)")
45
+
46
+ with gr.Accordion("Personal Information (click here for more information)", open=False):
47
+ gr.Markdown("This information will be used for an anonymous analysis of the overall situation of our patients. We aim to provide the best solutions for our users.")
48
+
49
+ with gr.Column():
50
+ name = gr.Textbox(label='Name:')
51
+ email = gr.Textbox(label='Email:')
52
+ age = gr.Textbox(label='Age:')
53
+ gender = gr.Dropdown(gender_options, label='Gender:')
54
+
55
+ with gr.Row():
56
+ gr.Markdown("The following questions seek to provide us with information about your situation. Over the past two weeks, how often were you affected by the following situations?")
57
+
58
+ with gr.Column():
59
+ drop1 = gr.Dropdown(options, label='Little interest or pleasure in doing things.')
60
+ drop2 = gr.Dropdown(options, label='Feeling down, depressed, or hopeless.')
61
+ drop3 = gr.Dropdown(options, label='Trouble falling asleep or sleeping too much.')
62
+ drop4 = gr.Dropdown(options, label='Feeling tired or having little energy.')
63
+ drop5 = gr.Dropdown(options, label='Thoughts of suicide or self-harm.')
64
+ drop6 = gr.Dropdown(options, label='Feeling bad about yourself or feeling like a failure or letting your family down.')
65
+ drop7 = gr.Dropdown(options, label='Trouble concentrating on things, such as reading or watching television.')
66
+ drop8 = gr.Dropdown(options, label='Moving or speaking slowly that others could have noticed. Or the opposite, being so fidgety that you move around more than usual.')
67
+ drop9 = gr.Dropdown(options, label='Poor appetite or overeating.')
68
+
69
+ with gr.Column():
70
+ gr.Markdown("Regarding technology-based solutions:")
71
+ checkbox1 = gr.Checkbox(value=False, label="I would like to have an informative chatbot to learn about depression and other mental health issues.")
72
+ checkbox2 = gr.Checkbox(value=False, label="I would like to have a chatbot to receive suggestions on how to feel better.")
73
+ checkbox3 = gr.Checkbox(value=False, label="I would like to have a chat with a specialist to ask questions about my health.")
74
+ checkbox4 = gr.Checkbox(value=False, label="I would be willing to pay for some of these developed solutions.")
75
+
76
+ with gr.Column():
77
+ gr.Markdown("Finally, we ask you to contribute by recording a 30-second video telling us how you have been feeling lately or about any topic you prefer to discuss.\n\n-Find a clear background\n\n-Choose a well-lit location\n\n-No glasses or hair on your face\n\n-Position the phone at face level\n\nThis information will be used for an anonymous analysis of the overall situation of our patients.")
78
+ video = gr.components.Video(shape=(640, 480), source="webcam", mirror_webcam=False, include_audio=True)
79
+
80
+ with gr.Row():
81
+ btn = gr.Button("Finish Survey.")
82
+
83
+ with gr.Row():
84
+ gr.Markdown('Thank you very much for completing the survey. We will soon let you know about our new solutions!')
85
+ out = gr.Markdown()
86
+
87
+ btn.click(get_user_data, inputs=[name, email, age, gender, drop1, drop2, drop3, drop4, drop5, drop6, drop7, drop8, drop9, checkbox1, checkbox2, checkbox3, checkbox4], outputs=[out])
88
+
89
+ demo.launch()