File size: 32,437 Bytes
9b6df61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6924281
9b6df61
 
 
6924281
9b6df61
 
 
fb3bf97
9b6df61
 
 
6924281
9b6df61
 
 
 
 
 
6924281
9b6df61
 
 
6924281
9b6df61
 
 
fb3bf97
9b6df61
 
 
6924281
9b6df61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6924281
 
 
 
9b6df61
 
 
6924281
 
 
9b6df61
 
 
 
 
 
 
 
6924281
 
 
9b6df61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6924281
9b6df61
 
 
 
61a6b24
 
6924281
9b6df61
6924281
61a6b24
 
 
9b6df61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85042ad
 
 
 
 
 
 
9b6df61
 
 
85042ad
 
 
 
 
 
 
9b6df61
 
 
 
85042ad
 
 
 
 
 
9b6df61
 
 
 
85042ad
 
 
 
 
 
9b6df61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6924281
9b6df61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6924281
9b6df61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7cc90d3
9b6df61
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
import os
HF_TOKEN = os.getenv("HF_TOKEN")

import numpy as np
import pandas as pd
import sklearn
import sklearn.metrics
from math import sqrt
from scipy import stats as st
from matplotlib import pyplot as plt

from sklearn.linear_model import LogisticRegression

import shap
import gradio as gr
import random
import re
import textwrap
from datasets import load_dataset


#Read data training data.

x1 = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="los_data_train.csv", use_auth_token = HF_TOKEN)
x1 = pd.DataFrame(x1['train'])
x1 = x1.iloc[:, 1:]

x2 = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="discharge_data_train.csv", use_auth_token = HF_TOKEN)
x2 = pd.DataFrame(x2['train'])
x2 = x2.iloc[:, 1:]

x3 = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="readmission_data_train.csv", use_auth_token = HF_TOKEN)
x3 = pd.DataFrame(x3['train'])
x3 = x3.iloc[:, 1:]

x4 = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="complications_data_train.csv", use_auth_token = HF_TOKEN)
x4 = pd.DataFrame(x4['train'])
x4 = x4.iloc[:, 1:]


#Read validation data.

x1_valid = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="los_data_valid.csv", use_auth_token = HF_TOKEN)
x1_valid = pd.DataFrame(x1_valid['train'])
x1_valid = x1_valid.iloc[:, 1:]

x2_valid = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="discharge_data_valid.csv", use_auth_token = HF_TOKEN)
x2_valid = pd.DataFrame(x2_valid['train'])
x2_valid = x2_valid.iloc[:, 1:]

x3_valid = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="readmission_data_valid.csv", use_auth_token = HF_TOKEN)
x3_valid = pd.DataFrame(x3_valid['train'])
x3_valid = x3_valid.iloc[:, 1:]

x4_valid = load_dataset("mertkarabacak/NSQIP-ACDF", data_files="complications_data_valid.csv", use_auth_token = HF_TOKEN)
x4_valid = pd.DataFrame(x4_valid['train'])
x4_valid = x4_valid.iloc[:, 1:]


#Define feature names.
f1_names = list(x1.columns)
f1_names = [f1.replace('__', ' - ') for f1 in f1_names]
f1_names = [f1.replace('_', ' ') for f1 in f1_names]

f2_names = list(x2.columns)
f2_names = [f2.replace('__', ' - ') for f2 in f2_names]
f2_names = [f2.replace('_', ' ') for f2 in f2_names]

f3_names = list(x3.columns)
f3_names = [f3.replace('__', ' - ') for f3 in f3_names]
f3_names = [f3.replace('_', ' ') for f3 in f3_names]

f4_names = list(x4.columns)
f4_names = [f4.replace('__', ' - ') for f4 in f4_names]
f4_names = [f4.replace('_', ' ') for f4 in f4_names]


#Prepare training data for the outcome 1 (prolonged LOS).
y1 = x1.pop('OUTCOME')

#Prepare validation data for the outcome 1 (prolonged LOS).
y1_valid = x1_valid.pop('OUTCOME')

#Prepare training data for the outcome 2 (non-home discharges).
y2 = x2.pop('OUTCOME')

#Prepare validation data for the outcome 2 (non-home discharges).
y2_valid = x2_valid.pop('OUTCOME')

#Prepare training data for the outcome 3 (30-day readmissions).
y3 = x3.pop('OUTCOME')

