|
|
|
import numpy as np |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.preprocessing import StandardScaler |
|
from sklearn.datasets import load_iris |
|
import tensorflow as tf |
|
from keras.models import Sequential |
|
from keras.layers import Dense |
|
import gradio as gr |
|
|
|
|
|
iris = load_iris() |
|
X = iris.data |
|
y = iris.target |
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
|
|
|
scaler = StandardScaler() |
|
X_train = scaler.fit_transform(X_train) |
|
X_test = scaler.transform(X_test) |
|
|
|
|
|
model = Sequential([ |
|
Dense(64, activation='relu', input_dim=4), |
|
Dense(3, activation='softmax') |
|
]) |
|
|
|
|
|
model.compile(optimizer='adam', |
|
loss='sparse_categorical_crossentropy', |
|
metrics=['accuracy']) |
|
|
|
|
|
model.fit(X_train, y_train, epochs=50, batch_size=32, validation_data=(X_test, y_test)) |
|
|
|
|
|
def predict_iris_species(sepal_length, sepal_width, petal_length, petal_width): |
|
input_data = np.array([[sepal_length, sepal_width, petal_length, petal_width]]) |
|
scaled_input_data = scaler.transform(input_data) |
|
prediction = model.predict(scaled_input_data) |
|
return iris.target_names[np.argmax(prediction)] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_iris_species, |
|
inputs=[ |
|
gr.Slider(minimum=0, maximum=10, label="Sepal Length"), |
|
gr.Slider(minimum=0, maximum=10, label="Sepal Width"), |
|
gr.Slider(minimum=0, maximum=10, label="Petal Length"), |
|
gr.Slider(minimum=0, maximum=10, label="Petal Width"), |
|
], |
|
outputs=gr.Label(num_top_classes=3), |
|
live=True, |
|
title='Detector de especies de iris, en Red Neuronal', |
|
description='Este modelo est谩 desarrollado para la clasificaci贸n Multiclase de flores de la especie Iris.', |
|
article= 'Autor: <a href=\"https://huggingface.co/Antonio49\">Antonio Fern谩ndez</a> de <a href=\"https://saturdays.ai/\">SaturdaysAI</a>. Aplicaci贸n desarrollada con fines docentes', |
|
theme='peach', |
|
examples = [[5,7,0,0], |
|
[0,1,2,8]] |
|
) |
|
|
|
|
|
iface.launch() |