|
import gradio as gr |
|
from model import SmokerModel |
|
import numpy as np |
|
|
|
MODEL = SmokerModel("ensemble_softvoting_model.joblib","min_max_scaler.joblib") |
|
|
|
def predict( |
|
age, height, weight, |
|
waist, eye_L, eye_R, |
|
hear_L, hear_R, systolic, |
|
relaxation, fasting_blood_sugar, cholesterol, |
|
triglyceride, HDL, LDL, |
|
hemoglobin, urine_protein, |
|
serum_creatinine, AST, ALT, |
|
Gtp, dental_caries |
|
): |
|
''' |
|
Predict the label for the data inputed |
|
''' |
|
|
|
input_array = np.array([ |
|
age, height, weight, |
|
waist, eye_L, eye_R, |
|
hear_L, hear_R, systolic, |
|
relaxation, fasting_blood_sugar, cholesterol, |
|
triglyceride, HDL, LDL, |
|
hemoglobin, urine_protein, |
|
serum_creatinine, AST, ALT, |
|
Gtp, dental_caries |
|
]) |
|
|
|
|
|
label = MODEL.predict(input_array) |
|
|
|
return label |
|
|
|
def load_interface(): |
|
''' |
|
Configure Gradio interface |
|
''' |
|
|
|
info_page = gr.Blocks() |
|
model_page = gr.Blocks() |
|
|
|
with info_page: |
|
|
|
gr.Markdown( |
|
""" |
|
# Ensemble Classifier for Predicting Smoker or Non-Smoker |
|
|
|
Contributors: Matt Soria, Jake Leniart, Francisco Lozano |
|
University: Depaul University |
|
Class: DSC 478, Programming Machine Learning |
|
--- |
|
|
|
## Overview |
|
For our project we decided to create a classifer for a kaggle dataset that has bio-signals along with information on whether individuals are smokers or non-smokers. Our classifier attempts to identify whether or not a patient is a smoker based on the 22 features provided. |
|
[Smoker Dataset](https://www.kaggle.com/datasets/gauravduttakiit/smoker-status-prediction-using-biosignals?resource=download&select=train_dataset.csv). |
|
|
|
## Classifier Metrics |
|
|
|
TODO: insert the classification report and confusion matrix |
|
|
|
## Report |
|
To learn more about our Ensemble Classifier, view our jupyter notebooks in our repo. |
|
[DSC 478 Project Repo](https://github.com/msoria17/dsc478-project) |
|
""" |
|
) |
|
|
|
with model_page: |
|
|
|
gr.Markdown( |
|
""" |
|
# Interact with the Ensemble Classifier Model |
|
Enter sample bio data to predict smoking status. |
|
Medical Disclaimer: The predictions provided by this model are for educational purposes only and should not be considered a substitute for professional medical advice. |
|
""") |
|
|
|
|
|
with gr.Row(): |
|
age = gr.Number(label="Age", precision=0, minimum=0) |
|
height = gr.Number(label="Height(cm)", precision=0, minimum=0) |
|
weight = gr.Number(label="Weight(kg)", precision=0, minimum=0) |
|
with gr.Row(): |
|
waist = gr.Number(label="Waist(cm)", minimum=0, info="Waist circumference length") |
|
eye_L = gr.Number(label="Visual acuity of the left eye, measured in diopters (D)", minimum=0) |
|
eye_R = gr.Number(label="Visual acuity of the right eye, measured in diopters (D)", minimum=0) |
|
with gr.Row(): |
|
hear_L = gr.Radio(label="Is there any hearing ability in the left ear?",choices=[("Yes",1),("No",2)]) |
|
hear_R = gr.Radio(label="Is there any hearing ability in the right ear?",choices=[("Yes",1),("No",2)]) |
|
systolic = gr.Number(label="Systolic(mmHg)", precision=0, minimum=0, info="Blood Pressure") |
|
with gr.Row(): |
|
relaxation = gr.Number(label="Relaxation(mmHg)", precision=0, minimum=0, info="Blood Pressure") |
|
fasting_blood_sugar = gr.Number(label="Fasting Blood Sugar(mg/dL)", precision=0, minimum=0, info="the concentration of glucose (sugar) in the bloodstream after an extended period of fasting") |
|
cholesterol = gr.Number(label="Total Cholesterol(mg/dL)", precision=0, minimum=0, info="Total amount of cholesterol present in the blood") |
|
with gr.Row(): |
|
triglyceride = gr.Number(label="Triglyceride(mg/dL)", precision=0, minimum=0, info="A type of fat (lipid) found in blood") |
|
HDL = gr.Number(label="High-Density Lipoprotein(mg/dL) ", precision=0, minimum=0, info="It is commonly referred to as 'good cholesterol'") |
|
LDL = gr.Number(label="Low-Density Lipoprotein(mg/dL) ", precision=0, minimum=0, info="It is commonly referred to as 'bad cholesterol'") |
|
with gr.Row(): |
|
hemoglobin = gr.Number(label="Hemoglobin(g/dL)", minimum=0, info="a protein found in red blood cells that is responsible for carrying oxygen from the lungs to the tissues and organs of the body") |
|
urine_protein = gr.Radio(label="Does urine contain excessive traces of protein?",choices=[("Yes",2),("No",1)], info="when excessive protein is detected in the urine, it may indicate a problem with kidney function or other underlying health conditions.") |
|
serum_creatinine = gr.Number(label="Serum creatinine(mg/dL)", minimum=0, info="Serum creatinine levels are commonly measured through a blood test and are used to assess kidney function") |
|
with gr.Row(): |
|
AST = gr.Number(label="Aspartate Aminotransferase(IU/L)", precision=0, minimum=0, info="glutamic oxaloacetic transaminase type; AST is released into the bloodstream when cells are damaged or destroyed, such as during injury or disease affecting organs rich in AST.") |
|
ALT = gr.Number(label="Alanine Aminotransferase(IU/L)", precision=0, minimum=0, info="glutamic oxaloacetic transaminase type; ALT is primarily found in the liver cells, and increased levels of ALT in the blood can indicate liver damage or disease") |
|
Gtp = gr.Number(label="Gamma-glutamyl Transferase(IU/L)", precision=0, minimum=0, info="Elevated levels of GGT in the blood can indicate liver disease or bile duct obstruction. GGT levels are often measured alongside other liver function tests to assess liver health and function.") |
|
dental_caries = gr.Radio(label="Are there any signs of dental cavities?",choices=[("Yes",1),("No",0)]) |
|
|
|
|
|
with gr.Row(): |
|
pred_btn = gr.Button("Predict") |
|
clear_btn = gr.Button("Clear") |
|
|
|
|
|
|
|
smoker_label = gr.Label(label="Predicted Label") |
|
|
|
|
|
inputs = [age, height, weight, waist, eye_L, eye_R, hear_L, hear_R, systolic, relaxation, fasting_blood_sugar, cholesterol, triglyceride, HDL, LDL, hemoglobin, urine_protein, serum_creatinine, AST, ALT, Gtp, dental_caries] |
|
pred_btn.click(fn=predict, inputs=inputs, outputs=smoker_label) |
|
clear_btn.click(lambda: [None]*22, outputs=inputs) |
|
|
|
|
|
iface = gr.TabbedInterface( |
|
[info_page, model_page], |
|
["Information", "Smoker Model"] |
|
) |
|
|
|
|
|
|
|
iface.launch(server_name="0.0.0.0", server_port=7860) |
|
|
|
if __name__ == "__main__": |
|
load_interface() |