irisapp / app.py
sunil11r's picture
Update app.py
6091059 verified
Raw History Blame Contribute Delete
940 Bytes
import gradio as gr
import numpy as np
import pickle
# Load the trained model
model = pickle.load(open('model.pkl', 'rb'))
iris_labels = ['Setosa', 'Versicolor', 'Virginica']
# Define the prediction function
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
data = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
prediction = model.predict(data)[0]
return f"Predicted Iris Species: {iris_labels[prediction]}"
# Create the 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="text",
title="Iris Species Predictor",
description="Enter the flower's measurements to predict the Iris species."
)
# Launch the app
if __name__ == "__main__":
iface.launch()