Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,10 @@ import tensorflow as tf
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
-
#
|
| 7 |
etiquetas = ['apple', 'car', 'cloud', 'moon', 'stop sign']
|
| 8 |
|
| 9 |
-
#
|
| 10 |
model = tf.keras.models.load_model("quickdraw_model.keras")
|
| 11 |
|
| 12 |
def procesar_imagen(image):
|
|
@@ -17,24 +17,27 @@ def procesar_imagen(image):
|
|
| 17 |
image = cv2.resize(image, (28, 28), interpolation=cv2.INTER_AREA)
|
| 18 |
# Normalizar (0-1)
|
| 19 |
image = image / 255.0
|
| 20 |
-
# Invertir: fondo negro, trazo blanco
|
| 21 |
image = 1.0 - image
|
| 22 |
-
#
|
| 23 |
-
image = image.reshape(1, 784)
|
| 24 |
-
return image
|
| 25 |
|
| 26 |
def predict(image):
|
| 27 |
image_proc = procesar_imagen(image)
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
class_idx = np.argmax(preds)
|
| 30 |
-
return etiquetas[class_idx]
|
| 31 |
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=predict,
|
| 34 |
inputs=gr.Image(image_mode='L', label="Dibuja o sube una imagen (trazo negro, fondo blanco)"),
|
| 35 |
-
outputs=
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
+
# Lista de etiquetas (ajusta seg煤n tus clases)
|
| 7 |
etiquetas = ['apple', 'car', 'cloud', 'moon', 'stop sign']
|
| 8 |
|
| 9 |
+
# Carga el modelo
|
| 10 |
model = tf.keras.models.load_model("quickdraw_model.keras")
|
| 11 |
|
| 12 |
def procesar_imagen(image):
|
|
|
|
| 17 |
image = cv2.resize(image, (28, 28), interpolation=cv2.INTER_AREA)
|
| 18 |
# Normalizar (0-1)
|
| 19 |
image = image / 255.0
|
| 20 |
+
# Invertir colores: fondo negro, trazo blanco
|
| 21 |
image = 1.0 - image
|
| 22 |
+
return image # NO lo aplanes aqu铆, as铆 puedes mostrarlo
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def predict(image):
|
| 25 |
image_proc = procesar_imagen(image)
|
| 26 |
+
# Para el modelo, s铆 lo aplanas
|
| 27 |
+
image_for_model = image_proc.reshape(1, 784)
|
| 28 |
+
preds = model.predict(image_for_model)
|
| 29 |
class_idx = np.argmax(preds)
|
| 30 |
+
return etiquetas[class_idx], image_proc
|
| 31 |
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=predict,
|
| 34 |
inputs=gr.Image(image_mode='L', label="Dibuja o sube una imagen (trazo negro, fondo blanco)"),
|
| 35 |
+
outputs=[
|
| 36 |
+
gr.Label(num_top_classes=1, label="Predicci贸n"),
|
| 37 |
+
gr.Image(shape=(28, 28), image_mode='L', label="Imagen preprocesada (lo que ve la IA)")
|
| 38 |
+
],
|
| 39 |
+
title="QuickDraw API (con imagen preprocesada)",
|
| 40 |
+
description="Sube tu dibujo (fondo blanco, trazo negro). La IA mostrar谩 la predicci贸n y la imagen final con la que realmente predice."
|
| 41 |
)
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|