File size: 923 Bytes
0ee0725 54e24db 0ee0725 54e24db 0ee0725 54e24db 0ee0725 54e24db 0ee0725 54e24db 0ee0725 54e24db |
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 30 31 32 33 34 35 36 |
import joblib
import numpy as np
from sklearn import datasets
import gradio as gr
import os
# Load the model and class names
if os.path.exists('new_iris_model.pkl'):
model = joblib.load('new_iris_model.pkl')
else:
model = joblib.load('iris_model.pkl')
iris = datasets.load_iris()
class_names = iris.target_names
# Define prediction function
def predict_species(sepal_length, sepal_width, petal_length, petal_width):
features = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
prediction = model.predict(features)[0]
return f"Iris {class_names[prediction]}"
# Create Gradio interface
demo = gr.Interface(
fn=predict_species,
inputs=[
gr.Number(label="Sepal Length"),
gr.Number(label="Sepal Width"),
gr.Number(label="Petal Length"),
gr.Number(label="Petal Width")
],
outputs="text",
title="Iris Flower Classifier"
)
demo.launch()
|