Spaces:
Sleeping
Sleeping
File size: 1,048 Bytes
2a0985b 3bf3105 f2fdad2 3bf3105 ff291aa f2fdad2 d2e0005 f2fdad2 ff291aa 4ca6dc6 f2fdad2 ff291aa f2fdad2 ff291aa |
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 |
import gradio as gr
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing import image
# Cargar el modelo
def load_model():
return tf.keras.models.load_model("modelo_frutas_transfer.keras")
model = load_model()
# Clases del modelo
class_names = ['Fresa', 'Limon', 'Manzana', 'Pera', 'Platano', 'Uva']
# Funci贸n de predicci贸n usando imagen PIL
def predict_image(img):
img = img.resize((150, 150)) # Asegurar tama帽o
img_array = image.img_to_array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
pred = model.predict(img_array)
predicted_class = np.argmax(pred, axis=1)[0]
return class_names[predicted_class]
# Interfaz Gradio (sin "tool", con PIL)
iface = gr.Interface(
fn=predict_image,
inputs=gr.Image(type="pil", label="馃摲 Sube una imagen de fruta", height=300),
outputs=gr.Textbox(label="馃崕 Predicci贸n de la clase"),
title="Clasificador de Frutas",
description="Sube una imagen de una fruta y el modelo predecir谩 qu茅 fruta es."
)
iface.launch()
|