File size: 85,057 Bytes
49e436b
 
d65e651
49e436b
 
 
 
 
 
 
 
 
 
13854f8
49e436b
 
 
843669a
49e436b
 
 
 
 
 
37833d2
b799b72
ba4e974
49e436b
f3a1bf5
49e436b
323e9bf
49e436b
323e9bf
ba4e974
 
323e9bf
ba4e974
323e9bf
ba4e974
 
323e9bf
ba4e974
323e9bf
ba4e974
 
056d8c9
ba4e974
323e9bf
ba4e974
49e436b
323e9bf
ba4e974
323e9bf
ba4e974
f3a1bf5
b799b72
ba4e974
ef2a626
 
ba4e974
 
ef2a626
 
ba4e974
 
ef2a626
 
ba4e974
 
ef2a626
 
ba4e974
 
ef2a626
 
b799b72
 
49e436b
 
 
 
 
 
 
323e9bf
 
 
 
49e436b
323e9bf
49e436b
 
323e9bf
49e436b
323e9bf
 
49e436b
323e9bf
49e436b
323e9bf
 
 
 
 
 
 
 
49e436b
323e9bf
 
 
49e436b
 
323e9bf
49e436b
323e9bf
 
49e436b
323e9bf
49e436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323e9bf
49e436b
f3a1bf5
49e436b
 
 
 
886f71b
49e436b
ba4e974
 
 
 
886f71b
ba4e974
 
 
 
 
886f71b
ba4e974
 
 
 
 
886f71b
ba4e974
 
 
 
 
886f71b
88d92ba
ba4e974
323e9bf
 
 
b3cb1d2
323e9bf
 
ba4e974
e7701fa
 
 
4fe7374
49e436b
 
323e9bf
e7701fa
ba4e974
 
e7701fa
 
 
 
ba4e974
e7701fa
 
 
323e9bf
ba4e974
e7701fa
 
 
323e9bf
49e436b
 
 
d59de8d
e7701fa
 
 
 
 
49e436b
 
e7701fa
 
 
 
 
 
49e436b
 
d59de8d
 
 
49e436b
 
 
d59de8d
 
 
e7701fa
d59de8d
13854f8
49e436b
ba4e974
 
d59de8d
 
e7701fa
ba4e974
 
 
d59de8d
 
 
ba4e974
 
 
d59de8d
 
 
ba4e974
 
 
d59de8d
 
 
 
 
ba4e974
 
 
 
d59de8d
 
e7701fa
ba4e974
 
 
d59de8d
 
 
ba4e974
 
 
d59de8d
 
 
ba4e974
 
 
d59de8d
 
 
 
 
ba4e974
 
 
 
d59de8d
 
e7701fa
ba4e974
 
 
d59de8d
9e1a964
d59de8d
ba4e974
 
 
d59de8d
 
 
ba4e974
 
 
d59de8d
 
 
 
 
ba4e974
 
 
 
d59de8d
 
e7701fa
ba4e974
 
 
d59de8d
 
 
ba4e974
 
 
d59de8d
 
 
ba4e974
 
 
d59de8d
 
 
 
 
ba4e974
 
49e436b
ba4e974
b799b72
 
 
 
ba4e974
b799b72
 
 
49e436b
 
ba4e974
 
d59de8d
ba4e974
 
 
 
 
 
2d99f73
ba4e974
 
ea471c6
 
 
ba4e974
49e436b
 
ba4e974
 
 
 
d59de8d
ba4e974
 
 
 
aa3c555
ba4e974
 
aa3c555
 
 
ba4e974
49e436b
 
ba4e974
 
d59de8d
ba4e974
d59de8d
49e436b
ba4e974
 
 
 
 
 
 
 
 
 
 
49e436b
 
ba4e974
 
d59de8d
ba4e974
d59de8d
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d59de8d
 
 
ba4e974
 
 
 
 
 
 
 
 
 
 
f3a1bf5
323e9bf
49e436b
 
 
ff5c1b0
18168d2
 
6423072
323e9bf
49e436b
 
323e9bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49e436b
 
 
 
 
 
fdeec0a
49e436b
 
 
 
 
 
 
 
 
4d84f3e
49e436b
6d9b18e
49e436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c4701f
49e436b
 
 
 
 
323e9bf
 
 
 
49e436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7621044
49e436b
 
 
 
 
 
4d84f3e
49e436b
 
 
7621044
 
 
49e436b
 
 
 
 
 
 
 
 
 
 
38e79b7
49e436b
6e1522d
49e436b
f67a1ad
49e436b
 
 
 
 
d8b3637
49e436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d84f3e
49e436b
3962b0c
49e436b
 
 
 
 
 
 
 
10d625f
f83b315
d2bdc3a
18168d2
323e9bf
f67a1ad
ba4e974
 
 
 
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
10d625f
257d3ea
c8437c5
257d3ea
2616a22
e508846
49e436b
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
 
 
 
 
 
 
 
 
 
18168d2
f67a1ad
 
ba4e974
 
 
 
 
c8437c5
 
 
 
 
 
 
ff5c1b0
c8437c5
 
 
 
 
 
 
49e436b
ba4e974
c8437c5
 
 
 
 
 
 
ff5c1b0
c8437c5
 
 
 
 
 
 
ba4e974
 
 
 
18168d2
323e9bf
f67a1ad
ba4e974
 
 
 
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
 
 
 
 
 
 
 
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
 
 
 
 
 
49e436b
ba4e974
 
 
18168d2
323e9bf
f67a1ad
ba4e974
691f2cf
ba4e974
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
 
 
 
 
 
 
 
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
 
 
 
 
 
 
 
 
 
18168d2
323e9bf
f67a1ad
ba4e974
 
 
 
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
 
 
 
 
 
 
 
323e9bf
ba4e974
 
 
 
 
 
 
ff5c1b0
ba4e974
 
 
 
 
 
 
323e9bf
 
 
ff5c1b0
49e436b
 
ba4e974
 
323e9bf
ff5c1b0
49e436b
ba4e974
323e9bf
 
 
ff5c1b0
49e436b
 
323e9bf
 
 
ff5c1b0
ba4e974
 
323e9bf
 
 
ff5c1b0
49e436b
 
323e9bf
 
 
ff5c1b0
49e436b
ba4e974
 
 
323e9bf
ff5c1b0
ba4e974
49e436b
323e9bf
 
 
ff5c1b0
ba4e974
 
323e9bf
 
 
ff5c1b0
ba4e974
 
323e9bf
 
 
ff5c1b0
49e436b
323e9bf
 
 
 
 
 
 
 
 
 
 
 
 
49e436b
33bee46
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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
import os
HF_TOKEN = os.getenv("HF_TOKEN")

import numpy as np
import pandas as pd
import sklearn
import sklearn.metrics
from sklearn.metrics import roc_auc_score, roc_curve, precision_recall_curve, auc, precision_score, recall_score, f1_score, classification_report, accuracy_score, confusion_matrix, ConfusionMatrixDisplay, matthews_corrcoef
from sklearn.model_selection import train_test_split
from sklearn.calibration import calibration_curve
from math import sqrt
from scipy import stats as st
from random import randrange
from matplotlib import pyplot as plt
import xgboost as xgb
import lightgbm as lgb
import catboost as cb
from catboost import Pool
from sklearn.ensemble import RandomForestClassifier
import optuna
from optuna.samplers import TPESampler
import shap
import gradio as gr
import random
import re
import textwrap
from datasets import load_dataset


