ItsEnder's picture
Create app.py
26c6fdc verified
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
# Cargar el modelo desde Hugging Face
model = tf.keras.models.load_model("ItsEnder/demo_model_deploy/resolve/main/model_mobileNetV2_MAX_70batch.h5")
# Funci贸n para preprocesar las im谩genes
def preprocess_image(img):
img = img.resize((224, 224))
img = np.array(img)
img = np.expand_dims(img, axis=0)
img = img / 255.0 # Normalizaci贸n
return img
# Funci贸n para hacer predicciones
def predict(img):
img_array = preprocess_image(img)
prediction = model.predict(img_array)
predicted_class = np.argmax(prediction)
return predicted_class
# Crear la interfaz con Gradio
interface = gr.Interface(
fn=predict,
inputs="image",
outputs="label",
title="Clasificaci贸n de im谩genes con MobileNetV2",
description="Sube una imagen y obt茅n la clase predicha."
)
# Ejecutar la interfaz
interface.launch()