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