Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
from PIL import Image, ImageFilter | |
import numpy as np | |
pipe = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf") | |
def blur_img(img, blur): | |
depth = pipe(img)["depth"] | |
depth_array = np.array(depth) / 255.0 | |
blurred_image_pil = img.filter(ImageFilter.BoxBlur(blur)) | |
blurred_image_array = np.array(blurred_image_pil) | |
mask_array = np.expand_dims(depth_array, axis=-1) | |
result_array = np.uint8(np.array(img) * mask_array + blurred_image_array * (1 - mask_array)) | |
result_pil = Image.fromarray(result_array) | |
return result_pil | |
#interface | |
inputs = [ | |
gr.Image(type="pil", label="Input Image"), | |
gr.Slider(minimum=1, maximum=10, label="Blur Amount", step=1) | |
] | |
output = gr.Image(type="pil", label="Blurred Image") | |
app= gr.Interface(fn=blur_img, inputs=inputs, outputs=output, title="Depth Anything model based Image Blurring", | |
description="Upload an image and adjust the blur amount using the slider. \nThis project takes in an image, obtains a depth mask using the Depth Anything model by https://huggingface.co/LiheYoung/depth-anything-base-hf, and blurs image based on the depth mask.", | |
gr.Image(file="/Blur-Anything/depth.gif")) | |
app.launch(share=True) |