Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
|
|
| 1 |
import joblib
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import hf_hub_download
|
| 2 |
import joblib
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Download the model from Hugging Face Hub
|
| 7 |
+
model_path = hf_hub_download(repo_id="suryadev1/knn", filename="knn_model.pkl")
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
knn = joblib.load(model_path)
|
| 11 |
+
|
| 12 |
+
# Define the prediction function
|
| 13 |
+
def predict(input_data):
|
| 14 |
+
# Convert input_data to numpy array
|
| 15 |
+
input_data = np.array(input_data).reshape(1, -1)
|
| 16 |
+
# Make predictions
|
| 17 |
+
predictions = knn.predict([[0.2,0.03,0.0,1.0,0.0]])
|
| 18 |
+
return predictions[0]
|
| 19 |
+
|
| 20 |
+
# Create Gradio interface
|
| 21 |
+
# Adjust the input components based on the number of features your model expects
|
| 22 |
+
input_components = [gr.inputs.Number(label=f"Feature {i+1}") for i in range(4)]
|
| 23 |
+
output_component = gr.outputs.Textbox(label="Prediction")
|
| 24 |
+
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=predict,
|
| 27 |
+
inputs=input_components,
|
| 28 |
+
outputs=output_component,
|
| 29 |
+
title="KNN Model Prediction",
|
| 30 |
+
description="Enter values for each feature to get a prediction."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Launch the interface
|
| 34 |
+
iface.launch()
|