#Prepare validation data for the outcome 3 (30-day readmissions).
y3_valid = x3_valid.pop('OUTCOME')

#Prepare training data for the outcome 4 (unplanned reoperations).
y4 = x4.pop('OUTCOME')

#Prepare validation data for the outcome 4 (unplanned reoperations).
y4_valid = x4_valid.pop('OUTCOME')


#Assign hyperparameters.

y1_params =  {'criterion': 'gini', 'max_features': 'sqrt', 'max_depth': 53, 'n_estimators': 200, 'min_samples_leaf': 1, 'min_samples_split': 2, 'random_state': 31}
y2_params =  {'criterion': 'gini', 'max_features': 'sqrt', 'max_depth': 53, 'n_estimators': 200, 'min_samples_leaf': 1, 'min_samples_split': 2, 'random_state': 31}
y3_params =  {'criterion': 'gini', 'max_features': 'sqrt', 'max_depth': 53, 'n_estimators': 200, 'min_samples_leaf': 1, 'min_samples_split': 2, 'random_state': 31}
y4_params =  {'criterion': 'gini', 'max_features': 'sqrt', 'max_depth': 35, 'n_estimators': 2000, 'min_samples_leaf': 1, 'min_samples_split': 4, 'random_state': 31}

#Training models.

from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(**y1_params)
y1_model = rf

y1_model = y1_model.fit(x1, y1)
y1_explainer = shap.Explainer(y1_model.predict, x1)
y1_calib_probs = y1_model.predict_proba(x1_valid)
y1_calib_model = LogisticRegression()
y1_calib_model = y1_calib_model.fit(y1_calib_probs, y1_valid)


from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(**y2_params)
y2_model = rf

y2_model = y2_model.fit(x2, y2)
y2_explainer = shap.Explainer(y2_model.predict, x2)
y2_calib_probs = y2_model.predict_proba(x2_valid)
y2_calib_model = LogisticRegression()
y2_calib_model = y2_calib_model.fit(y2_calib_probs, y2_valid)


from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(**y3_params)
y3_model = rf

y3_model = y3_model.fit(x3, y3)
y3_explainer = shap.Explainer(y3_model.predict, x3)
y3_calib_probs = y3_model.predict_proba(x3_valid)
y3_calib_model = LogisticRegression()
y3_calib_model = y3_calib_model.fit(y3_calib_probs, y3_valid)


from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(**y4_params)
y4_model = rf

y4_model = y4_model.fit(x4, y4)
y4_explainer = shap.Explainer(y4_model.predict, x4)
y4_calib_probs = y4_model.predict_proba(x4_valid)
y4_calib_model = LogisticRegression()
y4_calib_model = y4_calib_model.fit(y4_calib_probs, y4_valid)


output_y1 = (
    """          
        <br/>
        <center>The predicted risk of prolonged length of stay:</center>
        <br/>
        <center><h1>{:.2f}%</h1></center>
"""
)

output_y2 = (
    """          
        <br/>        
        <center>The predicted risk of non-home discharge:</center>
        <br/>        
        <center><h1>{:.2f}%</h1></center>
"""
)

output_y3 = (
    """          
        <br/>        
        <center>The predicted risk of 30-day readmission:</center>
        <br/>        
        <center><h1>{:.2f}%</h1></center>
"""
)

output_y4 = (
    """          
        <br/>        
        <center>The predicted risk of major complications:</center>
        <br/>        
        <center><h1>{:.2f}%</h1></center>
"""
)


#Define predict for y1.
def y1_predict(*args):
    df1 = pd.DataFrame([args], columns=x1.columns)
    pos_pred = y1_model.predict_proba(df1)
    pos_pred = y1_calib_model.predict_proba(pos_pred)
    prob = pos_pred[0][1]
    output = output_y1.format(prob * 100)
    return output

#Define predict for y2.
def y2_predict(*args):
    df2 = pd.DataFrame([args], columns=x2.columns)
    pos_pred = y2_model.predict_proba(df2)
    pos_pred = y2_calib_model.predict_proba(pos_pred)        
    prob = pos_pred[0][1]
    output = output_y2.format(prob * 100)
    return output

#Define predict for y3.
def y3_predict(*args):
    df3 = pd.DataFrame([args], columns=x3.columns)
    pos_pred = y3_model.predict_proba(df3)
    pos_pred = y3_calib_model.predict_proba(pos_pred)            
    prob = pos_pred[0][1]
    output = output_y3.format(prob * 100)
    return output

