Spaces:
Sleeping
Sleeping
File size: 2,366 Bytes
bc15f08 14b9946 bc15f08 14b9946 bc15f08 e2706f0 bc15f08 e2706f0 bc15f08 14b9946 e2706f0 a7d93c6 bc15f08 14b9946 bc15f08 14b9946 bc15f08 14b9946 bc15f08 14b9946 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
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()
|