File size: 968 Bytes
26c6fdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
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()