Spaces:
Build error
Build error
Upload 3 files
Browse files- .gitattributes +1 -0
- app.py +50 -0
- my_model.keras +3 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
my_model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
|
| 6 |
+
# Etiquetas en espa帽ol
|
| 7 |
+
cifar10_labels = np.array([
|
| 8 |
+
'avi贸n', 'autom贸vil', 'p谩jaro', 'gato', 'venado',
|
| 9 |
+
'perro', 'rana', 'caballo', 'barco', 'cami贸n'
|
| 10 |
+
])
|
| 11 |
+
|
| 12 |
+
# Cargar el modelo al iniciar la app
|
| 13 |
+
model = tf.keras.models.load_model('my_model.keras')
|
| 14 |
+
|
| 15 |
+
def preprocess_image(image):
|
| 16 |
+
"""Preprocesa la imagen para el modelo"""
|
| 17 |
+
img = image.resize((32, 32)) # Redimensionar
|
| 18 |
+
img = np.array(img) # Convertir a numpy array
|
| 19 |
+
img = img.astype('float32') / 255 # Normalizar
|
| 20 |
+
return img.reshape(1, 32, 32, 3) # Reformatear para el modelo
|
| 21 |
+
|
| 22 |
+
def predict(image):
|
| 23 |
+
"""Realiza la predicci贸n y devuelve los resultados"""
|
| 24 |
+
processed_img = preprocess_image(image)
|
| 25 |
+
preds = model.predict(processed_img)[0]
|
| 26 |
+
return {cifar10_labels[i]: float(preds[i]) for i in range(10)}
|
| 27 |
+
|
| 28 |
+
# Configuraci贸n de la interfaz
|
| 29 |
+
title = "Clasificador CIFAR-10 鉁堬笍馃殫"
|
| 30 |
+
description = "Sube una imagen para clasificarla en una de las 10 categor铆as del dataset CIFAR-10"
|
| 31 |
+
examples = [
|
| 32 |
+
['examples/ejemplo_avion.jpg'],
|
| 33 |
+
['examples/ejemplo_caballo.jpg'],
|
| 34 |
+
['examples/ejemplo_perro.jpg'],
|
| 35 |
+
['examples/ejemplo_gato.jpg']
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
# Crear la interfaz Gradio
|
| 39 |
+
interface = gr.Interface(
|
| 40 |
+
fn=predict,
|
| 41 |
+
inputs=gr.Image(type="pil", label="Imagen de entrada"),
|
| 42 |
+
outputs=gr.Label(num_top_classes=3, label="Predicciones"),
|
| 43 |
+
title=title,
|
| 44 |
+
description=description,
|
| 45 |
+
examples=examples,
|
| 46 |
+
theme=gr.themes.Soft()
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Lanzar la aplicaci贸n
|
| 50 |
+
interface.launch()
|
my_model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1eb804b551b6120b59139acfc1c1d007376801365040576ac2794c514809a4d2
|
| 3 |
+
size 26767840
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
gradio
|
| 3 |
+
pillow
|
| 4 |
+
matplotlib
|