Spaces:
Sleeping
Sleeping
File size: 2,823 Bytes
d02effd |
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 |
import gradio as gr
import pandas as pd
import joblib
import matplotlib
matplotlib.use('TkAgg')
def predict(gender, bmi, asthma, glucose, pulse):
gender_char = 1
if gender == "Female":
gender_char = 0
asthma_val = False
if asthma is True:
asthma_val = 1
pred_data = {
"id": 0,
"rcount": train_data['rcount'].mean(),
"gender": gender_char,
"dialysisrenalendstage": False,
"asthma": asthma_val,
"irondef": False,
"pneum": False,
"substancedependence": False,
"psychologicaldisordermajor": False,
"depress": False,
"psychother": False,
"fibrosisandother": False,
"malnutrition": False,
"hemo": False,
"hematocrit": False,
"neutrophils": False,
"sodium": train_data['sodium'].mean(),
"glucose": glucose,
"bloodureanitro": train_data['bloodureanitro'].mean(),
"creatinine": train_data['creatinine'].mean(),
"bmi": bmi,
"pulse": pulse,
"respiration": train_data['respiration'].mean(),
"secondarydiagnosisnonicd9": 0,
"facid": 0
}
features = ['id', 'rcount', 'gender', 'dialysisrenalendstage', 'asthma', 'irondef', 'pneum', 'substancedependence',
'psychologicaldisordermajor', 'depress', 'psychother', 'fibrosisandother', 'malnutrition', 'hemo',
'hematocrit', 'neutrophils', 'sodium', 'glucose', 'bloodureanitro', 'creatinine', 'bmi', 'pulse',
'respiration', 'secondarydiagnosisnonicd9', 'facid']
pred_df = pd.DataFrame([pred_data], columns=features)
result = "Error in prediction"
try:
model = joblib.load('data/model.pkl')
result = model.predict(pred_df)
except Exception as e:
print(f"Fehler beim Laden des Modells: {str(e)}")
print(result)
return result
gender = 0
bmi_min, bmi_max, bmi_default = 15, 50, 25
asthma = 0
glucose_min, glucose_max, glucose_default = 30, 190, 85
pulse_min, pulse_max, pulse_default = 40, 70, 180
# Create the interface
iface = gr.Interface(
fn=predict,
inputs=[
gr.components.Radio(["Female", "Male"], label="Gender"),
gr.components.Slider(minimum=bmi_min, maximum=bmi_max, value=bmi_default, label="BMI"),
gr.components.Checkbox(label="Asthma"),
gr.components.Slider(minimum=glucose_min, maximum=glucose_max, value=glucose_default, label="Glucose Level"),
gr.components.Slider(minimum=pulse_min, maximum=glucose_max, value=pulse_default, label="Pulse")
],
outputs=gr.components.Textbox(label="Prediction of stay length"),
title="Length of Stay - Predictor",
description="""Enter the values to get a prediction of your length of stay""",
)
# Launch the interface
iface.launch()
|