Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Cargar el modelo
|
| 6 |
+
model = tf.keras.models.load_model("quickdraw_model.keras")
|
| 7 |
+
|
| 8 |
+
def predict(image):
|
| 9 |
+
# La imagen llega como un array (28x28) o RGB, normalizamos y aplanamos
|
| 10 |
+
image = image[...,0] if image.ndim == 3 else image # si es RGB, toma un canal
|
| 11 |
+
image = image / 255.0
|
| 12 |
+
image = image.reshape(1, 784)
|
| 13 |
+
preds = model.predict(image)
|
| 14 |
+
class_idx = np.argmax(preds)
|
| 15 |
+
return class_idx # puedes mapear a etiquetas si quieres
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=predict,
|
| 19 |
+
inputs=gr.inputs.Image(shape=(28, 28), image_mode='L', source='upload'),
|
| 20 |
+
outputs="label",
|
| 21 |
+
title="QuickDraw API",
|
| 22 |
+
description="API para reconocer dibujos estilo QuickDraw"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
iface.launch()
|