|
!pip install gradio |
|
|
|
import gradio as gr |
|
import numpy as np |
|
from sklearn.datasets import load_iris |
|
from sklearn.ensemble import RandomForestClassifier |
|
|
|
|
|
iris = load_iris() |
|
X = iris.data |
|
y = iris.target |
|
target_names = iris.target_names |
|
|
|
|
|
clf = RandomForestClassifier(n_estimators=100).fit(X, y) |
|
|
|
|
|
def predict_species(sepal_length, sepal_width, petal_length, petal_width): |
|
features = np.array([sepal_length, sepal_width, petal_length, petal_width]).reshape(1, -1) |
|
prediction = clf.predict(features)[0] |
|
species = target_names[prediction] |
|
return species |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_species, |
|
inputs=["number", "number", "number", "number"], |
|
outputs="text", |
|
title="Iris Species Classification", |
|
description="Predict the species of an Iris flower based on its sepal and petal measurements." |
|
) |
|
|
|
|
|
iface.launch() |
|
|