Mikeztrada commited on
Commit
020d3b5
verified
1 Parent(s): 1d1e403

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -13,23 +13,23 @@ def preprocesar_imagen(image):
13
  image = Image.fromarray(image)
14
  if image.mode in ('RGBA', 'LA'):
15
  image = image.convert('RGB')
16
- image = image.convert('L')
17
  image = ImageOps.invert(image)
18
  image = image.resize((28, 28), Image.NEAREST)
19
  arr = np.array(image) / 255.0
20
- return arr, image # Regresamos el array (para el modelo) y el PIL (para mostrar)
 
21
 
22
  def predict(image):
23
  try:
24
  arr, img_procesada_pil = preprocesar_imagen(image)
25
- entrada = arr.reshape(1, 784)
26
- preds = model.predict(entrada)
27
  class_idx = np.argmax(preds)
28
- # Devolvemos: predicci贸n, imagen preprocesada (como PIL)
29
  return {etiquetas[class_idx]: float(preds[0][class_idx])}, img_procesada_pil
30
  except Exception as e:
31
  return f"Error: {str(e)}", None
32
 
 
33
  iface = gr.Interface(
34
  fn=predict,
35
  inputs=gr.Image(label="Dibuja o sube una imagen (fondo blanco, trazo negro)"),
 
13
  image = Image.fromarray(image)
14
  if image.mode in ('RGBA', 'LA'):
15
  image = image.convert('RGB')
16
+ image = image.convert('L') # blanco y negro
17
  image = ImageOps.invert(image)
18
  image = image.resize((28, 28), Image.NEAREST)
19
  arr = np.array(image) / 255.0
20
+ arr = arr.reshape(1, 28, 28, 1) # Para CNN
21
+ return arr, image # Regresa el array (input modelo) y el PIL (para mostrar)
22
 
23
  def predict(image):
24
  try:
25
  arr, img_procesada_pil = preprocesar_imagen(image)
26
+ preds = model.predict(arr)
 
27
  class_idx = np.argmax(preds)
 
28
  return {etiquetas[class_idx]: float(preds[0][class_idx])}, img_procesada_pil
29
  except Exception as e:
30
  return f"Error: {str(e)}", None
31
 
32
+
33
  iface = gr.Interface(
34
  fn=predict,
35
  inputs=gr.Image(label="Dibuja o sube una imagen (fondo blanco, trazo negro)"),