File size: 977 Bytes
5658f28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
from rembg import remove
from PIL import Image, ImageOps
import gradio as gr


def image_mod(image):

    output = remove(image)
    image = output.convert("RGBA")
    new_image = Image.new("RGBA", image.size, "MAGENTA")
    new_image.paste(image, mask=image)
    # Add a black border of 10 pixels on all sides
    new_image = ImageOps.expand(new_image, border=5, fill='black')

    # Get the image size
    width, height = new_image.size

    # Calculate the number of photos per row
    num_per_row = int(width / 4)

    # Create a new image to hold the photos
    output_image = Image.new("RGB", (width * 4, height * 2))

    # Paste the source image into the new image
    for row in range(2):
        for col in range(4):
            output_image.paste(new_image, (col * width, row * height))
    # Save the output image
    return output_image


demo = gr.Interface(
    image_mod,
    gr.Image(type="pil"),
    "image",
)

if __name__ == "__main__":
    demo.launch()