Spaces:
Sleeping
Sleeping
File size: 1,284 Bytes
1cfefea 4d40db2 |
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 40 41 42 43 44 |
import gradio as gr
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# Load Iris dataset
iris = load_iris()
X = iris.data
y = iris.target
# Split dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Define model
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
# Train model
model.fit(X_train, y_train)
# Define a function for prediction
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
features = [[sepal_length, sepal_width, petal_length, petal_width]]
prediction = model.predict(features)
return iris.target_names[prediction[0]]
# Create Gradio interface
iris_interface = gr.Interface(
fn=predict_iris,
inputs=["number", "number", "number", "number"],
outputs="text",
title="Iris clarrification model",
description="Measurements --> species prediction.",
examples=[
[5.1, 3.5, 1.4, 0.2],
[6.9, 3.1, 5.4, 2.1]
]
)
# Launch the interface
iris_interface.launch()
|