File size: 3,374 Bytes
5c2f56c
 
2e7cba2
 
5c2f56c
 
 
 
 
2e7cba2
5c2f56c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from joblib import dump, load
import tensorflow as tf
from tensorflow import keras

#loading models
log = load('logistic_model.joblib')
knn = load('knn_model.joblib')
decision = load('decision_tree_model.joblib')
deep = tf.keras.models.load_model('deep_model')

#input/output modules
input_module1 = gr.Dropdown(choices=["Logistic Regression", "KNN", "Decision Tree","Neural Network"], label = "method")
input_module2 = gr.Dropdown(choices=["male", 'female'], label = "gender")
input_module3 = gr.Dropdown(choices=['african-american','asian','black','black african','black or african american',\
                                     'caucasian', 'han chinese', 'hispanic', 'intermediate', 'japanese', 'korean', 'other',\
                                     'Other (Black British)','Other Mixed Race','White'], label = "race")
input_module4 = gr.Number(label='age')
input_module5 = gr.Number(label='height (cm)')
input_module6 = gr.Number(label='weight (kg)')
input_module7 = gr.Checkbox(label='Diabetes')
input_module8 = gr.Checkbox(label='Simvastatin (Zocor)')
input_module9 = gr.Checkbox(label='Amiodarone (Cordarone)')
input_module10 = gr.Number(label='target INR')
input_module11 = gr.Number(label='INR on Reported Therapeutic Dose of Warfarin')
input_module12 = gr.Number(label='Cyp2C9 genotypes (1-13)')
input_module13 = gr.Dropdown(choices=['A/A','A/G','G/G'], label = "VKORC1 genotype")

output_module = gr.Number(label='Therapeutic Dose of Warfarin (>=30 mg/wk) (1=true, 0=false)')

race_options = ['african-american','asian','black','black african','black or african american',\
                                     'caucasian', 'han chinese', 'hispanic', 'intermediate', 'japanese', 'korean', 'other',\
                                     'Other (Black British)','Other Mixed Race','White']

#gradio function
def predict(method, gender, race, age, height, weight, diabetes, simv, amio, targetINR, INR, cyp2c9, vkorc1):

  #converting inputs into numeric data
  if gender == 'male':
    gender = 0
  else:
    gender = 1

  for i in range(len(race_options)):
    if race_options[i] == race:
      race_options[i] = 1
    else:
      race_options[i] = 0
  
  if diabetes == True:
    diabetes = 1
  else:
    diabetes = 0
  
  if simv == True:
    simv = 1
  else:
    simv = 0
  
  if amio == True:
    amio = 1
  else:
    amio = 0

  if vkorc1 == 'A/A':
    vkorc1 = 0
  elif vkorc1 == 'A/G':
    vkorc1 = 1
  else:
    vkorc1 = 2

  #compiling data
  data = [gender, age, height, weight, diabetes, simv, amio, targetINR, INR, cyp2c9, vkorc1]
  data.extend(race_options)
  data.extend([0]) #accounting for extra unused race category (there are 2 'other' options for race)

  #predicting using given method
  if method == "Logistic Regression":
    value = log.predict([data])[0]
  elif method == "KNN":
    value = knn.predict([data])[0]
  elif method == "Decision Tree":
    value = decision.predict([data])[0]
  else:
    value = deep.predict([data])[0]
    if value >= 0.5:
      value = 1
    else:
      value = 0
    

  return value



gr.Interface(fn=predict, inputs=[input_module1,input_module2,input_module3,input_module4,input_module5,input_module6,input_module7,\
                                 input_module8,input_module9,input_module10,input_module11,input_module12,input_module13], outputs=output_module).launch(debug=True)