sth4nth commited on
Commit
edd56c8
·
verified ·
1 Parent(s): d3721db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -6,16 +6,18 @@ import io
6
  def merge_images(foreground, background):
7
  # foreground와 background를 바이트 배열로 변환
8
  foreground_bytes = io.BytesIO()
9
- foreground.save(foreground_bytes, format=foreground.format)
 
10
  background_bytes = io.BytesIO()
11
- background.save(background_bytes, format=background.format)
 
12
 
13
  # 배경 제거
14
- foreground_no_bg_bytes = remove(foreground_bytes.getvalue())
15
 
16
  # 바이트 데이터를 BytesIO 스트림으로 변환하여 PIL 이미지로 로드
17
  foreground_no_bg = Image.open(io.BytesIO(foreground_no_bg_bytes)).convert("RGBA")
18
- background_image = background.convert("RGBA")
19
 
20
  # 배경 이미지 크기 조정
21
  background_image = background_image.resize(foreground_no_bg.size)
@@ -28,8 +30,8 @@ def merge_images(foreground, background):
28
 
29
  with gr.Blocks() as demo:
30
  with gr.Row():
31
- foreground_input = gr.Image(type="pil", label="Upload your main image", tool="editor")
32
- background_input = gr.Image(type="pil", label="Upload your background image", tool="editor")
33
  image_output = gr.Image(type="pil", label="Merged Image")
34
 
35
  btn = gr.Button("Merge Images")
 
6
  def merge_images(foreground, background):
7
  # foreground와 background를 바이트 배열로 변환
8
  foreground_bytes = io.BytesIO()
9
+ foreground.save(foreground_bytes, format="PNG")
10
+ foreground_bytes.seek(0) # 포인터를 처음으로 이동
11
  background_bytes = io.BytesIO()
12
+ background.save(background_bytes, format="PNG")
13
+ background_bytes.seek(0) # 포인터를 처음으로 이동
14
 
15
  # 배경 제거
16
+ foreground_no_bg_bytes = remove(foreground_bytes.read())
17
 
18
  # 바이트 데이터를 BytesIO 스트림으로 변환하여 PIL 이미지로 로드
19
  foreground_no_bg = Image.open(io.BytesIO(foreground_no_bg_bytes)).convert("RGBA")
20
+ background_image = Image.open(background_bytes).convert("RGBA")
21
 
22
  # 배경 이미지 크기 조정
23
  background_image = background_image.resize(foreground_no_bg.size)
 
30
 
31
  with gr.Blocks() as demo:
32
  with gr.Row():
33
+ foreground_input = gr.Image(type="pil", label="Upload your main image")
34
+ background_input = gr.Image(type="pil", label="Upload your background image")
35
  image_output = gr.Image(type="pil", label="Merged Image")
36
 
37
  btn = gr.Button("Merge Images")