#Define predict for y4.
def y4_predict(*args):
    df4 = pd.DataFrame([args], columns=x4.columns)
    pos_pred = y4_model.predict_proba(df4)
    pos_pred = y4_calib_model.predict_proba(pos_pred)            
    prob = pos_pred[0][1]
    output = output_y4.format(prob * 100)
    return output


#Define function for wrapping feature labels.
def wrap_labels(ax, width, break_long_words=False):
    labels = []
    for label in ax.get_yticklabels():
        text = label.get_text()
        labels.append(textwrap.fill(text, width=width, break_long_words=break_long_words))
    ax.set_yticklabels(labels, rotation=0)
    

#Define interpret for y1.
def y1_interpret(*args):
    df1 = pd.DataFrame([args], columns=x1.columns)
    shap_values1 = y1_explainer(df1).values
    shap_values1 = np.abs(shap_values1)
    shap.bar_plot(shap_values1[0], max_display = 10, show = False, feature_names = f1_names)
    fig = plt.gcf()
    ax = plt.gca()
    wrap_labels(ax, 20)
    ax.figure
    plt.tight_layout()
    fig.set_figheight(7)
    fig.set_figwidth(9)
    plt.xlabel("SHAP value (impact on model output)", fontsize =12, fontweight = 'heavy', labelpad = 8)
    plt.tick_params(axis="y",direction="out", labelsize = 12)
    plt.tick_params(axis="x",direction="out", labelsize = 12)
    return fig

#Define interpret for y2.
def y2_interpret(*args):
    df2 = pd.DataFrame([args], columns=x2.columns)
    shap_values2 = y2_explainer(df2).values
    shap_values2 = np.abs(shap_values2)
    shap.bar_plot(shap_values2[0], max_display = 10, show = False, feature_names = f2_names)
    fig = plt.gcf()
    ax = plt.gca()
    wrap_labels(ax, 20)
    ax.figure
    plt.tight_layout()
    fig.set_figheight(7)
    fig.set_figwidth(9)
    plt.xlabel("SHAP value (impact on model output)", fontsize =12, fontweight = 'heavy', labelpad = 8)
    plt.tick_params(axis="y",direction="out", labelsize = 12)
    plt.tick_params(axis="x",direction="out", labelsize = 12)
    return fig

#Define interpret for y3.
def y3_interpret(*args):
    df3 = pd.DataFrame([args], columns=x3.columns)
    shap_values3 = y3_explainer(df3).values
    shap_values3 = np.abs(shap_values3)
    shap.bar_plot(shap_values3[0], max_display = 10, show = False, feature_names = f3_names)
    fig = plt.gcf()
    ax = plt.gca()
    wrap_labels(ax, 20)
    ax.figure
    plt.tight_layout()
    fig.set_figheight(7)
    fig.set_figwidth(9)
    plt.xlabel("SHAP value (impact on model output)", fontsize =12, fontweight = 'heavy', labelpad = 8)
    plt.tick_params(axis="y",direction="out", labelsize = 12)
    plt.tick_params(axis="x",direction="out", labelsize = 12)
    return fig

#Define interpret for y4.
def y4_interpret(*args):
    df4 = pd.DataFrame([args], columns=x4.columns)
    shap_values4 = y4_explainer(df4).values
    shap_values4 = np.abs(shap_values4)
    shap.bar_plot(shap_values4[0], max_display = 10, show = False, feature_names = f4_names)
    fig = plt.gcf()
    ax = plt.gca()
    wrap_labels(ax, 20)
    ax.figure
    plt.tight_layout()
    fig.set_figheight(7)
    fig.set_figwidth(9)
    plt.xlabel("SHAP value (impact on model output)", fontsize =12, fontweight = 'heavy', labelpad = 8)
    plt.tick_params(axis="y",direction="out", labelsize = 12)
    plt.tick_params(axis="x",direction="out", labelsize = 12)
    return fig


