Spaces:
Sleeping
Sleeping
import joblib | |
import pandas as pd | |
import gradio as gr | |
class BioQuest: | |
def __init__(self): | |
self.liver_model = None | |
def load_liver_model(self, model_path): | |
self.liver_model = joblib.load(model_path) | |
def liver_prediction(self, input_values): | |
feature_names = [ | |
'age', 'gender', 'total_bilirubin', 'alkaline_phosphotase', | |
'alamine_aminotransferase', 'albumin_and_globulin_ratio' | |
] | |
input_data = dict(zip(feature_names, input_values)) | |
input_df = pd.DataFrame([input_data]) | |
result = self.liver_model.predict(input_df) | |
if result[0] == 0: | |
return 'The person does not have liver disease.' | |
else: | |
return 'The person has liver disease.' | |
# Load the model | |
bioquest = BioQuest() | |
bioquest.load_liver_model('liver_model.sav') | |
# Define the Gradio prediction function | |
def predict_liver_disease(age, gender, total_bilirubin, alkaline_phosphotase, | |
alamine_aminotransferase, albumin_and_globulin_ratio): | |
input_values = [ | |
age, | |
1 if gender == "Male" else 0, | |
total_bilirubin, | |
alkaline_phosphotase, | |
alamine_aminotransferase, | |
albumin_and_globulin_ratio | |
] | |
# Get the prediction from the BioQuest instance | |
prediction = bioquest.liver_prediction(input_values) | |
return prediction,image_url | |
# Image URL | |
image_url = "liver.PNG" | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=predict_liver_disease, | |
inputs=[ | |
gr.Slider(minimum=1, maximum=100, value=65, label="Age"), | |
gr.Radio(choices=["Male", "Female"], label="Gender", value="Female"), | |
gr.Slider(minimum=0.0, maximum=10.0, step=0.01, value=0.7, label="Total Bilirubin"), | |
gr.Slider(minimum=0, maximum=500, value=187, label="Alkaline Phosphotase"), | |
gr.Slider(minimum=0, maximum=500, value=16, label="Alamine Aminotransferase"), | |
gr.Slider(minimum=0.0, maximum=10.0, step=0.01, value=0.9, label="Albumin and Globulin Ratio") | |
], | |
outputs=[ | |
gr.Text(label="Prediction"), | |
gr.Image(value=image_url, label="Image", show_label=True) # Set the image to be static | |
], | |
title="Liver Disease Prediction", | |
description="Enter the patient's details to predict the likelihood of liver disease." | |
) | |
# Launch the interface | |
iface.launch() | |