File size: 2,188 Bytes
159eb29
e6f657c
 
 
c6aa51a
 
e6f657c
a12b4ed
0ebcec0
c6aa51a
a12b4ed
e6f657c
 
 
 
 
 
c6aa51a
 
 
 
 
 
 
e6f657c
c6aa51a
 
a12b4ed
c6aa51a
 
a12b4ed
 
 
 
 
0ebcec0
 
c6aa51a
0ebcec0
 
159eb29
c6aa51a
 
 
 
 
 
 
 
 
a12b4ed
e022594
 
0ebcec0
d7bf89d
d6187ba
8b4ec89
e022594
 
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
import gradio as gr
import xgboost
import pandas as pd
import numpy as np
import json
import pickle


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)
    '''
    with open('HH_ensemble_classifier_online.json', 'r') as file:
    model_data = json.load(file)
    for item in model_data:
        index = item['index']
        model = pickle.loads(item['model'].encode('latin1'))
        loaded_models.append(model)

    classifier_list = loaded_models
    '''
    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')


    predictions = np.zeros((len(classifier_list),2))
    for i in range(len(classifier_list)):
        predictions[i] = classifier_list[i].predict_proba(user_input[cont_features + cat_features])
    averaged_prediction = predictions.mean(axis=0)
    '''
    pred = xgb_reg.predict_proba(user_input)
'''
    return {"No Hidden Hypoxemia": float(averaged_prediction[0]), "Hidden Hypoxemia": float(averaged_prediction[1])}
    

demo = gr.Interface(
    fn=predicter,
    inputs=[gr.Slider(88.1, 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(label = "Probabilities")],
    title = "Model Predictions"
)
demo.launch()