Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,10 +10,13 @@ image_processor = AutoImageProcessor.from_pretrained("depth-anything/Depth-Anyth
|
|
10 |
model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Small-hf")
|
11 |
|
12 |
def apply_gaussian_blur(image, mask):
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
# Ensure mask is grayscale and resized to match image dimensions
|
15 |
-
mask_pil = Image.fromarray(mask
|
16 |
-
mask_pil = mask_pil.resize(image.size)
|
17 |
mask_array = np.array(mask_pil)
|
18 |
|
19 |
# Create a blurred background
|
@@ -97,7 +100,7 @@ interface = gr.Interface(
|
|
97 |
fn=process_image,
|
98 |
inputs=[
|
99 |
gr.Image(type="pil", label="Upload an Image"),
|
100 |
-
gr.
|
101 |
gr.Radio(["Gaussian Blur", "Lens Blur"], label="Choose Blur Effect")
|
102 |
],
|
103 |
outputs=gr.Image(type="pil"),
|
|
|
10 |
model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Small-hf")
|
11 |
|
12 |
def apply_gaussian_blur(image, mask):
|
13 |
+
"""Applies Gaussian blur to the background based on a user-drawn mask."""
|
14 |
+
|
15 |
+
if mask is None:
|
16 |
+
return image # If no mask is provided, return the original image
|
17 |
+
|
18 |
# Ensure mask is grayscale and resized to match image dimensions
|
19 |
+
mask_pil = Image.fromarray(mask).convert("L").resize(image.size)
|
|
|
20 |
mask_array = np.array(mask_pil)
|
21 |
|
22 |
# Create a blurred background
|
|
|
100 |
fn=process_image,
|
101 |
inputs=[
|
102 |
gr.Image(type="pil", label="Upload an Image"),
|
103 |
+
gr.Sketchpad(shape=(256, 256), label="Draw Mask (Only for Gaussian Blur)"),
|
104 |
gr.Radio(["Gaussian Blur", "Lens Blur"], label="Choose Blur Effect")
|
105 |
],
|
106 |
outputs=gr.Image(type="pil"),
|