File size: 962 Bytes
5e3a60e dae226f f4226b7 dae226f f4226b7 dae226f |
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 37 38 39 |
!pip install gradio
import gradio as gr
import pickle
import numpy as np
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
# Load iris dataset and train the model
iris = load_iris()
X = iris.data
y = iris.target
model = DecisionTreeClassifier()
model.fit(X, y)
# Save the model
with open('model.pkl', 'wb') as f:
pickle.dump(model, f)
# Load the trained model
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()
|