File size: 1,048 Bytes
2afb4ce 146fd50 2afb4ce |
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 |
from huggingface_hub import hf_hub_download
import joblib
import gradio as gr
import numpy as np
# Download the model from Hugging Face Hub
model_path = hf_hub_download(repo_id="suryadev1/knn", filename="knn_model.pkl")
# Load the model
knn = joblib.load(model_path)
# Define the prediction function
def predict(input_data):
# Convert input_data to numpy array
input_data = np.array(input_data).reshape(1, -1)
# Make predictions
predictions = knn.predict([[0.2,0.03,0.0,1.0,0.0]])
return predictions[0]
# Create Gradio interface
# Adjust the input components based on the number of features your model expects
input_components = [gr.inputs.Number(label=f"Feature {i+1}") for i in range(4)]
output_component = gr.outputs.Textbox(label="Prediction")
iface = gr.Interface(
fn=predict,
inputs=input_components,
outputs=output_component,
title="KNN Model Prediction",
description="Enter values for each feature to get a prediction."
)
# Launch the interface
iface.launch()
|