pulse_ox / app.py
zonova's picture
Update app.py
46d2751
raw
history blame
1.67 kB
import gradio as gr
import xgboost
import pandas as pd
import numpy as np
def predicter(SpO2, Age, Weight, Height, Temperature, Gender, Race):
xgb_reg = xgboost.XGBClassifier(tree_method = 'approx',
enable_categorical = True,
learning_rate=.1,
max_depth=2,
n_estimators=70,
early_stopping_rounds = 0,
scale_pos_weight=1)
xgb_reg.load_model('classifier_fewer_features_HH.json')
if Gender == "Male":
gen = "M"
elif Gender == "Female":
gen = "F"
cont_features = ['SpO2','anchor_age','weight','height','temperature']
cat_features = ['gender','race_group']
user_input = pd.DataFrame([[SpO2/100,Age/91,Weight/309,Height/213,Temperature/42.06,gen,Race]],columns = cont_features+cat_features)
user_input[cat_features] = user_input[cat_features].copy().astype('category')
pred = xgb_reg.predict_proba(user_input)
#return str(pred)
return {"Probability of Not Having Hidden Hypoxemia": float(pred[0][0]), "Probability of Having Hidden Hypoxemia": float(pred[0][1])}
demo = gr.Interface(
fn=predicter,
inputs=[gr.Slider(0, 100),"number",gr.inputs.Number(label = "Weight in kg"),gr.inputs.Number(label = "Height in cm"),gr.inputs.Number(label = "Temperature in Celcius"),gr.Radio(["Male", "Female"]),gr.Radio(["White", "Black", "Asian", "Hispanic", "Other"])],
outputs=[gr.Label()],
#outputs = gr.Textbox(label = "Probabilities"),
title = "Probability of Hidden Hypoxemia"
)
demo.launch()