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)