Mohit8219's picture
Create app.py
d0ecead verified
raw
history blame contribute delete
841 Bytes
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()