Spaces:
Runtime error
Runtime error
#!/usr/bin/env python | |
# coding: utf-8 | |
# In[1]: | |
import warnings | |
warnings.simplefilter("ignore") | |
import pandas as pd | |
import numpy as np | |
from sklearn.metrics import classification_report, confusion_matrix | |
from sklearn.model_selection import train_test_split | |
import xgboost as xgb | |
from sklearn.preprocessing import LabelEncoder | |
import joblib | |
import gradio as gr | |
import joblib | |
# Define the Gradio input and output interfaces | |
inputs = [ | |
gr.inputs.Dropdown(choices=["0", "1"], label="Gender"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you smoke?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have Yellow Fingers?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have Anxiety?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you get influenced by Peer Pressure?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have any Chronic Disease?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have Fatigue?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have an Allergy?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you experience Wheezing?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you drink alcohol?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Are you Coughing?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have Shortness of Breath?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have Swallowing Difficulty?"), | |
gr.inputs.Dropdown(choices=["0", "1"], label="Do you have Chest Pain?"), | |
gr.inputs.Number(label='What is your Age') | |
] | |
output = gr.outputs.Label(num_top_classes=2) | |
# Define the predict function | |
def predict(gender, smoking, yellow_fingers, anxiety, peer_pressure, | |
chronic_disease, fatigue, allergy, wheezing, alcohol_consuming, | |
coughing, shortness_of_breath, swallowing_difficulty, chest_pain, | |
age): | |
# Create a dataframe with the input values | |
input_dict = {'GENDER': gender, 'SMOKING': smoking, 'YELLOW_FINGERS': yellow_fingers, | |
'ANXIETY': anxiety, 'PEER_PRESSURE': peer_pressure, | |
'CHRONIC DISEASE': chronic_disease, 'FATIGUE ': fatigue, | |
'ALLERGY ': allergy, 'WHEEZING': wheezing, | |
'ALCOHOL CONSUMING': alcohol_consuming, 'COUGHING': coughing, | |
'SHORTNESS OF BREATH': shortness_of_breath, | |
'SWALLOWING DIFFICULTY': swallowing_difficulty, | |
'CHEST PAIN': chest_pain, 'AGE': age} | |
input_df = pd.DataFrame.from_dict([input_dict]).astype("int") | |
dtest = xgb.DMatrix(input_df) | |
#make predictions | |
#load model | |
model = joblib.load("model.pkl") | |
prediction = model.predict(dtest) | |
# Return prediction | |
return "You exhibit symptomps of Lung cancer,you might want to see the Doctor for proper diagnosis ❤." if prediction >0.99 else "You don't seem to have Lung Cancer, Enjoy and take good care of yourself❤" | |
# Create and launch the interface | |
interface = gr.Interface(fn=predict, inputs=inputs, outputs=output, | |
title='Lung Cancer Prediction', description='Predicting lung cancer using XGBoost Classifier.\nPlease Note:\nFemale = 0, Male= 1\nNo = 0, Yes = 1', | |
theme = 'darkhuggingface') | |
interface.launch() | |