Update app.py
Browse files
app.py
CHANGED
@@ -25,17 +25,19 @@ def extract_object(image):
|
|
25 |
pred = preds[0].squeeze()
|
26 |
pred_pil = transforms.ToPILImage()(pred)
|
27 |
mask = pred_pil.resize(image.size)
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
|
32 |
iface = gr.Interface(
|
33 |
fn=extract_object,
|
34 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
35 |
-
outputs=gr.Image(type="pil", label="
|
36 |
title="BiRefNet Background Removal",
|
37 |
-
description="Upload an image and get the foreground object extracted."
|
38 |
)
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
-
iface.launch()
|
|
|
25 |
pred = preds[0].squeeze()
|
26 |
pred_pil = transforms.ToPILImage()(pred)
|
27 |
mask = pred_pil.resize(image.size)
|
28 |
+
|
29 |
+
# Create a new transparent image
|
30 |
+
result = Image.new("RGBA", image.size, (0, 0, 0, 0))
|
31 |
+
result.paste(image, mask=mask)
|
32 |
+
return result
|
33 |
|
34 |
iface = gr.Interface(
|
35 |
fn=extract_object,
|
36 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
37 |
+
outputs=gr.Image(type="pil", label="Object with Transparent Background"),
|
38 |
title="BiRefNet Background Removal",
|
39 |
+
description="Upload an image and get the foreground object extracted onto a transparent background."
|
40 |
)
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
+
iface.launch()
|