Spaces:
Runtime error
Runtime error
File size: 1,259 Bytes
7fd213f 39fcd90 7fd213f 887c501 9e86d00 7fd213f a3e99fa 7fd213f 1946fad 0357d68 697773a 1946fad |
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 |
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.",
)
app.launch(share=True) |