Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,22 +3,21 @@ from sklearn.datasets import load_iris
|
|
| 3 |
from sklearn.tree import DecisionTreeClassifier
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
iris = load_iris()
|
| 8 |
X = pd.DataFrame(iris.data, columns=iris.feature_names)
|
| 9 |
y = iris.target
|
| 10 |
|
| 11 |
-
# Train model
|
| 12 |
model = DecisionTreeClassifier()
|
| 13 |
model.fit(X, y)
|
| 14 |
|
| 15 |
-
#
|
| 16 |
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
|
| 17 |
input_data = [[sepal_length, sepal_width, petal_length, petal_width]]
|
| 18 |
pred = model.predict(input_data)[0]
|
| 19 |
return iris.target_names[pred]
|
| 20 |
|
| 21 |
-
#
|
| 22 |
iface = gr.Interface(
|
| 23 |
fn=predict_iris,
|
| 24 |
inputs=[
|
|
@@ -28,9 +27,10 @@ iface = gr.Interface(
|
|
| 28 |
gr.Number(label="Petal Width (cm)")
|
| 29 |
],
|
| 30 |
outputs=gr.Text(label="Predicted Iris Species"),
|
| 31 |
-
title="Iris Flower
|
| 32 |
-
description="
|
| 33 |
)
|
| 34 |
|
|
|
|
| 35 |
if __name__ == "__main__":
|
| 36 |
-
iface.launch()
|
|
|
|
| 3 |
from sklearn.tree import DecisionTreeClassifier
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
+
# Load and train model
|
| 7 |
iris = load_iris()
|
| 8 |
X = pd.DataFrame(iris.data, columns=iris.feature_names)
|
| 9 |
y = iris.target
|
| 10 |
|
|
|
|
| 11 |
model = DecisionTreeClassifier()
|
| 12 |
model.fit(X, y)
|
| 13 |
|
| 14 |
+
# Prediction function
|
| 15 |
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
|
| 16 |
input_data = [[sepal_length, sepal_width, petal_length, petal_width]]
|
| 17 |
pred = model.predict(input_data)[0]
|
| 18 |
return iris.target_names[pred]
|
| 19 |
|
| 20 |
+
# Gradio interface
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=predict_iris,
|
| 23 |
inputs=[
|
|
|
|
| 27 |
gr.Number(label="Petal Width (cm)")
|
| 28 |
],
|
| 29 |
outputs=gr.Text(label="Predicted Iris Species"),
|
| 30 |
+
title="Iris Flower Classifier",
|
| 31 |
+
description="A Decision Tree model to classify Iris species based on flower measurements."
|
| 32 |
)
|
| 33 |
|
| 34 |
+
# Launch app with explicit host and port for Hugging Face
|
| 35 |
if __name__ == "__main__":
|
| 36 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|