criticalDanger's picture
Update app.py
a40d01f verified
raw
history blame
3.22 kB
import gradio as gr
import numpy as np
import pickle
# Load the trained model
with open('asthma_disease_model.pkl', 'rb') as file:
model = pickle.load(file)
# Define the prediction function
def predict_heart_disease(Age, Gender, BMI, Smoking, PhysicalActivity, DietQuality, SleepQuality, PollutionExposure, PollenExposure, DustExposure, PetAllergy, FamilyHistoryAsthma, HistoryOfAllergies, Eczema, HayFever, GastroesophagealReflux, Wheezing, ShortnessOfBreath, ChestTightness, Coughing, NighttimeSymptoms, ExerciseInduced):
Gender = 0 if Gender == "Male" else 1
Smoking = 1 if Smoking else 0
PetAllergy = 1 if PetAllergy else 0
FamilyHistoryAsthma = 1 if FamilyHistoryAsthma else 0
HistoryOfAllergies = 1 if HistoryOfAllergies else 0
Eczema = 1 if Eczema else 0
HayFever = 1 if HayFever else 0
GastroesophagealReflux = 1 if GastroesophagealReflux else 0
Wheezing = 1 if Wheezing else 0
ShortnessOfBreath = 1 if ShortnessOfBreath else 0
ChestTightness = 1 if ChestTightness else 0
Coughing = 1 if Coughing else 0
NighttimeSymptoms = 1 if NighttimeSymptoms else 0
ExerciseInduced = 1 if ExerciseInduced else 0
input_data = np.array([[Age, Gender, BMI, Smoking, PhysicalActivity, DietQuality, SleepQuality, PollutionExposure, PollenExposure, DustExposure, PetAllergy, FamilyHistoryAsthma, HistoryOfAllergies, Eczema, HayFever, GastroesophagealReflux, Wheezing, ShortnessOfBreath, ChestTightness, Coughing, NighttimeSymptoms, ExerciseInduced]])
prediction = model.predict(input_data)
return 'Heart Disease' if prediction[0] == 1 else 'No Heart Disease'
# Define the input components
inputs = [
gr.Number(label="Age"),
gr.Radio(choices=["Male","Female"], label="Sex"),
gr.Number(value=float, label="What is your BMI?"),
gr.Checkbox(label="Do you smoke?"),
gr.Slider(label="Rate your physical activeness", minimum=0, maximum=10, step=1),
gr.Slider(label="Rate your diet quality", minimum=0, maximum=10, step=1),
gr.Slider(label="Rate your sleep quality", minimum=4, maximum=10, step=1),
gr.Slider(label="Rate your pollution exposure", minimum=0, maximum=10, step=1),
gr.Slider(label="Rate your pollen exposure", minimum=0, maximum=10, step=1),
gr.Slider(label="Rate your dust exposure", minimum=0, maximum=10, step=1),
gr.Checkbox(label="Do you have Pet Allergy?"),
gr.Checkbox(label="Does your family have a history of Asthma"),
gr.Checkbox(label="Do you have history of allergies?"),
gr.Checkbox(label="Do you have Eczema?"),
gr.Checkbox(label="Do you have Hay fever?"),
gr.Checkbox(label="Do you have Gastroesophageal Reflux?"),
gr.Checkbox(label="Do you wheeze?"),
gr.Checkbox(label="Do you feel shortness of breath?"),
gr.Checkbox(label="Do you feel chest tightness?"),
gr.Checkbox(label="Do you Cough very often?"),
gr.Checkbox(label="Do you these symptoms occur in the night time?"),
gr.Checkbox(label="Do you these symptoms occur during exercise?"),
]
# Define the output component
outputs = gr.Textbox(label="Prediction")
# Create and launch the Gradio interface
gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs=outputs).launch()