Spaces:
Sleeping
Sleeping
import gradio as gr | |
from sklearn import datasets | |
from sklearn.model_selection import train_test_split | |
from sklearn import svm | |
from sklearn import metrics | |
# Load Iris dataset | |
iris = datasets.load_iris() | |
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=42) | |
# Train a Support Vector Classifier | |
clf = svm.SVC(kernel='linear') | |
clf.fit(X_train, y_train) | |
def iris_classifier(sepal_length, sepal_width, petal_length, petal_width): | |
prediction = clf.predict([[sepal_length, sepal_width, petal_length, petal_width]]) | |
return iris.target_names[prediction[0]] | |
iface = gr.Interface( | |
fn=iris_classifier, | |
inputs=["number", "number", "number", "number"], | |
outputs="text", | |
title="Iris Classifier", | |
description="Enter the measurements of an iris flower to predict its species." | |
) | |
iface.launch() | |