|
!pip install gradio |
|
|
|
import gradio as gr |
|
import pickle |
|
import numpy as np |
|
from sklearn.datasets import load_iris |
|
from sklearn.tree import DecisionTreeClassifier |
|
|
|
|
|
iris = load_iris() |
|
X = iris.data |
|
y = iris.target |
|
|
|
model = DecisionTreeClassifier() |
|
model.fit(X, y) |
|
|
|
|
|
with open('model.pkl', 'wb') as f: |
|
pickle.dump(model, f) |
|
|
|
|
|
with open('model.pkl', 'rb') as f: |
|
model = pickle.load(f) |
|
|
|
def predict(sepal_length, sepal_width, petal_length, petal_width): |
|
input_data = np.array([[sepal_length, sepal_width, petal_length, petal_width]]) |
|
prediction = model.predict(input_data) |
|
return iris.target_names[prediction[0]] |
|
|
|
interface = gr.Interface( |
|
fn=predict, |
|
inputs=["number", "number", "number", "number"], |
|
outputs="text", |
|
title="Iris Flower Classifier", |
|
description="Enter the features of the iris flower to predict its species." |
|
) |
|
|
|
interface.launch() |
|
|