Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pickle
|
| 3 |
|
| 4 |
-
# Load model
|
| 5 |
model = pickle.load(open("model.pkl", "rb"))
|
| 6 |
|
| 7 |
-
# Flower labels
|
| 8 |
flowers = ["Setosa", "Versicolor", "Virginica"]
|
| 9 |
|
| 10 |
-
# Image URLs (you can also store locally)
|
| 11 |
-
flower_images = {
|
| 12 |
-
"Setosa": "",
|
| 13 |
-
"Versicolor": "https://upload.wikimedia.org/wikipedia/commons/4/41/Iris_versicolor_3.jpg",
|
| 14 |
-
"Virginica": "https://upload.wikimedia.org/wikipedia/commons/9/9f/Iris_virginica.jpg"
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
|
| 18 |
def predict(sl, sw, pl, pw):
|
| 19 |
data = [[sl, sw, pl, pw]]
|
| 20 |
pred = model.predict(data)[0]
|
| 21 |
-
|
| 22 |
-
flower_name = flowers[pred]
|
| 23 |
-
image = flower_images[flower_name]
|
| 24 |
-
|
| 25 |
-
return flower_name, image
|
| 26 |
|
| 27 |
-
# Gradio Interface
|
| 28 |
interface = gr.Interface(
|
| 29 |
fn=predict,
|
| 30 |
inputs=[
|
|
@@ -33,11 +18,8 @@ interface = gr.Interface(
|
|
| 33 |
gr.Number(label="Petal Length"),
|
| 34 |
gr.Number(label="Petal Width")
|
| 35 |
],
|
| 36 |
-
outputs=
|
| 37 |
-
|
| 38 |
-
gr.Image(label="Flower Image")
|
| 39 |
-
],
|
| 40 |
-
title="🌸 Flower Prediction with Image"
|
| 41 |
)
|
| 42 |
|
| 43 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pickle
|
| 3 |
|
|
|
|
| 4 |
model = pickle.load(open("model.pkl", "rb"))
|
| 5 |
|
|
|
|
| 6 |
flowers = ["Setosa", "Versicolor", "Virginica"]
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def predict(sl, sw, pl, pw):
|
| 9 |
data = [[sl, sw, pl, pw]]
|
| 10 |
pred = model.predict(data)[0]
|
| 11 |
+
return flowers[pred]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
| 13 |
interface = gr.Interface(
|
| 14 |
fn=predict,
|
| 15 |
inputs=[
|
|
|
|
| 18 |
gr.Number(label="Petal Length"),
|
| 19 |
gr.Number(label="Petal Width")
|
| 20 |
],
|
| 21 |
+
outputs="text",
|
| 22 |
+
title="🌸 Flower Prediction App"
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
interface.launch()
|