Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
from
|
4 |
-
import
|
5 |
|
6 |
def cargar_imagen_tif(tifile):
|
7 |
try:
|
8 |
-
with
|
9 |
-
data =
|
10 |
-
tuki =
|
11 |
return convertir_a_blanco_y_negro(tuki) # Captura el valor de retorno de la función
|
12 |
except Exception as e:
|
13 |
return f"Error al cargar la imagen TIFF: {str(e)}"
|
14 |
|
15 |
def convertir_a_blanco_y_negro(input_img):
|
16 |
try:
|
17 |
-
img_array =
|
18 |
|
19 |
-
binary_img =
|
20 |
|
21 |
color_threshold = 50
|
22 |
|
@@ -28,13 +28,13 @@ def convertir_a_blanco_y_negro(input_img):
|
|
28 |
else:
|
29 |
binary_img[i, j] = 255
|
30 |
|
31 |
-
binary_img =
|
32 |
|
33 |
return binary_img, "Hecho"
|
34 |
except Exception as e:
|
35 |
return f"Error al convertir a blanco y negro: {str(e)}"
|
36 |
|
37 |
-
demo =
|
38 |
fn=cargar_imagen_tif,
|
39 |
inputs="file",
|
40 |
outputs=["image", "text"],
|
|
|
1 |
+
import huggingface.transformers as transformers
|
2 |
+
from huggingface.images import HfImage
|
3 |
+
from huggingface.utils import HfArray
|
4 |
+
from huggingface.raster import HfRaster
|
5 |
|
6 |
def cargar_imagen_tif(tifile):
|
7 |
try:
|
8 |
+
with HfRaster(tifile, "r") as src:
|
9 |
+
data = src.read()
|
10 |
+
tuki = HfImage.fromarray(data[0]) # Convierte el arreglo raster a una imagen HfImage
|
11 |
return convertir_a_blanco_y_negro(tuki) # Captura el valor de retorno de la función
|
12 |
except Exception as e:
|
13 |
return f"Error al cargar la imagen TIFF: {str(e)}"
|
14 |
|
15 |
def convertir_a_blanco_y_negro(input_img):
|
16 |
try:
|
17 |
+
img_array = HfArray(input_img)
|
18 |
|
19 |
+
binary_img = HfArray.zeros_like(img_array)
|
20 |
|
21 |
color_threshold = 50
|
22 |
|
|
|
28 |
else:
|
29 |
binary_img[i, j] = 255
|
30 |
|
31 |
+
binary_img = HfImage.fromarray(np.uint8(binary_img))
|
32 |
|
33 |
return binary_img, "Hecho"
|
34 |
except Exception as e:
|
35 |
return f"Error al convertir a blanco y negro: {str(e)}"
|
36 |
|
37 |
+
demo = transformers. Interface(
|
38 |
fn=cargar_imagen_tif,
|
39 |
inputs="file",
|
40 |
outputs=["image", "text"],
|