Spaces:
Sleeping
Sleeping
| 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() | |