Spaces:
Runtime error
Runtime error
from PIL import Image | |
import numpy as np | |
import io | |
from huggingface_hub import hf_shiny as hf | |
# Define function to process uploaded image | |
def process_image(image): | |
# Convert image to numpy array | |
img_array = np.array(image) | |
patch_size = 128 | |
step = 128 | |
all_img_patches = [] | |
for i in range(0, img_array.shape[0] - patch_size + 1, step): | |
for j in range(0, img_array.shape[1] - patch_size + 1, step): | |
single_patch_img = img_array[i:i + patch_size, j:j + patch_size] | |
all_img_patches.append(single_patch_img) | |
images = np.array(all_img_patches) | |
# This is just a example to process the image | |
processed_images = [] | |
for img in images: | |
processed_image = np.mean(img, axis=-1) # Example: Convert to grayscale | |
processed_images.append(processed_image) | |
processed_images = np.array(processed_images) | |
return processed_images | |
# Define Shiny app | |
app = hf.start() | |
def main(uploaded_image): | |
# Convert uploaded image to PIL Image | |
image = Image.open(io.BytesIO(uploaded_image.read())) | |
# Display uploaded image | |
app.image(image, caption="Uploaded Image") | |
# Process uploaded image | |
with app.spinner("Processing..."): | |
segmentation_result = process_image(image) | |
# Display segmentation result | |
app.image(segmentation_result, caption="Sidewalk Segmentation Result") | |
if __name__ == "__main__": | |
app.run() | |