Spaces:
Running
Running
T.Masuda
commited on
Commit
·
98333cb
1
Parent(s):
b4dfc05
combine-images
Browse files- .gitattributes +2 -0
- app.py +58 -0
- examples/background.png +3 -0
- examples/foreground.png +3 -0
- requirements.txt +1 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
examples/background.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
examples/foreground.png filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from rembg import remove
|
3 |
+
from PIL import ImageOps, ImageDraw
|
4 |
+
|
5 |
+
def process_image(foreImg, flip, backImg, left, top, width, height, isLoc):
|
6 |
+
if foreImg is None:
|
7 |
+
return None
|
8 |
+
|
9 |
+
if isLoc:
|
10 |
+
if backImg is None:
|
11 |
+
return None
|
12 |
+
rect = ImageDraw.Draw(backImg)
|
13 |
+
imwidth = foreImg.width
|
14 |
+
imheight = foreImg.height
|
15 |
+
if width > 0:
|
16 |
+
imwidth = width
|
17 |
+
if height > 0:
|
18 |
+
imheight = height
|
19 |
+
rect.rectangle([(left, top), (imwidth + left, imheight + top)], outline=(255, 0, 0), width=4)
|
20 |
+
return backImg
|
21 |
+
|
22 |
+
image = remove(foreImg)
|
23 |
+
if flip:
|
24 |
+
image = ImageOps.mirror(image)
|
25 |
+
|
26 |
+
imwidth = image.width
|
27 |
+
imheight = image.height
|
28 |
+
if width > 0:
|
29 |
+
imwidth = width
|
30 |
+
if height > 0:
|
31 |
+
imheight = height
|
32 |
+
image = image.resize((imwidth, imheight))
|
33 |
+
|
34 |
+
if backImg is None:
|
35 |
+
return image
|
36 |
+
|
37 |
+
backImg.paste(image, (left, top), image)
|
38 |
+
return backImg
|
39 |
+
|
40 |
+
gr.Interface(
|
41 |
+
fn=process_image,
|
42 |
+
inputs=[
|
43 |
+
gr.Image(label='foreground', type='pil'),
|
44 |
+
gr.Checkbox(label='flip left and right'),
|
45 |
+
gr.Image(label='background', type='pil'),
|
46 |
+
gr.Slider(maximum=4000, step=1, label='left'),
|
47 |
+
gr.Slider(maximum=4000, step=1, label='top'),
|
48 |
+
gr.Slider(maximum=4000, step=1, label='width'),
|
49 |
+
gr.Slider(maximum=4000, step=1, label='height'),
|
50 |
+
gr.Checkbox(label='check location only'),
|
51 |
+
],
|
52 |
+
title='combine images',
|
53 |
+
description='combine images',
|
54 |
+
outputs='image',
|
55 |
+
allow_flagging='never',
|
56 |
+
examples=[['examples/foreground.png', False, 'examples/background.png', 720, 540, 256, 256, False]],
|
57 |
+
#cache_examples=False
|
58 |
+
).launch()
|
examples/background.png
ADDED
![]() |
Git LFS Details
|
examples/foreground.png
ADDED
![]() |
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
rembg
|