#Read data.
x1 = load_dataset("mertkarabacak/TQP-atEDH", data_files="mortality_data_train.csv", use_auth_token = HF_TOKEN)
x1 = pd.DataFrame(x1['train'])
variables1 = ['Age', 'Sex', 'Ethnicity', 'Weight', 'Height', 'Systolic_Blood_Pressure', 'Pulse_Rate', 'Supplemental_Oxygen', 'Pulse_Oximetry', 'Respiratory_Assistance', 'Respiratory_Rate', 'Temperature', 'GCS__Eye', 'GCS__Verbal', 'GCS__Motor', 'Total_GCS', 'Pupillary_Response', 'Midline_Shift', 'Bleeding_Localization', 'Bleeding_Size', 'Current_Smoker', 'Alcohol_Use_Disorder', 'Substance_Abuse_Disorder', 'Diabetes_Mellitus', 'Hypertension', 'Congestive_Heart_Failure', 'History_of_Myocardial_Infarction', 'Angina_Pectoris', 'History_of_Cerebrovascular_Accident', 'Peripheral_Arterial_Disease', 'Chronic_Obstructive_Pulmonary_Disease', 'Chronic_Renal_Failure', 'Cirrhosis', 'Bleeding_Disorder', 'Disseminated_Cancer', 'Currently_Receiving_Chemotherapy_for_Cancer', 'Dementia', 'Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder', 'Mental_or_Personality_Disorder', 'Ability_to_Complete_AgeAppropriate_ADL', 'Pregnancy', 'Anticoagulant_Therapy', 'Steroid_Use', 'Days_from_Incident_to_ED_or_Hospital_Arrival', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', 'WorkRelated', 'Blood_Transfusion', 'Neurosurgical_Intervention', 'Alcohol_Screen', 'Alcohol_Screen_Result', 'Drug_Screen__Amphetamine', 'Drug_Screen__Barbiturate', 'Drug_Screen__Benzodiazepines', 'Drug_Screen__Cannabinoid', 'Drug_Screen__Cocaine', 'Drug_Screen__MDMA_or_Ecstasy', 'Drug_Screen__Methadone', 'Drug_Screen__Methamphetamine', 'Drug_Screen__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment', 'Race', 'Protective_Device', 'Cerebral_Monitoring', 'OUTCOME']
x1 = x1[variables1]

x2 = load_dataset("mertkarabacak/TQP-atEDH", data_files="discharge_data_train.csv", use_auth_token = HF_TOKEN)
x2 = pd.DataFrame(x2['train'])
variables2= ['Age', 'Sex', 'Ethnicity', 'Weight', 'Height', 'Systolic_Blood_Pressure', 'Pulse_Rate', 'Supplemental_Oxygen', 'Pulse_Oximetry', 'Respiratory_Assistance', 'Respiratory_Rate', 'Temperature', 'GCS__Eye', 'GCS__Verbal', 'GCS__Motor', 'Total_GCS', 'Pupillary_Response', 'Midline_Shift', 'Bleeding_Localization', 'Bleeding_Size', 'Current_Smoker', 'Alcohol_Use_Disorder', 'Substance_Abuse_Disorder', 'Diabetes_Mellitus', 'Hypertension', 'Congestive_Heart_Failure', 'History_of_Myocardial_Infarction', 'Angina_Pectoris', 'History_of_Cerebrovascular_Accident', 'Peripheral_Arterial_Disease', 'Chronic_Obstructive_Pulmonary_Disease', 'Chronic_Renal_Failure', 'Cirrhosis', 'Bleeding_Disorder', 'Disseminated_Cancer', 'Currently_Receiving_Chemotherapy_for_Cancer', 'Dementia', 'Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder', 'Mental_or_Personality_Disorder', 'Ability_to_Complete_AgeAppropriate_ADL', 'Pregnancy', 'Anticoagulant_Therapy', 'Steroid_Use', 'Days_from_Incident_to_ED_or_Hospital_Arrival', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', 'WorkRelated', 'Blood_Transfusion', 'Neurosurgical_Intervention', 'Alcohol_Screen', 'Alcohol_Screen_Result', 'Drug_Screen__Amphetamine', 'Drug_Screen__Barbiturate', 'Drug_Screen__Benzodiazepines', 'Drug_Screen__Cannabinoid', 'Drug_Screen__Cocaine', 'Drug_Screen__MDMA_or_Ecstasy', 'Drug_Screen__Methadone', 'Drug_Screen__Methamphetamine', 'Drug_Screen__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment', 'Race', 'Protective_Device', 'Cerebral_Monitoring', 'OUTCOME']
x2 = x2[variables2]

x3 = load_dataset("mertkarabacak/TQP-atEDH", data_files="los_data_train.csv", use_auth_token = HF_TOKEN)
x3 = pd.DataFrame(x3['train'])
variables3 = ['Age', 'Sex', 'Ethnicity', 'Weight', 'Height', 'Systolic_Blood_Pressure', 'Pulse_Rate', 'Supplemental_Oxygen', 'Pulse_Oximetry', 'Respiratory_Assistance', 'Respiratory_Rate', 'Temperature', 'GCS__Eye', 'GCS__Verbal', 'GCS__Motor', 'Total_GCS', 'Pupillary_Response', 'Midline_Shift', 'Bleeding_Localization', 'Bleeding_Size', 'Current_Smoker', 'Alcohol_Use_Disorder', 'Substance_Abuse_Disorder', 'Diabetes_Mellitus', 'Hypertension', 'Congestive_Heart_Failure', 'History_of_Myocardial_Infarction', 'Angina_Pectoris', 'History_of_Cerebrovascular_Accident', 'Peripheral_Arterial_Disease', 'Chronic_Obstructive_Pulmonary_Disease', 'Chronic_Renal_Failure', 'Cirrhosis', 'Bleeding_Disorder', 'Disseminated_Cancer', 'Currently_Receiving_Chemotherapy_for_Cancer', 'Dementia', 'Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder', 'Mental_or_Personality_Disorder', 'Ability_to_Complete_AgeAppropriate_ADL', 'Pregnancy', 'Anticoagulant_Therapy', 'Steroid_Use', 'Days_from_Incident_to_ED_or_Hospital_Arrival', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', 'WorkRelated', 'Blood_Transfusion', 'Neurosurgical_Intervention', 'Alcohol_Screen', 'Alcohol_Screen_Result', 'Drug_Screen__Amphetamine', 'Drug_Screen__Barbiturate', 'Drug_Screen__Benzodiazepines', 'Drug_Screen__Cannabinoid', 'Drug_Screen__Cocaine', 'Drug_Screen__MDMA_or_Ecstasy', 'Drug_Screen__Methadone', 'Drug_Screen__Methamphetamine', 'Drug_Screen__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment', 'Race', 'Protective_Device', 'Cerebral_Monitoring', 'OUTCOME']
x3 = x3[variables3]

x4 = load_dataset("mertkarabacak/TQP-atEDH", data_files="iculos_data_train.csv", use_auth_token = HF_TOKEN)
x4 = pd.DataFrame(x4['train'])
variables4 = ['Age', 'Sex', 'Ethnicity', 'Weight', 'Height', 'Systolic_Blood_Pressure', 'Pulse_Rate', 'Supplemental_Oxygen', 'Pulse_Oximetry', 'Respiratory_Assistance', 'Respiratory_Rate', 'Temperature', 'GCS__Eye', 'GCS__Verbal', 'GCS__Motor', 'Total_GCS', 'Pupillary_Response', 'Midline_Shift', 'Bleeding_Localization', 'Bleeding_Size', 'Current_Smoker', 'Alcohol_Use_Disorder', 'Substance_Abuse_Disorder', 'Diabetes_Mellitus', 'Hypertension', 'Congestive_Heart_Failure', 'History_of_Myocardial_Infarction', 'Angina_Pectoris', 'History_of_Cerebrovascular_Accident', 'Peripheral_Arterial_Disease', 'Chronic_Obstructive_Pulmonary_Disease', 'Chronic_Renal_Failure', 'Cirrhosis', 'Bleeding_Disorder', 'Disseminated_Cancer', 'Currently_Receiving_Chemotherapy_for_Cancer', 'Dementia', 'Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder', 'Mental_or_Personality_Disorder', 'Ability_to_Complete_AgeAppropriate_ADL', 'Pregnancy', 'Anticoagulant_Therapy', 'Steroid_Use', 'Days_from_Incident_to_ED_or_Hospital_Arrival', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', 'WorkRelated', 'Blood_Transfusion', 'Neurosurgical_Intervention', 'Alcohol_Screen', 'Alcohol_Screen_Result', 'Drug_Screen__Amphetamine', 'Drug_Screen__Barbiturate', 'Drug_Screen__Benzodiazepines', 'Drug_Screen__Cannabinoid', 'Drug_Screen__Cocaine', 'Drug_Screen__MDMA_or_Ecstasy', 'Drug_Screen__Methadone', 'Drug_Screen__Methamphetamine', 'Drug_Screen__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment', 'Race', 'Protective_Device', 'Cerebral_Monitoring', 'OUTCOME']
x4 = x4[variables4]

x5 = load_dataset("mertkarabacak/TQP-atEDH", data_files="complications_data_train.csv", use_auth_token = HF_TOKEN)
x5 = pd.DataFrame(x5['train'])
variables5 = ['Age', 'Sex', 'Ethnicity', 'Weight', 'Height', 'Systolic_Blood_Pressure', 'Pulse_Rate', 'Supplemental_Oxygen', 'Pulse_Oximetry', 'Respiratory_Assistance', 'Respiratory_Rate', 'Temperature', 'GCS__Eye', 'GCS__Verbal', 'GCS__Motor', 'Total_GCS', 'Pupillary_Response', 'Midline_Shift', 'Bleeding_Localization', 'Bleeding_Size', 'Current_Smoker', 'Alcohol_Use_Disorder', 'Substance_Abuse_Disorder', 'Diabetes_Mellitus', 'Hypertension', 'Congestive_Heart_Failure', 'History_of_Myocardial_Infarction', 'Angina_Pectoris', 'History_of_Cerebrovascular_Accident', 'Peripheral_Arterial_Disease', 'Chronic_Obstructive_Pulmonary_Disease', 'Chronic_Renal_Failure', 'Cirrhosis', 'Bleeding_Disorder', 'Disseminated_Cancer', 'Currently_Receiving_Chemotherapy_for_Cancer', 'Dementia', 'Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder', 'Mental_or_Personality_Disorder', 'Ability_to_Complete_AgeAppropriate_ADL', 'Pregnancy', 'Anticoagulant_Therapy', 'Steroid_Use', 'Days_from_Incident_to_ED_or_Hospital_Arrival', 'Transport_Mode', 'InterFacility_Transfer', 'Trauma_Type', 'Injury_Intent', 'Mechanism_of_Injury', 'WorkRelated', 'Blood_Transfusion', 'Neurosurgical_Intervention', 'Alcohol_Screen', 'Alcohol_Screen_Result', 'Drug_Screen__Amphetamine', 'Drug_Screen__Barbiturate', 'Drug_Screen__Benzodiazepines', 'Drug_Screen__Cannabinoid', 'Drug_Screen__Cocaine', 'Drug_Screen__MDMA_or_Ecstasy', 'Drug_Screen__Methadone', 'Drug_Screen__Methamphetamine', 'Drug_Screen__Opioid', 'Drug_Screen__Oxycodone', 'Drug_Screen__Phencyclidine', 'Drug_Screen__Tricyclic_Antidepressant', 'ACS_Verification_Level', 'Hospital_Type', 'Facility_Bed_Size', 'Primary_Method_of_Payment', 'Race', 'Protective_Device', 'Cerebral_Monitoring', 'OUTCOME']
x5 = x5[variables5]

#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]

f5_names = list(x5.columns)
f5_names = [f5.replace('__', ' - ') for f5 in f5_names]
f5_names = [f5.replace('_', ' ') for f5 in f5_names]


#Assign unique values as answer options.
unique_SEX = ['Male', 'Female', 'Unknown']
unique_RACE = ['White', 'Black', 'Asian', 'American Indian', 'Pacific Islander', 'Other', 'Unknown']
unique_ETHNICITY = ['Not Hispanic or Latino', 'Hispanic or Latino', 'Unknown']
unique_SUPPLEMENTALOXYGEN = ['No supplemental oxygen', 'Supplemental oxygen', 'Unknown']
unique_RESPIRATORYASSISTANCE = ['Unassisted respiratory rate', 'Assisted respiratory rate', 'Unknown']
unique_TBIPUPILLARYRESPONSE = ['Both reactive', 'One reactive', 'Neither reactive', 'Unknown']
unique_TBIMIDLINESHIFT = ['No', 'Yes', 'Not imaged/unknown']
unique_LOCALIZATION = ['Supratentorial', 'Infratentorial']
unique_SIZE = ['Large, massive, or extensive (more than 30cc, more than 1cm thick', 'Small or moderate (less than 30cc or 0.6-1cm thick)', 'Tiny (less than 0.6cm thick)', 'Bilateral small or moderate (less than 30cc or 0.6-1cm thick)', 'Bilateral large, massive, or extensive (more than 30cc, more than 1cm thick)']
unique_CC_SMOKING = ['No', 'Yes', 'Unknown']
unique_CC_ALCOHOLISM = ['No', 'Yes', 'Unknown']
unique_CC_SUBSTANCEABUSE = ['No', 'Yes', 'Unknown']
unique_CC_DIABETES = ['No', 'Yes', 'Unknown']
unique_CC_HYPERTENSION = ['No', 'Yes', 'Unknown']
unique_CC_CHF = ['No', 'Yes', 'Unknown']
unique_CC_MI = ['No', 'Yes', 'Unknown']
unique_CC_ANGINAPECTORIS = ['No', 'Yes', 'Unknown']
unique_CC_CVA = ['No', 'Yes', 'Unknown']
unique_CC_PAD = ['No', 'Yes', 'Unknown']
unique_CC_COPD = ['No', 'Yes', 'Unknown']
unique_CC_RENAL = ['No', 'Yes', 'Unknown']
unique_CC_CIRRHOSIS = ['No', 'Yes', 'Unknown']
unique_CC_BLEEDING = ['No', 'Yes', 'Unknown']
unique_CC_DISCANCER = ['No', 'Yes', 'Unknown']
unique_CC_CHEMO = ['No', 'Yes', 'Unknown']
unique_CC_DEMENTIA = ['No', 'Yes', 'Unknown']
unique_CC_ADHD = ['No', 'Yes', 'Unknown']
unique_CC_MENTALPERSONALITY = ['No', 'Yes', 'Unknown']
unique_CC_FUNCTIONAL = ['No', 'Yes', 'Unknown']
unique_CC_PREGNANCY = ['No', 'Yes', 'Unknown', 'Not applicable (male patient)']
unique_CC_ANTICOAGULANT = ['No', 'Yes', 'Unknown']
unique_CC_STEROID = ['No', 'Yes', 'Unknown']
unique_TRANSPORTMODE = ['Ground ambulance', 'Private vehicle/public vehicle/walk-in', 'Air ambulance', 'Other/police/unknown/etc.']
unique_INTERFACILITYTRANSFER = ['No', 'Yes']
unique_TRAUMATYPE = ['Blunt', 'Penetrating', 'Other/unknown']
unique_INTENT = ['Unintentional', 'Assault', 'Self-inflicted', 'Other/unknown']
unique_MECHANISM = ['Fall', 'Struck by or against', 'MVT occupant', 'MVT pedestrian', 'MVT motorcyclist', 'MVT pedal cyclist', 'Other MVT', 'Other transport', 'Other pedestrian', 'Other pedal cyclist', 'Firearm', 'Cut/pierce', 'Natural/environmental', 'Machinery', 'Overexertion', 'Other/unspecified/unknown']
unique_PROTDEV = ['None', 'Belt', 'Airbag present', 'Helmet', 'Protective clothing', 'Protective non-clothing gear', 'Eye protection', 'Other']
unique_WORKRELATED = ['No', 'Yes']
unique_INTERVENTION = ['No', 'Yes']
unique_ICP = ['None', 'Intraventricular drain/catheter', 'Intraparenchymal oxygen/pressure monitor', 'Jugular venous bulb', 'Unknown']
unique_ALCOHOLSCREEN = ['Yes', 'No', 'Unknown']
unique_ANTIBIOTICTHERAPY = ['Yes', 'No', 'Unknown']
unique_DRGSCR_AMPHETAMINE = ['Not tested', 'No', 'Yes']
unique_DRGSCR_BARBITURATE = ['Not tested', 'No', 'Yes']
unique_DRGSCR_BENZODIAZEPINES = ['Not tested', 'No', 'Yes']
unique_DRGSCR_CANNABINOID = ['Not tested', 'No', 'Yes']
unique_DRGSCR_COCAINE = ['Not tested', 'No', 'Yes']
unique_DRGSCR_ECSTASY = ['Not tested', 'No', 'Yes']
unique_DRGSCR_METHADONE = ['Not tested', 'No', 'Yes']
unique_DRGSCR_METHAMPHETAMINE = ['Not tested', 'No', 'Yes']
unique_DRGSCR_OPIOID = ['Not tested', 'No', 'Yes']
unique_DRGSCR_OXYCODONE = ['Not tested', 'No', 'Yes']
unique_DRGSCR_PHENCYCLIDINE = ['Not tested', 'No', 'Yes']
unique_DRGSCR_TRICYCLICDEPRESS = ['Not tested', 'No', 'Yes']
unique_VERIFICATIONLEVEL = ['Level I Trauma Center', 'Level II Trauma Center', 'Level III Trauma Center', 'Unknown']
unique_HOSPITALTYPE = ['Non-profit', 'For profit', 'Government', 'Unknown']
unique_BEDSIZE = ['More than 600', '401 to 600', '201 to 400', '200 or fewer']
unique_PRIMARYMETHODPAYMENT = ['Private/commercial insurance', 'Medicaid', 'Medicare', 'Other government', 'Self-pay',  'Other/Unknown']


#Prepare data for the outcome 1 (mortality).
y1 = x1.pop('OUTCOME')
categorical_columns1 = list(x1.select_dtypes('object').columns)
le = sklearn.preprocessing.LabelEncoder()
x1[categorical_columns1] = x1[categorical_columns1].apply(le.fit_transform)

#Prepare data for the outcome 2 (discharge).
y2 = x2.pop('OUTCOME')
categorical_columns2 = list(x2.select_dtypes('object').columns)
le = sklearn.preprocessing.LabelEncoder()
x2[categorical_columns2] = x2[categorical_columns2].apply(le.fit_transform)

#Prepare data for the outcome 3 (LOS).
y3 = x3.pop('OUTCOME')
categorical_columns3 = list(x3.select_dtypes('object').columns)
le = sklearn.preprocessing.LabelEncoder()
x3[categorical_columns3] = x3[categorical_columns3].apply(le.fit_transform)

#Prepare data for the outcome 4 (ICU LOS).
y4 = x4.pop('OUTCOME')
categorical_columns4 = list(x4.select_dtypes('object').columns)
le = sklearn.preprocessing.LabelEncoder()
x4[categorical_columns4] = x4[categorical_columns4].apply(le.fit_transform)

#Prepare data for the outcome 5 (complications).
y5 = x5.pop('OUTCOME')
categorical_columns5 = list(x5.select_dtypes('object').columns)
le = sklearn.preprocessing.LabelEncoder()
x5[categorical_columns5] = x5[categorical_columns5].apply(le.fit_transform)

#Assign hyperparameters.
y1_params = {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 0.5059844209148782, 'alpha': 0.0030156848979492556, 'max_depth': 2, 'eta': 4.546875002603483e-07, 'gamma': 1.1982641538268563e-08, 'grow_policy': 'lossguide', 'eval_metric': 'auc', 'verbosity': 0, 'seed': 31}
y2_params = {'criterion': 'gini', 'max_features': None, 'max_depth': 5, 'n_estimators': 1700, 'min_samples_leaf': 2, 'min_samples_split': 2, 'random_state': 31}
y3_params =  {'objective': 'binary:logistic', 'booster': 'gbtree', 'lambda': 3.540855010579091e-08, 'alpha': 4.005546508605542e-08, 'max_depth': 5, 'eta': 5.190362998186933e-08, 'gamma': 1.1458984717217304e-05, 'grow_policy': 'depthwise', 'eval_metric': 'auc', 'verbosity': 0, 'seed': 31}
y4_params =  {'objective': 'binary', 'booster': 'gbtree', 'lambda': 9.081139728398413e-05, 'alpha': 2.6896480100715624e-06, 'max_depth': 3, 'eta': 1.1457645461556677e-08, 'gamma': 0.00043222206530621666, 'grow_policy': 'depthwise', 'eval_metric': 'auc', 'verbosity': 0, 'seed': 31}
y5_params =  {'objective': 'binary', 'boosting_type': 'gbdt', 'lambda_l1': 0.0016190622681086678, 'lambda_l2': 0.00041749233000407354, 'num_leaves': 2, 'feature_fraction': 0.5730231365909909, 'bagging_fraction': 0.6964002116636187, 'bagging_freq': 6, 'min_child_samples': 44, 'metric': 'binary_logloss', 'verbosity': -1, 'random_state': 31}

#Training models.
from xgboost import XGBClassifier
y1_xgb = XGBClassifier(**y1_params)
y1_model_xgb = y1_xgb.fit(x1, y1)
y1_explainer_xgb = shap.TreeExplainer(y1_model_xgb)

from sklearn.ensemble import RandomForestClassifier as rf
y2_rf = rf(**y2_params)
y2_model_rf = y2_rf.fit(x2, y2)
y2_explainer_rf = shap.TreeExplainer(y2_model_rf)

from xgboost import XGBClassifier
y3_xgb = XGBClassifier(**y3_params)
y3_model_xgb = y3_xgb.fit(x3, y3)
y3_explainer_xgb = shap.TreeExplainer(y3_model_xgb)

from lightgbm import LGBMClassifier
lgb = LGBMClassifier(**y4_params)
y4_model_lgb = lgb.fit(x4, y4)
y4_explainer_lgb = shap.TreeExplainer(y4_model_lgb)

from lightgbm import LGBMClassifier
lgb = LGBMClassifier(**y5_params)
y5_model_lgb = lgb.fit(x5, y5)
y5_explainer_lgb = shap.TreeExplainer(y5_model_lgb)

#Define predict for y1 (mortality).
def y1_predict_xgb(*args):
    df1 = pd.DataFrame([args], columns=x1.columns)
    df1 = df.astype({col: "category" for col in categorical_columns1})
    d1 = dict.fromkeys(df1.select_dtypes(np.int64).columns, np.int32)
    df1 = df1.astype(d1)
    pos_pred = y1_model_xgb.predict_proba(df1)
    return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}

def y1_predict_lgb(*args):
    df1 = pd.DataFrame([args], columns=x1.columns)
    df1 = df.astype({col: "category" for col in categorical_columns1})
    d1 = dict.fromkeys(df1.select_dtypes(np.int64).columns, np.int32)
    df1 = df1.astype(d1)
    pos_pred = y1_model_lgb.predict_proba(df1)
    return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}

def y1_predict_cb(*args):
    df1 = pd.DataFrame([args], columns=x1.columns)
    df1 = df1.astype({col: "category" for col in categorical_columns1})
    pos_pred = y1_model_cb.predict(Pool(df1, cat_features = categorical_columns1), prediction_type='Probability')
    return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}

def y1_predict_rf(*args):
    df1 = pd.DataFrame([args], columns=x1_rf.columns)
    df1 = df.astype({col: "category" for col in categorical_columns1})
    d1 = dict.fromkeys(df1.select_dtypes(np.int64).columns, np.int32)
    df1 = df1.astype(d1)
    pos_pred = y1_model_rf.predict_proba(df1)
    return {"Mortality": float(pos_pred[0][1]), "No Mortality": float(pos_pred[0][0])}

#Define predict for y2 (discharge).
def y2_predict_xgb(*args):
    df2 = pd.DataFrame([args], columns=x2.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    pos_pred = y2_model_xgb.predict(xgb.DMatrix(df2, enable_categorical=True))
    return {"Facility Discharge": float(pos_pred[0]), "Home Discharge": 1 - float(pos_pred[0])}

def y2_predict_lgb(*args):
    df2 = pd.DataFrame([args], columns=x2_lgb.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    pos_pred = y2_model_lgb.predict(df2)
    return {"Facility Discharge": float(pos_pred[0]), "Home Discharge": 1 - float(pos_pred[0])}

def y2_predict_cb(*args):
    df2 = pd.DataFrame([args], columns=x2.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    pos_pred = y2_model_cb.predict(Pool(df2, cat_features = categorical_columns2), prediction_type='Probability')
    return {"Facility Discharge": float(pos_pred[0][1]), "Home Discharge": float(pos_pred[0][0])}

def y2_predict_rf(*args):
    df2 = pd.DataFrame([args], columns=x2_rf.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    d2 = dict.fromkeys(df2.select_dtypes(np.int64).columns, np.int32)
    df2 = df2.astype(d2)
    pos_pred = y2_model_rf.predict_proba(df2)
    return {"Facility Discharge": float(pos_pred[0][1]), "Home Discharge": float(pos_pred[0][0])}

#Define predict for y3 (LOS).
def y3_predict_xgb(*args):
    df3 = pd.DataFrame([args], columns=x3.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    pos_pred = y3_model_xgb.predict(xgb.DMatrix(df3, enable_categorical=True))
    return {"Prolonged LOS": float(pos_pred[0]), "No Prolonged LOS": 1 - float(pos_pred[0])}

def y3_predict_lgb(*args):
    df3 = pd.DataFrame([args], columns=x3_lgb.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    pos_pred = y3_model_lgb.predict(df3)
    return {"Prolonged LOS": float(pos_pred[0]), "No Prolonged LOS": 1 - float(pos_pred[0])}

def y3_predict_cb(*args):
    df3 = pd.DataFrame([args], columns=x3.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    pos_pred = y3_model_cb.predict(Pool(df3, cat_features = categorical_columns3), prediction_type='Probability')
    return {"Prolonged LOS": float(pos_pred[0][1]), "No Prolonged LOS": float(pos_pred[0][0])}

def y3_predict_rf(*args):
    df3 = pd.DataFrame([args], columns=x3_rf.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    d3 = dict.fromkeys(df3.select_dtypes(np.int64).columns, np.int32)
    df3 = df.astype(d3)
    pos_pred = y3_model_rf.predict_proba(df3)
    return {"Prolonged LOS": float(pos_pred[0][1]), "No Prolonged LOS": float(pos_pred[0][0])}

#Define predict for y4 (ICU LOS).
def y4_predict_xgb(*args):
    df4 = pd.DataFrame([args], columns=x4.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    pos_pred = y4_model_xgb.predict(xgb.DMatrix(df4, enable_categorical=True))
    return {"Prolonged ICU LOS": float(pos_pred[0]), "No Prolonged ICU LOS": 1 - float(pos_pred[0])}

def y4_predict_lgb(*args):
    df4 = pd.DataFrame([args], columns=x4_lgb.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    pos_pred = y4_model_lgb.predict(df4)
    return {"Prolonged ICU LOS": float(pos_pred[0]), "No Prolonged ICU LOS": 1 - float(pos_pred[0])}

def y4_predict_cb(*args):
    df4 = df4.DataFrame([args], columns=x4.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    pos_pred = y4_model_cb.predict(Pool(df4, cat_features = categorical_columns4), prediction_type='Probability')
    return {"Prolonged ICU LOS": float(pos_pred[0][1]), "No Prolonged ICU LOS": float(pos_pred[0][0])}

def y4_predict_rf(*args):
    df4 = pd.DataFrame([args], columns=x4_rf.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    d4 = dict.fromkeys(df4.select_dtypes(np.int64).columns, np.int32)
    df4 = df4.astype(d4)
    pos_pred = y4_model_rf.predict_proba(df4)
    return {"Prolonged ICU LOS": float(pos_pred[0][1]), "No Prolonged ICU LOS": float(pos_pred[0][0])}

#Define predict for y5 (complications).
def y5_predict_xgb(*args):
    df5 = pd.DataFrame([args], columns=x5.columns)
    df5 = df5.astype({col: "category" for col in categorical_columns5})
    pos_pred = y5_model_xgb.predict(xgb.DMatrix(df5, enable_categorical=True))
    return {"Major Complications": float(pos_pred[0]), "No Major Complications": 1 - float(pos_pred[0])}

def y5_predict_lgb(*args):
    df5 = pd.DataFrame([args], columns=x5_lgb.columns)
    df5 = df5.astype({col: "category" for col in categorical_columns5})
    pos_pred = y5_model_lgb.predict(df5)
    return {"Major Complications": float(pos_pred[0]), "No Major Complications": 1 - float(pos_pred[0])}

def y5_predict_cb(*args):
    df5 = pd.DataFrame([args], columns=x5.columns)
    df5 = df5.astype({col: "category" for col in categorical_columns5})
    pos_pred = y5_model_cb.predict(Pool(df5, cat_features = categorical_columns5), prediction_type='Probability')
    return {"Major Complications": float(pos_pred[0][1]), "No Major Complications": float(pos_pred[0][0])}

def y5_predict_rf(*args):
    df5 = pd.DataFrame([args], columns=x5_rf.columns)
    df5 = df.astype({col: "category" for col in categorical_columns5})
    d5 = dict.fromkeys(df5.select_dtypes(np.int64).columns, np.int32)
    df5 = df5.astype(d5)
    pos_pred = y5_model_rf.predict_proba(df5)
    return {"Major Complications": float(pos_pred[0][1]), "No Major Complications": float(pos_pred[0][0])}


#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 (mortality).
def y1_interpret_xgb(*args):
    df1 = pd.DataFrame([args], columns=x1.columns)
    df1 = df1.astype({col: "category" for col in categorical_columns1})
    shap_values1 = y1_explainer_xgb.shap_values(xgb.DMatrix(df1, enable_categorical=True))
    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

def y1_interpret_lgb(*args):
    df1 = pd.DataFrame([args], columns=x1_lgb.columns)
    df1 = df1.astype({col: "category" for col in categorical_columns1})
    shap_values1 = y1_explainer_lgb.shap_values(df1)
    shap_values1 = np.abs(shap_values1)
    shap.bar_plot(shap_values1[0][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

def y1_interpret_cb(*args):
    df1 = pd.DataFrame([args], columns=x1.columns)
    df1 = df1.astype({col: "category" for col in categorical_columns1})
    shap_values1 = y1_explainer_cb.shap_values(Pool(df1, cat_features = categorical_columns1))
    shap_values1 = np.abs(shap_values1)
    shap.bar_plot(shap_values1[0], max_display = 10, show = False, feature_names = f1_names)
    scores_desc = sorted(scores_desc)
    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

def y1_interpret_rf(*args):
    df1 = pd.DataFrame([args], columns=x1_rf.columns)
    df1 = df1.astype({col: "category" for col in categorical_columns1})
    shap_values1 = y1_explainer_rf.shap_values(df1)
    shap_values1 = np.abs(shap_values1)
    shap.bar_plot(shap_values1[0][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 (discharge).
def y2_interpret_xgb(*args):
    df2 = pd.DataFrame([args], columns=x2.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    shap_values2 = y2_explainer_xgb.shap_values(xgb.DMatrix(df2, enable_categorical=True))
    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

def y2_interpret_lgb(*args):
    df2 = pd.DataFrame([args], columns=x2_lgb.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    shap_values2 = y2_explainer_lgb.shap_values(df2)
    shap_values2 = np.abs(shap_values2)
    shap.bar_plot(shap_values2[0][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

def y2_interpret_cb(*args):
    df2 = pd.DataFrame([args], columns=x2.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    shap_values2 = y2_explainer_cb.shap_values(Pool(df2, cat_features = categorical_columns2))
    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

def y2_interpret_rf(*args):
    df2 = pd.DataFrame([args], columns=x2_rf.columns)
    df2 = df2.astype({col: "category" for col in categorical_columns2})
    shap_values2 = y2_explainer_rf.shap_values(df2)
    shap_values2 = np.abs(shap_values2)
    shap.bar_plot(shap_values2[0][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 (LOS).
def y3_interpret_xgb(*args):
    df3 = pd.DataFrame([args], columns=x3.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    shap_values3 = y3_explainer_xgb.shap_values(xgb.DMatrix(df3, enable_categorical=True))
    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

def y3_interpret_lgb(*args):
    df3 = pd.DataFrame([args], columns=x3_lgb.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    shap_values3 = y3_explainer_lgb.shap_values(df3)
    shap_values3 = np.abs(shap_values3)
    shap.bar_plot(shap_values3[0][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

def y3_interpret_cb(*args):
    df3 = pd.DataFrame([args], columns=x3.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    shap_values3 = y3_explainer_cb.shap_values(Pool(df3, cat_features = categorical_columns3))
    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

def y3_interpret_rf(*args):
    df3 = pd.DataFrame([args], columns=x3_rf.columns)
    df3 = df3.astype({col: "category" for col in categorical_columns3})
    shap_values3 = y3_explainer_rf.shap_values(df3)
    shap_values3 = np.abs(shap_values3)
    shap.bar_plot(shap_values3[0][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 (ICU LOS).
def y4_interpret_xgb(*args):
    df4 = pd.DataFrame([args], columns=x4.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    shap_values4 = y4_explainer_xgb.shap_values(xgb.DMatrix(df4, enable_categorical=True))
    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

def y4_interpret_lgb(*args):
    df4 = pd.DataFrame([args], columns=x4_lgb.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    shap_values4 = y4_explainer_lgb.shap_values(df4)
    shap_values4 = np.abs(shap_values4)
    shap.bar_plot(shap_values4[0][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

def y4_interpret_cb(*args):
    df4 = pd.DataFrame([args], columns=x4.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    shap_values4 = y4_explainer_cb.shap_values(Pool(df4, cat_features = categorical_columns4))
    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

def y4_interpret_rf(*args):
    df4 = pd.DataFrame([args], columns=x4_rf.columns)
    df4 = df4.astype({col: "category" for col in categorical_columns4})
    shap_values4 = y4_explainer_rf.shap_values(df4)
    shap_values4 = np.abs(shap_values4)
    shap.bar_plot(shap_values4[0][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

#Define interpret for y5 (complications).
def y5_interpret_xgb(*args):
    df5 = pd.DataFrame([args], columns=x5.columns)
    df5 = df5.astype({col: "category" for col in categorical_columns5})
    shap_values5 = y5_explainer_xgb.shap_values(xgb.DMatrix(df5, enable_categorical=True))
    shap_values5 = np.abs(shap_values5)
    shap.bar_plot(shap_values5[0], max_display = 10, show = False, feature_names = f5_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

def y5_interpret_lgb(*args):
    df5 = pd.DataFrame([args], columns=x5_lgb.columns)
    df5 = df5.astype({col: "category" for col in categorical_columns5})
    shap_values5 = y5_explainer_lgb.shap_values(df5)
    shap_values5 = np.abs(shap_values5)
    shap.bar_plot(shap_values5[0][0], max_display = 10, show = False, feature_names = f5_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

def y5_interpret_cb(*args):
    df5 = pd.DataFrame([args], columns=x5.columns)
    df5 = df5.astype({col: "category" for col in categorical_columns5})
    shap_values5 = y5_explainer_cb.shap_values(Pool(df5, cat_features = categorical_columns5))
    shap_values5 = np.abs(shap_values5)
    shap.bar_plot(shap_values5[0], max_display = 10, show = False, feature_names = f5_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

def y5_interpret_rf(*args):
    df5 = pd.DataFrame([args], columns=x5_rf.columns)
    df5 = df5.astype({col: "category" for col in categorical_columns5})
    shap_values = y5_explainer_rf.shap_values(df5)
    shap_values1 = np.abs(shap_values5)
    shap.bar_plot(shap_values5[0][0], max_display = 10, show = False, feature_names = f5_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 = "TQP-atEDH") as demo:
        
    gr.Markdown(
        """
    <br/>
    <center><h1>Epidural Hematoma Outcomes</h1></center>
    <center><h2>Prediction Tool</h2></center>
    <center><i>The publication describing the details of this predictive 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>
          <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>Mortality</td>
            <td>XGBoost</td>
            <td>0.981 (0.972 - 0.99)</td>
            <td>0.906 (0.886 - 0.926)</td>
            <td>0.412 (0.379 - 0.445)</td>
            <td>0.801 (0.774 - 0.828)</td>
            <td>0.926 (0.853 - 0.985)</td>
            <td>0.013 (0.005 - 0.021)</td>             
          </tr>
          <tr>
            <td>Non-home Discharges</td>
            <td>Random Forest</td>
            <td>0.758 (0.728 - 0.788)</td>
            <td>0.764 (0.734 - 0.794)</td>
            <td>0.51 (0.475 - 0.545)</td>
            <td>0.673 (0.64 - 0.706)</td>
            <td>0.798 (0.749 - 0.818)</td>
            <td>0.159 (0.133 - 0.185)</td>             
          </tr>
          <tr>
            <td>Prolonged LOS</td>
            <td>XGBoost</td>
            <td>0.803 (0.777 - 0.829)</td>
            <td>0.736 (0.707 - 0.765)</td>
            <td>0.414 (0.381 - 0.447)</td>
            <td>0.684 (0.653 - 0.715)</td>
            <td>0.782 (0.71 - 0.794)</td>
            <td>0.127 (0.105 - 0.149)</td>             
          </tr>
          <tr>
            <td>Prolonged ICU-LOS</td>
            <td>LightGBM</td>
            <td>0.82 (0.789 - 0.851)</td>
            <td>0.818 (0.787 - 0.849)</td>
            <td>0.303 (0.266 - 0.34)</td>
            <td>0.629 (0.59 - 0.668)</td>
            <td>0.774 (0.689 - 0.801)</td>
            <td>0.111 (0.086 - 0.136)</td>             
          </tr>
          <tr>
            <td>Major Complications</td>
            <td>LightGBM</td>
            <td>0.946 (0.93 - 0.962)</td>
            <td>0.821 (0.795 - 0.847)</td>
            <td>0.075 (0.057 - 0.093)</td>
            <td>0.578 (0.544 - 0.612)</td>
            <td>0.733 (0.61 - 0.801)</td>
            <td>0.03 (0.018 - 0.042)</td>             
          </tr>          
        </table>
        </div>
        """
    )    

    with gr.Row():

        with gr.Column():

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

            Sex = gr.Radio(label = "Sex", choices = unique_SEX, type = 'index', value = 'Male')

            Race = gr.Radio(label = "Race", choices = unique_RACE, type = 'index', value = 'White')
            
            Ethnicity = gr.Radio(label = "Ethnicity", choices = unique_ETHNICITY, type = 'index',value = 'Not Hispanic or Latino')

            Weight = gr.Slider(label = "Weight (in kilograms)", minimum = 20, maximum = 200, step = 1, value = 75)
            
            Height = gr.Slider(label = "Height (in centimeters)", minimum = 100, maximum = 250, step = 1, value = 175)
            
            Systolic_Blood_Pressure = gr.Slider(label = "Systolic Blood Pressure", minimum = 50, maximum = 250, step = 1, value = 135)

            Pulse_Rate = gr.Slider(label = "Pulse Rate", minimum=20, maximum=250, step=1, value = 75)

            Supplemental_Oxygen = gr.Radio(label = "Supplemental Oxygen", choices = unique_SUPPLEMENTALOXYGEN, type = 'index', value = 'No supplemental oxygen')
            
            Pulse_Oximetry = gr.Slider(label = "Pulse Oximetry", minimum = 50, maximum = 100, step = 1, value = 99)

            Respiratory_Assistance = gr.Radio(label = "Respiratory Assistance", choices = unique_RESPIRATORYASSISTANCE, type = 'index', value = 'Unassisted respiratory rate')

            Respiratory_Rate = gr.Slider(label = "Respiratory Rate", minimum = 1, maximum = 99, step = 1, value = 18)

            Temperature = gr.Slider(label = "Temperature", minimum = 30, maximum = 50, step = 0.1, value = 36.5)
            
            GCS__Eye = gr.Slider(label = "GCS - Eye", minimum = 1, maximum = 4, step = 1, value = 4)

            GCS__Verbal = gr.Slider(label = "GCS - Verbal", minimum = 1, maximum = 5, step = 1, value = 5)

            GCS__Motor = gr.Slider(label = "GCS - Motor", minimum = 1, maximum = 6, step = 1, value = 6)

            Total_GCS = gr.Slider(label = "GCS - Total", minimum = 1, maximum = 15, step = 1, value = 15)
            
            Pupillary_Response = gr.Radio(label = "Pupillary Response", choices = unique_TBIPUPILLARYRESPONSE, type = 'index', value = 'Both reactive')
            
            Midline_Shift = gr.Radio(label = "Midline Shift", choices = unique_TBIMIDLINESHIFT, type = 'index', value = 'No')
            
            Bleeding_Localization = gr.Radio(label = "Bleeding Localization", choices = unique_LOCALIZATION, type = 'index', value = 'Supratentorial')   
            
            Bleeding_Size = gr.Radio(label = "Bleeding Size", choices = unique_SIZE, type = 'index', value = 'Tiny (less than 0.6cm thick)')
            
            Current_Smoker = gr.Radio(label = "Current Smoker", choices = unique_CC_SMOKING, type = 'index', value = 'No')

            Comorbid_Condition__Alcohol_Use_Disorder = gr.Radio(label = "Comorbid Condition - Alcohol Use Disorder", choices = unique_CC_ALCOHOLISM, type = 'index', value = 'No')

            Comorbid_Condition__Substance_Abuse_Disorder = gr.Radio(label = "Comorbid Condition - Substance Abuse Disorder", choices = unique_CC_SUBSTANCEABUSE, type = 'index', value = 'No')

            Comorbid_Condition__Diabetes_Mellitus = gr.Radio(label = "Comorbid Condition - Diabetes Mellitus", choices = unique_CC_DIABETES, type = 'index', value = 'No')

            Comorbid_Condition__Hypertension = gr.Radio(label = "Comorbid Condition - Hypertension", choices = unique_CC_HYPERTENSION, type = 'index', value = 'No')

            Comorbid_Condition__Congestive_Heart_Failure = gr.Radio(label = "Comorbid Condition - Congestive Heart Failure", choices = unique_CC_CHF, type = 'index', value = 'No')
            
            History_of_Myocardial_Infarction = gr.Radio(label = "History of Myocardial Infarction", choices = unique_CC_MI, type = 'index', value = 'No')

            Comorbid_Condition__Angina_Pectoris = gr.Radio(label = "Comorbid Condition - Angina Pectoris", choices = unique_CC_ANGINAPECTORIS, type = 'index', value = 'No')
            
            History_of_Cerebrovascular_Accident = gr.Radio(label = "History of Cerebrovascular Accident", choices = unique_CC_CVA, type = 'index', value = 'No')

            Comorbid_Condition__Peripheral_Arterial_Disease = gr.Radio(label = "Comorbid Condition - Peripheral Arterial Disease", choices = unique_CC_PAD, type = 'index', value = 'No')

            Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease = gr.Radio(label = "Comorbid Condition - Chronic Obstructive Pulmonary Disease", choices = unique_CC_COPD, type = 'index', value = 'No')

            Comorbid_Condition__Chronic_Renal_Failure = gr.Radio(label = "Comorbid Condition - Chronic Renal Failure", choices = unique_CC_RENAL, type = 'index', value = 'No')

            Comorbid_Condition__Cirrhosis = gr.Radio(label = "Comorbid Condition - Cirrhosis", choices = unique_CC_CIRRHOSIS, type = 'index', value = 'No')

            Comorbid_Condition__Bleeding_Disorder = gr.Radio(label = "Comorbid Condition - Bleeding Disorder", choices = unique_CC_BLEEDING, type = 'index', value = 'No')
            
            Comorbid_Condition__Disseminated_Cancer = gr.Radio(label = "Comorbid Condition - Disseminated Cancer", choices = unique_CC_DISCANCER, type = 'index', value = 'No')

            Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer = gr.Radio(label = "Comorbid Condition - Currently Receiving Chemotherapy for Cancer", choices = unique_CC_CHEMO, type = 'index', value = 'No')

            Comorbid_Condition__Dementia = gr.Radio(label = "Comorbid Condition - Dementia", choices = unique_CC_DEMENTIA, type = 'index', value = 'No')
            Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder = gr.Radio(label = "Comorbid Condition - Attention Deficit Disorder or Attention Deficit Hyperactivity Disorder", choices = unique_CC_ADHD, type = 'index', value = 'No')

            Comorbid_Condition__Mental_or_Personality_Disorder = gr.Radio(label = "Comorbid Condition - Mental or Personality Disorder", choices = unique_CC_MENTALPERSONALITY, type = 'index', value = 'No')

            Ability_to_Complete_AgeAppropriate_ADL = gr.Radio(label = "Ability to Complete Age-Appropriate ADL", choices = unique_CC_FUNCTIONAL, type = 'index', value = 'Yes')

            Pregnancy = gr.Radio(label = "Pregnancy", choices = unique_CC_PREGNANCY, type = 'index', value = 'Not applicable (male patient)')

            Anticoagulant_Therapy = gr.Radio(label = "Anticoagulant Therapy", choices = unique_CC_ANTICOAGULANT, type = 'index', value = 'No')

            Steroid_Use = gr.Radio(label = "Steroid Use", choices = unique_CC_STEROID, type = 'index', value = 'No')
            
            Days_from_Incident_to_ED_or_Hospital_Arrival = gr.Slider(label = "Days from Incident to ED or Hospital Arrival", minimum = 1, maximum = 31, step = 1, value = 1)

            Transport_Mode = gr.Radio(label = "Transport Mode", choices = unique_TRANSPORTMODE, type = 'index', value = 'Ground ambulance')

            InterFacility_Transfer = gr.Radio(label = "Inter-Facility Transfer", choices = unique_INTERFACILITYTRANSFER, type = 'index', value = 'No')

            Trauma_Type = gr.Radio(label = "Trauma Type", choices = unique_TRAUMATYPE, type = 'index', value = 'Blunt')

            Injury_Intent = gr.Radio(label = "Injury Intent", choices = unique_INTENT, type = 'index', value = 'Unintentional')

            Mechanism_of_Injury = gr.Dropdown(label = "Mechanism of Injury", choices = unique_MECHANISM, type = 'index', value = 'Fall')
         
            Protective_Device = gr.Dropdown(label = "Protective Device", choices = unique_PROTDEV, type = 'index', value = 'None')

            WorkRelated = gr.Dropdown(label = "Work-Related", choices = unique_WORKRELATED, type = 'index', value = 'No')
            
            Blood_Transfusion = gr.Slider(label="Blood Transfusion (mL)", minimum = 0, maximum = 5000, step = 50, value = 0)
                        
            Neurosurgical_Intervention = gr.Radio(label = "Neurosurgical Intervention", choices = unique_INTERVENTION, type = 'index', value = 'No')

            Cerebral_Monitoring = gr.Dropdown(label = "Cerebral Monitoring", choices = unique_ICP, type = 'index', value = 'None')

            Alcohol_Screen = gr.Radio(label = "Alcohol Screen", choices = unique_ALCOHOLSCREEN, type = 'index', value = 'Yes')

            Alcohol_Screen_Result = gr.Slider(label="Alcohol Screen Result", minimum = 0, maximum = 1, step = 0.1, value = 0)
            
            Drug_Screen__Amphetamine = gr.Radio(label = "Drug Screen - Amphetamine", choices = unique_DRGSCR_AMPHETAMINE, type = 'index', value = 'No')
            
            Drug_Screen__Barbiturate = gr.Radio(label = "Drug Screen - Barbiturate", choices = unique_DRGSCR_BARBITURATE, type = 'index', value = 'No')
            
            Drug_Screen__Benzodiazepines = gr.Radio(label = "Drug Screen - Benzodiazepines", choices = unique_DRGSCR_BENZODIAZEPINES, type = 'index', value = 'No')
            
            Drug_Screen__Cannabinoid = gr.Radio(label = "Drug Screen - Cannabinoid", choices = unique_DRGSCR_CANNABINOID, type = 'index', value = 'No')
            
            Drug_Screen__Cocaine = gr.Radio(label = "Drug Screen - Cocaine", choices = unique_DRGSCR_COCAINE, type = 'index', value = 'No')
            
            Drug_Screen__MDMA_or_Ecstasy = gr.Radio(label = "Drug Screen - MDMA or Ecstasy", choices = unique_DRGSCR_ECSTASY, type = 'index', value = 'No')
            
            Drug_Screen__Methadone = gr.Radio(label = "Drug Screen - Methadone", choices = unique_DRGSCR_METHADONE, type = 'index', value = 'No')
            
            Drug_Screen__Methamphetamine = gr.Radio(label = "Drug Screen - Methamphetamine", choices = unique_DRGSCR_METHAMPHETAMINE, type = 'index', value = 'No')
            
            Drug_Screen__Opioid = gr.Radio(label = "Drug Screen - Opioid", choices = unique_DRGSCR_OPIOID, type = 'index', value = 'No')
            
            Drug_Screen__Oxycodone = gr.Radio(label = "Drug Screen - Oxycodone", choices = unique_DRGSCR_OXYCODONE, type = 'index', value = 'No')
            
            Drug_Screen__Phencyclidine = gr.Radio(label = "Drug Screen - Phencyclidine", choices = unique_DRGSCR_PHENCYCLIDINE, type = 'index', value = 'No')
            
            Drug_Screen__Tricyclic_Antidepressant = gr.Radio(label = "Drug Screen - Tricyclic Antidepressant", choices = unique_DRGSCR_TRICYCLICDEPRESS, type = 'index', value = 'No')
            
            ACS_Verification_Level = gr.Radio(label = "ACS Verification Level", choices = unique_VERIFICATIONLEVEL, type = 'index', value = 'Level I Trauma Center')
            
            Hospital_Type = gr.Radio(label = "Hospital Type", choices = unique_HOSPITALTYPE, type = 'index', value = 'Non-profit')
            
            Facility_Bed_Size = gr.Radio(label = "Facility Bed Size", choices = unique_BEDSIZE, type = 'index', value = 'More than 600')
            
            Primary_Method_of_Payment = gr.Dropdown(label = "Primary Method of Payment", choices = unique_PRIMARYMETHODPAYMENT, type = 'index', value = 'Private/commercial insurance')
            
        with gr.Column():
            
            with gr.Box():
                
                gr.Markdown(
                    """
                    <center> <h2>Mortality</h2> </center>
                    <center> This model uses the XGBoost algorithm. </center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y1_predict_btn_xgb = gr.Button(value="Predict")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                label1 = gr.Label()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y1_interpret_btn_xgb = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot1 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
            with gr.Box():
                gr.Markdown(
                    """
                    <center> <h2>Discharge Disposition</h2> </center>
                    <center> This model uses the Random Forest algorithm. </center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y2_predict_btn_rf = gr.Button(value="Predict")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                label2 = gr.Label()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y2_interpret_btn_rf = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot2 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
            with gr.Box():
                
                gr.Markdown(
                    """
                    <center> <h2>Prolonged Length of Stay</h2> </center>
                    <center> This model uses the XGBoost algorithm. </center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y3_predict_btn_xgb = gr.Button(value="Predict")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                label3 = gr.Label()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y3_interpret_btn_xgb = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot3 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )  

            with gr.Box():
                gr.Markdown(
                    """
                    <center> <h2>Prolonged Length of ICU Stay</h2> </center>
                    <center> This model uses the LightGBM algorithm. </center>
                    <br/>
                    """
                )
                with gr.Row():
                    y4_predict_btn_lgb = gr.Button(value="Predict")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                label4 = gr.Label()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y4_interpret_btn_lgb = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot4 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
            with gr.Box():
                gr.Markdown(
                    """
                    <center> <h2>Major Complications</h2> </center>
                    <center> This model uses the LightGBM algorithm. </center>
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y5_predict_btn_lgb = gr.Button(value="Predict")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                label5 = gr.Label()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                with gr.Row():
                    y5_interpret_btn_lgb = gr.Button(value="Explain")
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )
                
                plot5 = gr.Plot()
                
                gr.Markdown(
                    """
                    <br/>
                    """
                    )                
                                
                y1_predict_btn_xgb.click(
                    y1_predict_xgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [label1]
                )

                y2_predict_btn_rf.click(
                    y2_predict_rf,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [label2]
                )
                
                y3_predict_btn_xgb.click(
                    y3_predict_xgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [label3]
                )

                y4_predict_btn_lgb.click(
                    y4_predict_lgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [label4]
                )
                
                y5_predict_btn_lgb.click(
                    y5_predict_lgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [label5]
                )

                y1_interpret_btn_xgb.click(
                    y1_interpret_xgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [plot1],
                )
                
                y2_interpret_btn_rf.click(
                    y2_interpret_rf,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [plot2],
                )

                y3_interpret_btn_xgb.click(
                    y3_interpret_xgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [plot3],
                )
                
                y4_interpret_btn_lgb.click(
                    y4_interpret_lgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [plot4],
                )
                
                y5_interpret_btn_lgb.click(
                    y5_interpret_lgb,
                    inputs = [Age, Sex, Ethnicity, Weight, Height, Systolic_Blood_Pressure, Pulse_Rate, Supplemental_Oxygen, Pulse_Oximetry, Respiratory_Assistance, Respiratory_Rate, Temperature, GCS__Eye, GCS__Verbal, GCS__Motor, Total_GCS, Pupillary_Response, Midline_Shift, Bleeding_Localization, Bleeding_Size, Current_Smoker, Comorbid_Condition__Alcohol_Use_Disorder, Comorbid_Condition__Substance_Abuse_Disorder, Comorbid_Condition__Diabetes_Mellitus, Comorbid_Condition__Hypertension, Comorbid_Condition__Congestive_Heart_Failure, History_of_Myocardial_Infarction, Comorbid_Condition__Angina_Pectoris, History_of_Cerebrovascular_Accident, Comorbid_Condition__Peripheral_Arterial_Disease, Comorbid_Condition__Chronic_Obstructive_Pulmonary_Disease, Comorbid_Condition__Chronic_Renal_Failure, Comorbid_Condition__Cirrhosis, Comorbid_Condition__Bleeding_Disorder, Comorbid_Condition__Disseminated_Cancer, Comorbid_Condition__Currently_Receiving_Chemotherapy_for_Cancer, Comorbid_Condition__Dementia, Comorbid_Condition__Attention_Deficit_Disorder_or_Attention_Deficit_Hyperactivity_Disorder, Comorbid_Condition__Mental_or_Personality_Disorder, Ability_to_Complete_AgeAppropriate_ADL, Pregnancy, Anticoagulant_Therapy, Steroid_Use, Days_from_Incident_to_ED_or_Hospital_Arrival, Transport_Mode, InterFacility_Transfer, Trauma_Type, Injury_Intent, Mechanism_of_Injury, WorkRelated, Blood_Transfusion, Neurosurgical_Intervention, Alcohol_Screen, Alcohol_Screen_Result, Drug_Screen__Amphetamine, Drug_Screen__Barbiturate, Drug_Screen__Benzodiazepines, Drug_Screen__Cannabinoid, Drug_Screen__Cocaine, Drug_Screen__MDMA_or_Ecstasy, Drug_Screen__Methadone, Drug_Screen__Methamphetamine, Drug_Screen__Opioid, Drug_Screen__Oxycodone, Drug_Screen__Phencyclidine, Drug_Screen__Tricyclic_Antidepressant, ACS_Verification_Level, Hospital_Type, Facility_Bed_Size, Primary_Method_of_Payment, Race, Cerebral_Monitoring, Protective_Device,],
                    outputs = [plot5],
                )

    gr.Markdown(
                """    
                <center><h3>Disclaimer</h3>
                <center> 
                The American College of Surgeons National Trauma Data Bank (ACS-NTDB) and the hospitals participating in the ACS-NTDB 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 general health information 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/>
                <br/>
                <h4>By using this tool, you accept all of the above terms.<h4/>
                </center>
                <br/>
                """
    )                
                
demo.launch()