Files changed (1) hide show
  1. app.py +240 -0
app.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+
5
+ # Inputs for UI
6
+
7
+ with gr.Blocks(
8
+ theme=gr.themes.Soft(
9
+ primary_hue=gr.themes.colors.zinc,
10
+ neutral_hue=gr.themes.colors.slate,
11
+ )
12
+ ) as demo:
13
+ age = (
14
+ gr.Number(
15
+ label="Age",
16
+ info="Age of client at admission",
17
+ minimum=0,
18
+ maximum=100,
19
+ ),
20
+ )
21
+ race = (
22
+ gr.Dropdown(
23
+ [
24
+ "Alaska Native (Aleut, Eskimo, Indian)",
25
+ "American Indian (other than Alaska Native)",
26
+ "Asian or Pacific Islander",
27
+ "Black or African American",
28
+ "White",
29
+ "Asian",
30
+ "Other single race",
31
+ "Two or more races",
32
+ "Native Hawaiian or Other Pacific Islander",
33
+ ],
34
+ label="Race",
35
+ ),
36
+ )
37
+ education = (
38
+ gr.Dropdown(
39
+ [
40
+ "Less than one school grade, no schooling, nursery school, or kindergarten to Grade 8",
41
+ "Grades 9 to 11",
42
+ "Grade 12 (or GED)",
43
+ "1-3 years of college, university, or vocational school",
44
+ "4 years of college, university, BA/BS, some postgraduate study, or more",
45
+ ],
46
+ label="Education",
47
+ info="The highest school grade completed for adults or children not attending school, or current school grade for school-age children (3-17 years old) attending school",
48
+ ),
49
+ )
50
+ marital = (
51
+ gr.Dropdown(
52
+ ["Never married", "Now married", "Separated", "Divorced, widowed"],
53
+ label="Marital Status",
54
+ info="Client's marital status, compatible with U.S. Census categories",
55
+ ),
56
+ )
57
+ primary_income = (
58
+ gr.Dropdown(
59
+ [
60
+ "Wages/salary",
61
+ "Public assistance",
62
+ "Retirement/pension, disability",
63
+ "Other",
64
+ "None",
65
+ ],
66
+ label="Primary Source of Income/Support",
67
+ info="Client's principal source of financial support (for children younger than 18 years old, the primary parental source of income/support)",
68
+ ),
69
+ )
70
+ health_insurance = (
71
+ gr.Dropdown(
72
+ [
73
+ "Private insurance, Blue Cross/Blue Shield, HMO",
74
+ "Medicaid",
75
+ "Medicare, other (e.g. TRICARE, CHAMPUS)",
76
+ "None",
77
+ ],
78
+ label="Health Insurance",
79
+ info="Client's health insurance at admission",
80
+ ),
81
+ )
82
+ primary_substance = (
83
+ gr.Dropdown(
84
+ [
85
+ "None",
86
+ "Alcohol",
87
+ "Cocaine/crack",
88
+ "Marijuana/hashish: Includes THC and any other cannabis sativa preparations",
89
+ "Heroin",
90
+ "Non-prescription methadone",
91
+ "Other opiates and synthetics: Includes buprenorphine, butorphanol, codeine, hydrocodone, hydromorphone, meperidine,morphine, opium, oxycodone, pentazocine, propoxyphene, tramadol, and other narcotic analgesics, opiates, or synthetics",
92
+ "PCP: Phencyclidine",
93
+ "Hallucinogens: Includes LSD, DMT, mescaline, peyote, psilocybin, STP, and other hallucinogens",
94
+ "Methamphetamine/speed",
95
+ "Other amphetamines: Includes amphetamines, MDMA, ‘bath salts’, phenmetrazine, and other amines and related drugs",
96
+ "Other stimulants: Includes methylphenidate and any other stimulants",
97
+ "Benzodiazepines: Includes alprazolam, chlordiazepoxide, clonazepam, clorazepate, diazepam, flunitrazepam,flurazepam, halazepam, lorazepam, oxazepam, prazepam, temazepam, triazolam, and other unspecified benzodiazepines",
98
+ "Other tranquilizers: Includes meprobamate, and other non-benzodiazepine tranquilizers",
99
+ "Barbiturates: Includes amobarbital, pentobarbital, phenobarbital, secobarbital, etc.",
100
+ "Other sedatives or hypnotics: Includes chloral hydrate, ethchlorvynol, glutethimide, methaqualone, and othernon-barbiturate sedatives and hypnotics",
101
+ "Inhalants: Includes aerosols; chloroform, ether, nitrous oxide and other anesthetics; gasoline; glue; nitrites; paint thinnerand other solvents; and other inappropriately inhaled products",
102
+ "Over-the-counter medications: Includes aspirin, dextromethorphan and other cough syrups, diphenhydramine and otheranti-histamines, ephedrine, sleep aids, and any other legally obtained, non-prescription medication",
103
+ "Other drugs: Includes diphenylhydantoin/phenytoin, GHB/GBL, ketamine, synthetic cannabinoid 'Spice', carisoprodol(Soma), and other drugs",
104
+ ],
105
+ label="Primary Substance Use",
106
+ info="Client's primary substance use at admission",
107
+ ),
108
+ )
109
+ first_use = (
110
+ gr.Number(
111
+ label="Age at First Use of Primary Substance",
112
+ info="For alcohol use, this is the age of first intoxication",
113
+ minimum=0,
114
+ maximum=100,
115
+ ),
116
+ )
117
+ frequency = (
118
+ gr.Radio(
119
+ ["No use in the past month", "Some use", "Daily use"],
120
+ label="Frequency of Primary Substance Use",
121
+ ),
122
+ )
123
+ days_waiting = (
124
+ gr.Number(
125
+ label="Days Waiting to Enter Substance Use Treatment",
126
+ info="Number of days from the first contact or request for substance use treatment service until the client was admitted and the first clinical substance use treatment service was provided",
127
+ minimum=0,
128
+ ),
129
+ )
130
+ arrests = (
131
+ gr.Radio(
132
+ ["None", "Once", "Two or more times"],
133
+ label="Arrests",
134
+ info="Number of arrests in the 30 days prior to admission",
135
+ ),
136
+ )
137
+ attendance = (
138
+ gr.Dropdown(
139
+ [
140
+ "No attendance",
141
+ "1-3 times in the past month",
142
+ "4-7 times in the past month",
143
+ "8-30 times in the past month",
144
+ "Some attendance, frequency is unknown",
145
+ ],
146
+ label="Attendance at Substance Use Self-help Groups in Past 30 Days",
147
+ info="Frequency of attendance at a substance use self-help group in the 30 days prior to the reference date (the date of admission). Includes Alcoholics Anonymous (AA), Narcotics Anonymous (NA), and other self-help/mutual support groups focused on recovery from substance use and dependence",
148
+ ),
149
+ )
150
+ services = (
151
+ gr.Dropdown(
152
+ [
153
+ "Detox, 24-hour, hospital inpatient",
154
+ "Detox, 24-hour, free-standing residential",
155
+ "Rehab/residential, hospital (non-detox)",
156
+ "Rehab/residential, short term (30 days or fewer)",
157
+ "Rehab/residential, long term (more than 30 days)",
158
+ "Ambulatory, intensive outpatient",
159
+ "Ambulatory, non-intensive outpatient",
160
+ "Ambulatory, detoxification",
161
+ ],
162
+ label="Type of Treatment Service/Setting",
163
+ info="Type of treatment service or treatment setting in which the client is placed at the time of admission or transfer",
164
+ ),
165
+ )
166
+ co_occuring = (
167
+ gr.Radio(
168
+ ["Yes", "No"], label="Co-occurring Mental and Substance Use Disorders"
169
+ ),
170
+ )
171
+
172
+
173
+ def conversion():
174
+ # Convert inputs to model inputs
175
+ if age >= 12 or age <= 14:
176
+ age = 1
177
+ elif age >= 15 or age <= 17:
178
+ age = 2
179
+ elif age >= 18 or age <= 20:
180
+ age = 3
181
+ elif age >= 21 or age <= 24:
182
+ age = 4
183
+ elif age >= 25 or age <= 29:
184
+ age = 5
185
+ elif age >= 30 or age <= 34:
186
+ age = 6
187
+ elif age >= 35 or age <= 39:
188
+ age = 7
189
+ elif age >= 40 or age <= 44:
190
+ age = 8
191
+ elif age >= 45 or age <= 49:
192
+ age = 9
193
+ elif age >= 50 or age <= 54:
194
+ age = 10
195
+ elif age >= 55 or age <= 64:
196
+ age = 11
197
+ else:
198
+ age = 12
199
+
200
+ race = race.index() + 1
201
+ education = education.index() + 1
202
+ marital = marital.index() + 1
203
+ primary_income = primary_income.index() + 1
204
+ health_insurance = health_insurance.index() + 1
205
+ primary_substance = primary_substance.index() + 1
206
+ frequency = frequency(type="index") + 1
207
+
208
+ if days_waiting == 0:
209
+ days_waiting = 0
210
+ elif days_waiting >= 1 or days_waiting <= 7:
211
+ days_waiting = 1
212
+ elif days_waiting >= 8 or days_waiting <= 14:
213
+ days_waiting = 2
214
+ elif days_waiting >= 15 or days_waiting <= 30:
215
+ days_waiting = 3
216
+ else:
217
+ days_waiting = 4
218
+
219
+ arrests = arrests(type="index")
220
+ attendance = attendance.index() + 1
221
+ services = services.index() + 1
222
+
223
+ if first_use <= 11:
224
+ first_use = 1
225
+ elif first_use >= 12 or first_use <= 14:
226
+ first_use = 2
227
+ elif first_use >= 15 or first_use <= 17:
228
+ first_use = 3
229
+ elif first_use >= 18 or first_use <= 20:
230
+ first_use = 4
231
+ elif first_use >= 21 or first_use <= 24:
232
+ first_use = 5
233
+ elif first_use >= 25 or first_use <= 29:
234
+ first_use = 6
235
+ else:
236
+ first_use = 7
237
+
238
+
239
+ if __name__ == "__main__":
240
+ demo.launch()