Spaces:
Running
Running
adding explanation of usage on the gradio app
Browse files
app.py
CHANGED
@@ -6,7 +6,12 @@ import os
|
|
6 |
from tqdm import tqdm
|
7 |
from PIL import Image
|
8 |
|
9 |
-
def
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
segmenter = Mask2FormerSegmenter()
|
12 |
segmenter.load_models(checkpoint_name = "facebook/mask2former-swin-large-ade-semantic")
|
@@ -24,17 +29,22 @@ def main(image1, image2, refine='False'):
|
|
24 |
return image_a, image_b
|
25 |
|
26 |
|
27 |
-
def
|
|
|
28 |
img1 = Image.fromarray(image1.astype('uint8'), 'RGB')
|
29 |
img2 = Image.fromarray(image2.astype('uint8'), 'RGB')
|
30 |
-
return
|
31 |
|
32 |
|
33 |
iface = gr.Interface(
|
34 |
-
fn=
|
35 |
inputs=["image", "image", gr.inputs.Checkbox(label="Use Refiner on background")],
|
36 |
outputs=["image", "image"],
|
37 |
title="Background Swapper App",
|
38 |
-
description="Upload two images to see their backgrounds swapped.
|
|
|
|
|
|
|
|
|
39 |
)
|
40 |
iface.launch()
|
|
|
6 |
from tqdm import tqdm
|
7 |
from PIL import Image
|
8 |
|
9 |
+
def process_image(image1, image2, refine='False'):
|
10 |
+
""" Process a pair of images to swap their backgrounds.
|
11 |
+
image1: PIL image of the first image.
|
12 |
+
image2: PIL image of the second image.
|
13 |
+
refine: if True, use an additional network in the inpainter to refine the background.\
|
14 |
+
useful in high-resolution images and large inpainting masks. It takes longer to run."""
|
15 |
|
16 |
segmenter = Mask2FormerSegmenter()
|
17 |
segmenter.load_models(checkpoint_name = "facebook/mask2former-swin-large-ade-semantic")
|
|
|
29 |
return image_a, image_b
|
30 |
|
31 |
|
32 |
+
def run_gradio_fn(image1, image2, refine=False):
|
33 |
+
""" Run the background swapper app on a pair of images."""
|
34 |
img1 = Image.fromarray(image1.astype('uint8'), 'RGB')
|
35 |
img2 = Image.fromarray(image2.astype('uint8'), 'RGB')
|
36 |
+
return process_image(img1, img2, refine)
|
37 |
|
38 |
|
39 |
iface = gr.Interface(
|
40 |
+
fn=run_gradio_fn,
|
41 |
inputs=["image", "image", gr.inputs.Checkbox(label="Use Refiner on background")],
|
42 |
outputs=["image", "image"],
|
43 |
title="Background Swapper App",
|
44 |
+
description="Upload two images to see their backgrounds swapped. \
|
45 |
+
The first image will have the background of the second image, and vice versa. \
|
46 |
+
Refiner option: Uses an additional network in the inpainter to refine the background.\
|
47 |
+
Useful in high-resolution images and large inpainting masks. \
|
48 |
+
It takes about 20s longer to run on 1024x1024",
|
49 |
)
|
50 |
iface.launch()
|