Mikeztrada commited on
Commit
3503ee2
verified
1 Parent(s): 5fe6db3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+
6
+ # Cargar modelo
7
+ model = tf.keras.models.load_model("quickdraw_model.keras")
8
+
9
+ # etiquetas usadas en el entrenamiento
10
+ etiquetas = ['apple', 'banana', 'bed', 'carrot', 'laptop']
11
+
12
+ def preprocesar_imagen(image):
13
+ if isinstance(image, np.ndarray):
14
+ image = Image.fromarray(image)
15
+ image = image.convert('L')
16
+ image = image.resize((28, 28), Image.NEAREST)
17
+ arr = np.array(image) / 255.0
18
+ arr_bin = (arr < 0.5).astype(np.float32)
19
+ arr_bin_4d = arr_bin.reshape(1, 28, 28, 1)
20
+ return arr_bin_4d
21
+
22
+ def predict(image):
23
+ x = preprocesar_imagen(image)
24
+ preds = model.predict(x)
25
+ class_idx = np.argmax(preds)
26
+ return {etiquetas[class_idx]: float(preds[0][class_idx])}
27
+
28
+ iface = gr.Interface(
29
+ fn=predict,
30
+ inputs=gr.Image(label="Dibuja o sube una imagen"),
31
+ outputs=gr.Label(label="Predicci贸n"),
32
+ title="Predicci贸n QuickDraw",
33
+ description="Dibuja o sube una imagen para clasificarla."
34
+ )
35
+
36
+ iface.launch()