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 'You have a significant chance of having asthma.' if prediction[0] == 1 else 'You possibly do not have asthma.' # Define the input components inputs = [ gr.Number(label="Age", minimum=5, maximum=80), gr.Radio(choices=["Male","Female"], label="Sex"), gr.Number(value=float, label="What is your BMI?", minimum=13, maximum=40), 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") # Define custom css for the interface custom_css = """ body { background-color: white; colour: black; } .gradio-container { background-color: white; } .gradio-interface input, .gradio-interface select { background-color: #f0f0f0; color: black; } """ # Create and launch the Gradio interface gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs=outputs, css=custom_css).launch()