JaviSwift's picture
Update app.py
04c17c3 verified
raw
history blame
881 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
model = tf.keras.models.load_model("hf://JaviSwift/cifar10_simple")
def predict_image(img):
"""
Realiza la predicción sobre la imagen dada usando el modelo Keras.
"""
img = tf.image.resize(img, (32, 32))
img = img / 255.0
img = np.expand_dims(img, axis=0)
prediction = model.predict(img)
predicted_class = np.argmax(prediction)
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
predicted_label = class_names[predicted_class]
return predicted_label
iface = gr.Interface(
fn=predict_image,
inputs=gr.Image(label="Sube una imagen"),
outputs=gr.Label(label="Resultado"),
title="Detector de Objetos con CNN",
description="Sube una imagen y el modelo CNN predecirá el objeto."
)
iface.launch()