Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,14 +12,16 @@ def preprocesar_imagen(image):
|
|
| 12 |
image = Image.fromarray(image)
|
| 13 |
if image.mode in ('RGBA', 'LA'):
|
| 14 |
image = image.convert('RGB')
|
| 15 |
-
image = image.convert('L')
|
| 16 |
image = image.resize((28, 28), Image.NEAREST)
|
| 17 |
arr = np.array(image) / 255.0
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
arr_bin_4d = arr_bin.reshape(1, 28, 28, 1)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
return arr_bin_4d, img_para_mostrar
|
| 23 |
|
| 24 |
def predict(image):
|
| 25 |
try:
|
|
|
|
| 12 |
image = Image.fromarray(image)
|
| 13 |
if image.mode in ('RGBA', 'LA'):
|
| 14 |
image = image.convert('RGB')
|
| 15 |
+
image = image.convert('L') # escala de grises
|
| 16 |
image = image.resize((28, 28), Image.NEAREST)
|
| 17 |
arr = np.array(image) / 255.0
|
| 18 |
+
|
| 19 |
+
# Umbral bajo: todo menor o igual a 0.2 será negro (0), lo demás blanco (1)
|
| 20 |
+
arr_bin = np.where(arr <= 0.2, 0.0, 1.0).astype(np.float32)
|
| 21 |
+
|
| 22 |
arr_bin_4d = arr_bin.reshape(1, 28, 28, 1)
|
| 23 |
+
|
| 24 |
+
return arr_bin_4d, arr_bin
|
|
|
|
| 25 |
|
| 26 |
def predict(image):
|
| 27 |
try:
|