Spaces:
Sleeping
Sleeping
Upload app (6).py
Browse files- app (6).py +32 -0
app (6).py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import joblib
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the trained model
|
7 |
+
model = joblib.load("iris_decision_tree.pkl")
|
8 |
+
|
9 |
+
# Prediction function
|
10 |
+
def predict_species(sepal_length, sepal_width, petal_length, petal_width):
|
11 |
+
input_data = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
|
12 |
+
prediction = model.predict(input_data)[0]
|
13 |
+
species = ["setosa", "versicolor", "virginica"]
|
14 |
+
return f"The predicted Iris species is: 🌸 {species[prediction]}"
|
15 |
+
|
16 |
+
# Gradio interface
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=predict_species,
|
19 |
+
inputs=[
|
20 |
+
gr.Number(label="Sepal Length (cm)"),
|
21 |
+
gr.Number(label="Sepal Width (cm)"),
|
22 |
+
gr.Number(label="Petal Length (cm)"),
|
23 |
+
gr.Number(label="Petal Width (cm)")
|
24 |
+
],
|
25 |
+
outputs=gr.Textbox(label="Prediction"),
|
26 |
+
title="Iris Flower Species Predictor",
|
27 |
+
description="Enter flower measurements to predict its species using a Decision Tree model."
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the app
|
31 |
+
if __name__ == "__main__":
|
32 |
+
iface.launch()
|