with gr.Blocks(title = "NSQIP-ACDF") as demo:
        
    gr.Markdown(
        """
    <br/>
    <center><h2>NOT FOR CLINICAL USE</h2><center>    
    <br/>    
    <center><h1>ACDF Outcomes</h1></center>
    <center><h2>Prediction Tool</h2></center>
    <br/>
    <center><h3>This web application should not be used to guide any clinical decisions.</h3><center>
    <br/>
    <center><i>The publication describing the details of this prediction tool will be posted here upon the acceptance of publication.</i><center>
        """
    )

    gr.Markdown(
        """
        <center><h3>Model Performances</h3></center>
          <div style="text-align:center;">
          <table style="width:100%;">
          <tr>
            <th>Outcome</th>
            <th>Algorithm</th>
            <th>Weighted Precision</th>
            <th>Weighted Recall</th>
            <th>Weighted AUPRC</th>
            <th>Balanced Accuracy</th>
            <th>AUROC</th>
            <th>Brier Score</th>
          </tr>
          <tr>
            <td>Prolonged LOS</td>
            <td>Random Forest</td>
            <td>0.878 (0.872 - 0.884)</td>
            <td>0.894 (0.888 - 0.900)</td>
            <td>0.473 (0.464 - 0.482)</td>
            <td>0.651 (0.642 - 0.660)</td>
            <td>0.776 (0.766 - 0.792)</td>
            <td>0.078 (0.073 - 0.083)</td>             
          </tr>
          <tr>
            <td>Non-home Discharges</td>
            <td>Random Forest</td>
            <td>0.961 (0.957 - 0.965)</td>
            <td>0.964 (0.961 - 0.967)</td>
            <td>0.402 (0.393 - 0.411)</td>
            <td>0.666 (0.657 - 0.675)</td>
            <td>0.846 (0.809 - 0.855)</td>
            <td>0.024 (0.021 - 0.027)</td>             
          </tr>
          <tr>
            <td>30-Day Readmissions</td>
            <td>Random Forest</td>
            <td>0.968 (0.965 - 0.971)</td>
            <td>0.971 (0.968 - 0.974)</td>
            <td>0.376 (0.367 - 0.385)</td>
            <td>0.674 (0.665 - 0.683)</td>
            <td>0.775 (0.731 - 0.791)</td>
            <td>0.022 (0.019 - 0.025)</td>             
          </tr>                        
          <tr>
            <td>Major Complications</td>
            <td>Random Forest</td>
            <td>0.983 (0.981 - 0.985)</td>
            <td>0.987 (0.985 - 0.989)</td>
            <td>0.276 (0.268 - 0.284)</td>
            <td>0.629 (0.620 - 0.638)</td>
            <td>0.747 (0.702 - 0.779)</td>
            <td>0.012 (0.010 - 0.014)</td>             
          </tr>        
        </table>
        </div>
        """
    )    

    with gr.Row():

        with gr.Column():

            Age = gr.Slider(label="Age", minimum = 18, maximum = 99, step = 1, value = 55)

            Sex = gr.Radio(label = "Sex", choices = ['Male', 'Female'], type = 'index', value = 'Male')
            
            Race = gr.Radio(label = "Race", choices = ['White', 'Black or African American', 'Asian', 'American Indian or Alaska Native', 'Native Hawaiian or Pacific Islander', 'Other/Unknown'], type = 'index', value = 'White')
            
            Hispanic_Ethnicity = gr.Radio(label = "Hispanic Ethnicity", choices = ['No', 'Yes', 'Unknown'], type = 'index', value = 'No')
            
            Height = gr.Slider(label = "Height (in meters)", minimum = 1, maximum = 2.5, step = 0.01, value = 1.75)
            
            Weight = gr.Slider(label = "Weight (in kilograms)", minimum = 20, maximum = 200, step = 1, value = 75)            
            
            Transfer_Status = gr.Radio(label = "Transfer Status", choices = ['Not transferred', 'Transferred', 'Unknown'], type = 'index', value = 'Not transferred')
            
            Current_Smoker_Status = gr.Radio(label = "Current Smoker Status", choices = ['No', 'Yes', 'Unknown'], type = 'index', value = 'No')   
            
            Diabetes_Mellitus_Requiring_Therapy = gr.Radio(label = "Diabetes Mellitus Requiring Therapy", choices = ['No', 'Yes',], type = 'index', value = 'No')   

            Dyspnea = gr.Radio(label = "Dyspnea", choices = ['No', 'Yes'], type = 'index', value = 'No')   

            Ventilator_Dependency = gr.Radio(label = "Ventilator Dependency", choices = ['No', 'Yes'], type = 'index', value = 'No')   
            
            History_of_Severe_COPD = gr.Radio(label = "History of Severe COPD", choices = ['No', 'Yes'], type = 'index', value = 'No')             

            Ascites_within_30_Days_Prior_to_Surgery = gr.Radio(label = "Ascites within 30 Days Prior to Surgery", choices = ['No', 'Yes'], type = 'index', value = 'No')   

            CHF_within_30_Days_Prior_to_Surgery = gr.Radio(label = "CHF within 30 Days Prior to Surgery", choices = ['No', 'Yes'], type = 'index', value = 'No')   

            Hypertension_Requiring_Medication = gr.Radio(label = "Hypertension Requiring Medication", choices = ['No', 'Yes'], type = 'index', value = 'No')

            Acute_Renal_Failure = gr.Radio(label = "Acute Renal Failure", choices = ['No', 'Yes'], type = 'index', value = 'No')   

            Currently_Requiring_or_on_Dialysis = gr.Radio(label = "Currently Requiring or on Dialysis", choices = ['No', 'Yes'], type = 'index', value = 'No')
            
            Disseminated_Cancer = gr.Radio(label = "Disseminated Cancer", choices = ['No', 'Yes'], type = 'index', value = 'No')   

            Open_Wound = gr.Radio(label = "Open Wound", choices = ['No', 'Yes'], type = 'index', value = 'No')   

            Steroid_or_Immunosuppressant_for_a_Chronic_Condition = gr.Radio(label = "Steroid/Immunosuppressant for a Chronic Condition", choices = ['No', 'Yes'], type = 'index', value = 'No')   
            
            Malnourishment = gr.Radio(label = "Malnourishment", choices = ['No', 'Yes'], type = 'index', value = 'No')   
            
            Bleeding_Disorder = gr.Radio(label = "Bleeding Disorder", choices = ['No', 'Yes'], type = 'index', value = 'No')              
            
            RBC_Transfusion_within_72_Hours_Prior_to_Surgery = gr.Radio(label = "RBC Transfusion within 72 Hours Prior to Surgery", choices = ['No', 'Yes'], type = 'index', value = 'No')   
                
            Functional_Status = gr.Radio(label = "Functional_Status", choices = ['Independent', 'Partially Dependent', 'Totally Dependent', 'Unknown'], type = 'index', value = 'Independent')   
            
            Preoperative_Serum_Sodium = gr.Slider(label="Preoperative Serum Sodium", minimum = 110, maximum = 150, step = 1, value = 135)
            
            Preoperative_Serum_BUN = gr.Slider(label="Preoperative Serum BUN", minimum = 0, maximum = 100, step = 1, value = 15)
            
            Preoperative_Serum_Creatinine = gr.Slider(label="Preoperative Serum Creatinine", minimum = 0, maximum = 20, step = 0.1, value = 0.9)
            
            Preoperative_WBC_Count = gr.Slider(label="Preoperative WBC Count (x1000)", minimum = 1, maximum = 50, step = 0.1, value = 5)
            
            Preoperative_Hematocrit = gr.Slider(label="Preoperative Hematocrit", minimum = 20, maximum = 70, step = 0.1, value = 45)
            
            Preoperative_Platelet_Count = gr.Slider(label="Preoperative Platelet Count (x1000)", minimum = 50, maximum = 1000, step = 1, value = 250)
            
            ASA_Classification = gr.Radio(label = "ASA Classification", choices = ['1-No Disturb', '2-Mild Disturb', '3-Severe Disturb',], type = 'index', value = '1-No Disturb')
            
            Surgical_Specialty = gr.Radio(label = "Surgical Specialty", choices = ['Neurosurgery', 'Orthopedic Surgery',], type = 'index', value = 'Neurosurgery')   
            
            Single_or_Multiple_Level_Surgery = gr.Radio(label = "Single or Multiple Level Surgery", choices = ['Single', 'Multiple',], type = 'index', value = 'Single')
                        
        with gr.Column():
            
            with gr.Box():
                
                gr.Markdown(
                    """
                    <center> <h2>Prolonged Length of Stay</h2> </center>
                    <br/>
                    <center> This model uses the Random Forest algorithm.</center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y1_predict_btn = gr.Button(value="Predict")
                
                label1 = gr.Markdown()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y1_interpret_btn = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot1 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
            with gr.Box():
                gr.Markdown(
                    """
                    <center> <h2>Non-home Discharges</h2> </center>
                    <br/>
                    <center> This model uses the Random Forest algorithm.</center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y2_predict_btn = gr.Button(value="Predict")
                
                label2 = gr.Markdown()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y2_interpret_btn = gr.Button(value="Explain")
                
                plot2 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
            with gr.Box():
                
                gr.Markdown(
                    """
                    <center> <h2>30-day Readmissions</h2> </center>
                    <br/>
                    <center> This model uses the Random Forest algorithm.</center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y3_predict_btn = gr.Button(value="Predict")
                
                label3 = gr.Markdown()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y3_interpret_btn = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot3 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )  

            with gr.Box():
                
                gr.Markdown(
                    """
                    <center> <h2>Major Complications</h2> </center>
                    <br/>
                    <center> This model uses the Random Forest algorithm.</center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y4_predict_btn = gr.Button(value="Predict")
                
                label4 = gr.Markdown()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y4_interpret_btn = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot4 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )  

           
                y1_predict_btn.click(
                    y1_predict,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                    outputs = [label1]
                )

                y2_predict_btn.click(
                    y2_predict,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                    outputs = [label2]
                )
                
                y3_predict_btn.click(
                    y3_predict,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                    outputs = [label3]
                )

                y4_predict_btn.click(
                    y4_predict,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                    outputs = [label4]
                )

                y1_interpret_btn.click(
                    y1_interpret,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                    outputs = [plot1],
                )
                
                y2_interpret_btn.click(
                    y2_interpret,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                    outputs = [plot2],
                )

                y3_interpret_btn.click(
                    y3_interpret,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                  outputs = [plot3],
                )

                y4_interpret_btn.click(
                    y4_interpret,
                    inputs = [Sex, Race, Hispanic_Ethnicity, Transfer_Status, Age, Surgical_Specialty, Height, Weight, Diabetes_Mellitus_Requiring_Therapy, Current_Smoker_Status, Dyspnea, Functional_Status, Ventilator_Dependency, History_of_Severe_COPD, Ascites_within_30_Days_Prior_to_Surgery, CHF_within_30_Days_Prior_to_Surgery, Hypertension_Requiring_Medication, Acute_Renal_Failure, Currently_Requiring_or_on_Dialysis, Disseminated_Cancer, Open_Wound, Steroid_or_Immunosuppressant_for_a_Chronic_Condition, Malnourishment, Bleeding_Disorder, RBC_Transfusion_within_72_Hours_Prior_to_Surgery, Preoperative_Serum_Sodium, Preoperative_Serum_BUN, Preoperative_Serum_Creatinine, Preoperative_WBC_Count, Preoperative_Hematocrit, Preoperative_Platelet_Count, ASA_Classification, Single_or_Multiple_Level_Surgery],
                  outputs = [plot4],
                )
                
    gr.Markdown(
                """    
                <center><h2>Disclaimer</h2>
                <center> 
                The American College of Surgeons National Surgical Quality Improvement Program and the hospitals participating in the ACS NSQIP are the source of the data used herein; they have not been verified and are not responsible for the statistical validity of the data analysis or the conclusions derived by the authors. The predictive tool located on this web page is for healthcare professionals' use only. This prediction tool should not be used in place of professional medical service for any disease or concern. Users of the prediction tool shouldn't base their decisions about their own health issues on the information presented here. You should ask any questions to your own doctor or another healthcare professional. The authors of the study mentioned above make no guarantees or representations, either express or implied, as to the completeness, timeliness, comparative or contentious nature, or utility of any information contained in or referred to in this prediction tool. The risk associated with using this prediction tool or the information in this predictive tool is not at all assumed by the authors. The information contained in the prediction tools may be outdated, not complete, or incorrect because health-related information is subject to frequent change and multiple confounders. No express or implied doctor-patient relationship is established by using the prediction tool. The prediction tools on this website are not validated by the authors. Users of the tool are not contacted by the authors, who also do not record any specific information about them. You are hereby advised to seek the advice of a doctor or other qualified healthcare provider before making any decisions, acting, or refraining from acting in response to any healthcare problem or issue you may be experiencing at any time, now or in the future. By using the prediction tool, you acknowledge and agree that neither the authors nor any other party are or will be liable or otherwise responsible for any decisions you make, actions you take, or actions you choose not to take as a result of using any information presented here.
                <br/>
                <h4>By using this tool, you accept all of the above terms.<h4/>
                </center>
                """
    )                
                
demo.launch()