File size: 841 Bytes
d0ecead |
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 |
import gradio as gr
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
# Load the Iris dataset and train a model
iris = load_iris()
X, y = iris.data, iris.target
clf = RandomForestClassifier()
clf.fit(X, y)
# Define the prediction function
def predict_iris(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]]
# Create the Gradio interface
iface = gr.Interface(
fn=predict_iris,
inputs=[
gr.components.Number(label="Sepal Length (cm)"),
gr.components.Number(label="Sepal Width (cm)"),
gr.components.Number(label="Petal Length (cm)"),
gr.components.Number(label="Petal Width (cm)")
],
outputs="text"
)
iface.launch()
|