File size: 1,328 Bytes
9bd3242
 
 
7d8af34
9bd3242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import joblib
import numpy as np
import pandas as pd
from sklearn.datasets import load_breast_cancer

# Load the pipeline
pipeline = joblib.load('knn_pipeline.joblib')

# Load the data to get feature names
data = load_breast_cancer()
feature_names = data.feature_names


def predict_cancer(*input_data):
    # Convert input data to a DataFrame with feature names
    input_array = np.array([input_data])
    input_df = pd.DataFrame(input_array, columns=feature_names)
    # Use the pipeline to predict
    prediction = pipeline.predict(input_df)
    # Map prediction to target names
    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()