Spaces:
Runtime error
Runtime error
Commit
·
5658f28
1
Parent(s):
43778d7
Create core.py
Browse files
core.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rembg import remove
|
| 2 |
+
from PIL import Image, ImageOps
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def image_mod(image):
|
| 7 |
+
|
| 8 |
+
output = remove(image)
|
| 9 |
+
image = output.convert("RGBA")
|
| 10 |
+
new_image = Image.new("RGBA", image.size, "MAGENTA")
|
| 11 |
+
new_image.paste(image, mask=image)
|
| 12 |
+
# Add a black border of 10 pixels on all sides
|
| 13 |
+
new_image = ImageOps.expand(new_image, border=5, fill='black')
|
| 14 |
+
|
| 15 |
+
# Get the image size
|
| 16 |
+
width, height = new_image.size
|
| 17 |
+
|
| 18 |
+
# Calculate the number of photos per row
|
| 19 |
+
num_per_row = int(width / 4)
|
| 20 |
+
|
| 21 |
+
# Create a new image to hold the photos
|
| 22 |
+
output_image = Image.new("RGB", (width * 4, height * 2))
|
| 23 |
+
|
| 24 |
+
# Paste the source image into the new image
|
| 25 |
+
for row in range(2):
|
| 26 |
+
for col in range(4):
|
| 27 |
+
output_image.paste(new_image, (col * width, row * height))
|
| 28 |
+
# Save the output image
|
| 29 |
+
return output_image
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
demo = gr.Interface(
|
| 33 |
+
image_mod,
|
| 34 |
+
gr.Image(type="pil"),
|
| 35 |
+
"image",
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|
| 40 |
+
|
| 41 |
+
|