Spaces:
Running
Running
Commit
·
5f5d761
1
Parent(s):
cf14e47
Update app.py
Browse files
app.py
CHANGED
@@ -3,35 +3,39 @@ from PIL import Image, ImageOps
|
|
3 |
import gradio as gr
|
4 |
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
demo = gr.Interface(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
)
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
|
6 |
+
def change_color(passport='Passport Photo', color = 'Background Color'):
|
7 |
+
image = remove(passport)
|
8 |
+
new_image = Image.new("RGB", image.size, color)
|
9 |
+
new_image.paste(image, mask=image)
|
10 |
+
# Add a black border of 10 pixels on all sides
|
11 |
+
new_image = ImageOps.expand(new_image, border=5, fill='black')
|
12 |
+
new_image = ImageOps.expand(new_image, border=1, fill='white')
|
13 |
+
|
14 |
+
# Get the image size
|
15 |
+
width, height = new_image.size
|
16 |
+
|
17 |
+
# Create a new image to hold the photos
|
18 |
+
output_image = Image.new("RGB", (width * 4, height * 2))
|
19 |
+
|
20 |
+
# Paste the source image into the new image
|
21 |
+
for row in range(2):
|
22 |
+
for col in range(4):
|
23 |
+
output_image.paste(new_image, (col * width, row * height))
|
24 |
+
# Save the output image
|
25 |
+
return output_image
|
26 |
+
|
27 |
+
|
28 |
+
inputs = [
|
29 |
+
gr.Image(label="Passport Photo", type="pil", image_mode="RGBA"),
|
30 |
+
gr.ColorPicker(label="Background Color",),
|
31 |
+
]
|
32 |
+
outputs = gr.Image(label="Download Image")
|
33 |
|
34 |
demo = gr.Interface(
|
35 |
+
fn=change_color,
|
36 |
+
inputs=inputs,
|
37 |
+
outputs=outputs,
|
38 |
)
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
+
demo.launch()
|
|
|
|