|
import gradio as gr |
|
import joblib |
|
import numpy as np |
|
import pandas as pd |
|
from sklearn.datasets import load_breast_cancer |
|
|
|
|
|
pipeline = joblib.load('knn_pipeline.joblib') |
|
|
|
|
|
data = load_breast_cancer() |
|
feature_names = data.feature_names |
|
|
|
|
|
def predict_cancer(*input_data): |
|
|
|
input_array = np.array([input_data]) |
|
input_df = pd.DataFrame(input_array, columns=feature_names) |
|
|
|
prediction = pipeline.predict(input_df) |
|
|
|
target_names = ['malignant', 'benign'] |
|
return target_names[prediction[0]] |
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
with gr.Column(): |
|
col1 = [gr.Slider(label=feature, minimum=0, maximum=10000, step=0.1) for feature in feature_names[:10]] |
|
with gr.Column(): |
|
col2 = [gr.Slider(label=feature, minimum=0, maximum=10000, step=0.1) for feature in feature_names[10:20]] |
|
with gr.Column(): |
|
col3 = [gr.Slider(label=feature, minimum=0, maximum=10000, step=0.1) for feature in feature_names[20:]] |
|
|
|
outputs = gr.Textbox(label="Prediction") |
|
btn = gr.Button("Predict") |
|
btn.click(fn=predict_cancer, inputs=col1 + col2 + col3, outputs=outputs) |
|
|
|
demo.launch() |
|
|