Spaces:
Runtime error
Runtime error
File size: 1,706 Bytes
8331e09 2577c4e 537640d 2577c4e 002803a 2577c4e 5d85645 537640d 5d85645 537640d 2577c4e 537640d 2577c4e 537640d 5d85645 537640d 5d85645 537640d 5d85645 537640d 2577c4e 537640d 5d85645 537640d 2577c4e 537640d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from huggingface_hub import hf_hub_download
config_path=hf_hub_download(repo_id="ibm-nasa-geospatial/Prithvi-100M-sen1floods11", filename="sen1floods11_Prithvi_100M.py", token=os.environ.get("token"))
ckpt=hf_hub_download(repo_id="ibm-nasa-geospatial/Prithvi-100M-sen1floods11", filename='sen1floods11_Prithvi_100M.pth', token=os.environ.get("token"))
import numpy as np
import gradio as gr
from PIL import Image
import rasterio
def cargar_imagen_tif(tifile):
try:
with rasterio.open(tifile, "r") as src:
data = src.read()
tuki = Image.fromarray(data[0]) # Convierte el arreglo raster a una imagen PIL
return convertir_a_blanco_y_negro(tuki) # Captura el valor de retorno de la función
except Exception as e:
return f"Error al cargar la imagen TIFF: {str(e)}"
def convertir_a_blanco_y_negro(input_img):
try:
img_array = np.array(input_img)
binary_img = np.zeros_like(img_array)
color_threshold = 50
for i in range(img_array.shape[0]):
for j in range(img_array.shape[1]):
pixel_color = img_array[i, j]
if np.all(pixel_color <= color_threshold):
binary_img[i, j] = 0
else:
binary_img[i, j] = 255
binary_img = Image.fromarray(np.uint8(binary_img))
return binary_img, "Hecho"
except Exception as e:
return f"Error al convertir a blanco y negro: {str(e)}"
demo = gr.Interface(
fn=cargar_imagen_tif,
inputs="file",
outputs=["image", "text"],
title="Conversión a Blanco y Negro",
description="Carga una imagen TIFF y conviértela a blanco y negro."
)
demo.launch() |