Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,29 @@
|
|
| 1 |
-
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
import joblib
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
model = joblib.load("model.joblib")
|
| 9 |
labels = ["setosa", "versicolor", "virginica"]
|
| 10 |
|
| 11 |
-
|
| 12 |
-
sepal_length
|
| 13 |
-
sepal_width: float
|
| 14 |
-
petal_length: float
|
| 15 |
-
petal_width: float
|
| 16 |
-
|
| 17 |
-
@app.get("/")
|
| 18 |
-
def home():
|
| 19 |
-
return {"status": "Iris API is running"}
|
| 20 |
-
|
| 21 |
-
@app.post("/predict")
|
| 22 |
-
def predict(data: IrisInput):
|
| 23 |
-
X = np.array([[data.sepal_length, data.sepal_width,
|
| 24 |
-
data.petal_length, data.petal_width]])
|
| 25 |
probs = model.predict_proba(X)[0]
|
| 26 |
idx = probs.argmax()
|
| 27 |
-
return {
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
if __name__ == "__main__":
|
| 34 |
-
import uvicorn
|
| 35 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
import joblib
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
# Load model
|
|
|
|
| 6 |
model = joblib.load("model.joblib")
|
| 7 |
labels = ["setosa", "versicolor", "virginica"]
|
| 8 |
|
| 9 |
+
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
|
| 10 |
+
X = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
probs = model.predict_proba(X)[0]
|
| 12 |
idx = probs.argmax()
|
| 13 |
+
return f"{labels[idx]} (Confidence: {probs[idx]:.2f})"
|
| 14 |
+
|
| 15 |
+
# Gradio UI
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=predict_iris,
|
| 18 |
+
inputs=[
|
| 19 |
+
gr.Number(label="Sepal Length (cm)"),
|
| 20 |
+
gr.Number(label="Sepal Width (cm)"),
|
| 21 |
+
gr.Number(label="Petal Length (cm)"),
|
| 22 |
+
gr.Number(label="Petal Width (cm)")
|
| 23 |
+
],
|
| 24 |
+
outputs=gr.Textbox(label="Prediction"),
|
| 25 |
+
title="🌸 Iris Flower Classification",
|
| 26 |
+
description="Enter flower measurements to predict the Iris species"
|
| 27 |
+
)
|
| 28 |
|
| 29 |
+
interface.launch()
|
|
|
|
|
|
|
|
|