Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
|
| 6 |
+
model_path = hf_hub_download(
|
| 7 |
+
repo_id="USERNAME/iris-sklearn-model",
|
| 8 |
+
filename="model.joblib"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
model = joblib.load(model_path)
|
| 12 |
+
|
| 13 |
+
def predict(sl, sw, pl, pw):
|
| 14 |
+
x = np.array([[sl, sw, pl, pw]])
|
| 15 |
+
pred = model.predict(x)[0]
|
| 16 |
+
return ["setosa", "versicolor", "virginica"][pred]
|
| 17 |
+
|
| 18 |
+
gr.Interface(
|
| 19 |
+
fn=predict,
|
| 20 |
+
inputs=[
|
| 21 |
+
gr.Number(label="Sepal Length"),
|
| 22 |
+
gr.Number(label="Sepal Width"),
|
| 23 |
+
gr.Number(label="Petal Length"),
|
| 24 |
+
gr.Number(label="Petal Width"),
|
| 25 |
+
],
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="Iris Classification (sklearn)"
|
| 28 |
+
).launch()
|