Team Ai
Apppublic

SebastianHVL/MachineLearning

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
app.py86 linesDownload Raw Back to root
1import gradio as gr2import pandas as pd3import joblib4 5 6def predict(gender, bmi, asthma, glucose, pulse):7 8    gender_char = 19    if gender == "Female":10        gender_char = 011 12    asthma_val = False13    if asthma is True:14        asthma_val = 115 16    # Hardcoded Values are the mean of the training_data.csv17    pred_data = {18        "id": 0,19        "rcount": 1.1178,20        "gender": gender_char,21        "dialysisrenalendstage": False,22        "asthma": asthma_val,23        "irondef": False,24        "pneum": False,25        "substancedependence": False,26        "psychologicaldisordermajor": False,27        "depress": False,28        "psychother": False,29        "fibrosisandother": False,30        "malnutrition": False,31        "hemo": False,32        "hematocrit": False,33        "neutrophils": False,34        "sodium": 137.89369109187714,35        "glucose": glucose,36        "bloodureanitro": 14.101120748294186,37        "creatinine": 1.0994443932147715,38        "bmi": bmi,39        "pulse": pulse,40        "respiration": 6.491511666666584,41        "secondarydiagnosisnonicd9": 0,42        "facid": 043    }44 45    features = ['id', 'rcount', 'gender', 'dialysisrenalendstage', 'asthma', 'irondef', 'pneum', 'substancedependence',46                'psychologicaldisordermajor', 'depress', 'psychother', 'fibrosisandother', 'malnutrition', 'hemo',47                'hematocrit', 'neutrophils', 'sodium', 'glucose', 'bloodureanitro', 'creatinine', 'bmi', 'pulse',48                'respiration', 'secondarydiagnosisnonicd9', 'facid']49 50    pred_df = pd.DataFrame([pred_data], columns=features)51    result = "Error in prediction"52 53    try:54        model = joblib.load('data/model.pkl')55        result = model.predict(pred_df)56    except Exception as e:57        print(f"Fehler beim Laden des Modells: {str(e)}")58 59    print(result)60    return result61 62 63gender = 064bmi_min, bmi_max, bmi_default = 15, 50, 2565asthma = 066glucose_min, glucose_max, glucose_default = 30, 190, 8567pulse_min, pulse_max, pulse_default = 40, 70, 18068 69# Create the interface70iface = gr.Interface(71    fn=predict,72    inputs=[73        gr.components.Radio(["Female", "Male"], label="Gender"),74        gr.components.Slider(minimum=bmi_min, maximum=bmi_max, value=bmi_default, label="BMI"),75        gr.components.Checkbox(label="Asthma"),76        gr.components.Slider(minimum=glucose_min, maximum=glucose_max, value=glucose_default, label="Glucose Level"),77        gr.components.Slider(minimum=pulse_min, maximum=glucose_max, value=pulse_default, label="Pulse")78    ],79    outputs=gr.components.Textbox(label="Prediction of stay length"),80    title="Length of Stay - Predictor",81    description="""Enter the values to get a prediction of your length of stay""",82)83 84# Launch the interface85iface.launch()86