Spaces:
Sleeping
Sleeping
Sebastian Nausester
commited on
Commit
·
d02effd
1
Parent(s):
f29bcef
initial
Browse files- .gitignore +1 -0
- data/model.pkl +3 -0
- main.py +88 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.idea/*
|
data/model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:de759f7c4ad50a7d58a7531056fcda31314b13a9948a613b167fa35969290c14
|
| 3 |
+
size 164923921
|
main.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
import matplotlib
|
| 6 |
+
|
| 7 |
+
matplotlib.use('TkAgg')
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def predict(gender, bmi, asthma, glucose, pulse):
|
| 11 |
+
|
| 12 |
+
gender_char = 1
|
| 13 |
+
if gender == "Female":
|
| 14 |
+
gender_char = 0
|
| 15 |
+
|
| 16 |
+
asthma_val = False
|
| 17 |
+
if asthma is True:
|
| 18 |
+
asthma_val = 1
|
| 19 |
+
|
| 20 |
+
pred_data = {
|
| 21 |
+
"id": 0,
|
| 22 |
+
"rcount": train_data['rcount'].mean(),
|
| 23 |
+
"gender": gender_char,
|
| 24 |
+
"dialysisrenalendstage": False,
|
| 25 |
+
"asthma": asthma_val,
|
| 26 |
+
"irondef": False,
|
| 27 |
+
"pneum": False,
|
| 28 |
+
"substancedependence": False,
|
| 29 |
+
"psychologicaldisordermajor": False,
|
| 30 |
+
"depress": False,
|
| 31 |
+
"psychother": False,
|
| 32 |
+
"fibrosisandother": False,
|
| 33 |
+
"malnutrition": False,
|
| 34 |
+
"hemo": False,
|
| 35 |
+
"hematocrit": False,
|
| 36 |
+
"neutrophils": False,
|
| 37 |
+
"sodium": train_data['sodium'].mean(),
|
| 38 |
+
"glucose": glucose,
|
| 39 |
+
"bloodureanitro": train_data['bloodureanitro'].mean(),
|
| 40 |
+
"creatinine": train_data['creatinine'].mean(),
|
| 41 |
+
"bmi": bmi,
|
| 42 |
+
"pulse": pulse,
|
| 43 |
+
"respiration": train_data['respiration'].mean(),
|
| 44 |
+
"secondarydiagnosisnonicd9": 0,
|
| 45 |
+
"facid": 0
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
features = ['id', 'rcount', 'gender', 'dialysisrenalendstage', 'asthma', 'irondef', 'pneum', 'substancedependence',
|
| 49 |
+
'psychologicaldisordermajor', 'depress', 'psychother', 'fibrosisandother', 'malnutrition', 'hemo',
|
| 50 |
+
'hematocrit', 'neutrophils', 'sodium', 'glucose', 'bloodureanitro', 'creatinine', 'bmi', 'pulse',
|
| 51 |
+
'respiration', 'secondarydiagnosisnonicd9', 'facid']
|
| 52 |
+
|
| 53 |
+
pred_df = pd.DataFrame([pred_data], columns=features)
|
| 54 |
+
result = "Error in prediction"
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
model = joblib.load('data/model.pkl')
|
| 58 |
+
result = model.predict(pred_df)
|
| 59 |
+
except Exception as e:
|
| 60 |
+
print(f"Fehler beim Laden des Modells: {str(e)}")
|
| 61 |
+
|
| 62 |
+
print(result)
|
| 63 |
+
return result
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
gender = 0
|
| 67 |
+
bmi_min, bmi_max, bmi_default = 15, 50, 25
|
| 68 |
+
asthma = 0
|
| 69 |
+
glucose_min, glucose_max, glucose_default = 30, 190, 85
|
| 70 |
+
pulse_min, pulse_max, pulse_default = 40, 70, 180
|
| 71 |
+
|
| 72 |
+
# Create the interface
|
| 73 |
+
iface = gr.Interface(
|
| 74 |
+
fn=predict,
|
| 75 |
+
inputs=[
|
| 76 |
+
gr.components.Radio(["Female", "Male"], label="Gender"),
|
| 77 |
+
gr.components.Slider(minimum=bmi_min, maximum=bmi_max, value=bmi_default, label="BMI"),
|
| 78 |
+
gr.components.Checkbox(label="Asthma"),
|
| 79 |
+
gr.components.Slider(minimum=glucose_min, maximum=glucose_max, value=glucose_default, label="Glucose Level"),
|
| 80 |
+
gr.components.Slider(minimum=pulse_min, maximum=glucose_max, value=pulse_default, label="Pulse")
|
| 81 |
+
],
|
| 82 |
+
outputs=gr.components.Textbox(label="Prediction of stay length"),
|
| 83 |
+
title="Length of Stay - Predictor",
|
| 84 |
+
description="""Enter the values to get a prediction of your length of stay""",
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
# Launch the interface
|
| 88 |
+
iface.launch()
|