Final-Project / app.py
aaronbi's picture
Update app.py
478be56
raw
history blame
3.31 kB
import gradio as gr
from joblib import dump, load
#loading models
log = load('logistic_model.joblib')
knn = load('knn_model.joblib')
decision = load('decision_tree_model.joblib')
deep = load('deep_model.joblib')
#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)