Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,41 @@
|
|
| 1 |
-
import
|
| 2 |
-
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
-
import
|
| 5 |
import sklearn
|
| 6 |
|
|
|
|
| 7 |
model_file = "model-3.pkl"
|
| 8 |
try:
|
| 9 |
-
with open(model_file,'rb') as file:
|
| 10 |
model = pickle.load(file)
|
| 11 |
except FileNotFoundError:
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
+
import pickle
|
| 4 |
import sklearn
|
| 5 |
|
| 6 |
+
# Load your trained model
|
| 7 |
model_file = "model-3.pkl"
|
| 8 |
try:
|
| 9 |
+
with open(model_file, 'rb') as file:
|
| 10 |
model = pickle.load(file)
|
| 11 |
except FileNotFoundError:
|
| 12 |
+
raise FileNotFoundError("Model file 'model-3.pkl' not found in the directory.")
|
| 13 |
|
| 14 |
+
# Define prediction function
|
| 15 |
+
def predict_flower(sepal_length, sepal_width, petal_length, petal_width):
|
| 16 |
+
features = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
|
| 17 |
+
prediction = model.predict(features)[0]
|
| 18 |
+
return f"The predicted flower class is: {prediction}"
|
| 19 |
|
| 20 |
+
# Define input and output components
|
| 21 |
+
inputs = [
|
| 22 |
+
gr.Number(label="Sepal Length"),
|
| 23 |
+
gr.Number(label="Sepal Width"),
|
| 24 |
+
gr.Number(label="Petal Length"),
|
| 25 |
+
gr.Number(label="Petal Width")
|
| 26 |
+
]
|
| 27 |
|
| 28 |
+
output = gr.Textbox(label="Prediction Result")
|
| 29 |
+
|
| 30 |
+
# Create the Gradio interface
|
| 31 |
+
demo = gr.Interface(
|
| 32 |
+
fn=predict_flower,
|
| 33 |
+
inputs=inputs,
|
| 34 |
+
outputs=output,
|
| 35 |
+
title="🌸 Flower Classification on IRIS Dataset",
|
| 36 |
+
description="Enter the flower's sepal and petal measurements to predict its species using a trained ML model."
|
| 37 |
+
)
|
| 38 |
|
| 39 |
+
# Launch the Gradio app
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
demo.launch()
|