Spaces:
Runtime error
Runtime error
David-Chew-HL
commited on
Commit
•
7fd213f
1
Parent(s):
1799b77
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image, ImageFilter
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
pipe = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")
|
7 |
+
|
8 |
+
def blur_img(img, blur):
|
9 |
+
depth = pipe(img)["depth"]
|
10 |
+
depth_array = np.array(depth) / 255.0
|
11 |
+
blurred_image_pil = img.filter(ImageFilter.GaussianBlur(blur))
|
12 |
+
blurred_image_array = np.array(blurred_image_pil)
|
13 |
+
mask_array = np.expand_dims(depth_array, axis=-1)
|
14 |
+
result_array = np.uint8(np.array(img) * mask_array + blurred_image_array * (1 - mask_array))
|
15 |
+
result_pil = Image.fromarray(result_array)
|
16 |
+
return result_pil
|
17 |
+
|
18 |
+
#interface
|
19 |
+
inputs = [
|
20 |
+
gr.inputs.Image(type="pil", label="Input Image"),
|
21 |
+
gr.inputs.Slider(minimum=0, maximum=10, default=5, label="Blur Amount", step=1)
|
22 |
+
]
|
23 |
+
|
24 |
+
output = gr.outputs.Image(type="pil", label="Blurred Image")
|
25 |
+
|
26 |
+
gr.Interface(fn=blur_img, inputs=inputs, outputs=output, title="Depth-Based Image Blurring",
|
27 |
+
description="Upload an image and adjust the blur amount using the slider.").launch()
|