Zakia's picture
Upload 3 files
3c4b4cb
raw
history blame
1.1 kB
# Bismillahir Rahmaanir Raheem
# Almadadh Ya Gause Radi Allahu Ta'alah Anh - Ameen
import pickle
import gradio as gr
# Load the trained model from .pkl file
with open('iris_decision_tree_model.pkl', 'rb') as file:
clf = pickle.load(file)
# Import iris dataset for target names
from sklearn import datasets
iris = datasets.load_iris()
# 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[int(prediction[0])]
# Create and launch the Gradio interface
interface = gr.Interface(
fn=predict_iris,
inputs=["number", "number", "number", "number"],
outputs="text",
live=True,
title="Iris Flower Model",
description="An introductory example of machine learning in Python. An iris flower model trained on the iris flower dataset using the decision tree algorithm. The accuracy of the model is: 97.37%. Input the dimensions of the iris flower's sepal and petal to predict its species."
)
interface.launch()