Pastuu commited on
Commit
002803a
1 Parent(s): 5d85645

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,22 +1,22 @@
1
- import numpy as np
2
- import gradio as gr
3
- from PIL import Image
4
- import scipy.misc
5
 
6
  def cargar_imagen_tif(tifile):
7
  try:
8
- with open(tifile, 'rb') as f:
9
- data = scipy.misc.imread(f, mode='L')
10
- tuki = Image.fromarray(data) # Convertir el arreglo raster a una imagen PIL
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 = np.array(input_img)
18
 
19
- binary_img = np.zeros_like(img_array)
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 = Image.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 = gr.Interface(
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"],