Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -116,20 +116,37 @@ def apply_mask(img: Image.Image, mask_img: Image.Image, defringe: bool = True) -
|
|
| 116 |
result.paste(img, (0, 0), mask_img)
|
| 117 |
return result
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
def generate_background(prompt: str, width: int, height: int) -> Image.Image:
|
| 120 |
"""배경 이미지 생성 함수"""
|
| 121 |
try:
|
|
|
|
|
|
|
|
|
|
| 122 |
with timer("Background generation"):
|
| 123 |
image = pipe(
|
| 124 |
prompt=prompt,
|
| 125 |
-
width=
|
| 126 |
-
height=
|
| 127 |
num_inference_steps=8,
|
| 128 |
guidance_scale=4.0,
|
| 129 |
).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
return image
|
| 131 |
except Exception as e:
|
| 132 |
raise gr.Error(f"Background generation failed: {str(e)}")
|
|
|
|
|
|
|
| 133 |
|
| 134 |
def combine_with_background(foreground: Image.Image, background: Image.Image) -> Image.Image:
|
| 135 |
"""전경과 배경 합성 함수"""
|
|
|
|
| 116 |
result.paste(img, (0, 0), mask_img)
|
| 117 |
return result
|
| 118 |
|
| 119 |
+
|
| 120 |
+
def adjust_size_to_multiple_of_8(width: int, height: int) -> tuple[int, int]:
|
| 121 |
+
"""이미지 크기를 8의 배수로 조정하는 함수"""
|
| 122 |
+
new_width = ((width + 7) // 8) * 8
|
| 123 |
+
new_height = ((height + 7) // 8) * 8
|
| 124 |
+
return new_width, new_height
|
| 125 |
+
|
| 126 |
def generate_background(prompt: str, width: int, height: int) -> Image.Image:
|
| 127 |
"""배경 이미지 생성 함수"""
|
| 128 |
try:
|
| 129 |
+
# 이미지 크기를 8의 배수로 조정
|
| 130 |
+
adjusted_width, adjusted_height = adjust_size_to_multiple_of_8(width, height)
|
| 131 |
+
|
| 132 |
with timer("Background generation"):
|
| 133 |
image = pipe(
|
| 134 |
prompt=prompt,
|
| 135 |
+
width=adjusted_width,
|
| 136 |
+
height=adjusted_height,
|
| 137 |
num_inference_steps=8,
|
| 138 |
guidance_scale=4.0,
|
| 139 |
).images[0]
|
| 140 |
+
|
| 141 |
+
# 원본 크기로 리사이즈
|
| 142 |
+
if adjusted_width != width or adjusted_height != height:
|
| 143 |
+
image = image.resize((width, height), Image.Resampling.LANCZOS)
|
| 144 |
+
|
| 145 |
return image
|
| 146 |
except Exception as e:
|
| 147 |
raise gr.Error(f"Background generation failed: {str(e)}")
|
| 148 |
+
|
| 149 |
+
|
| 150 |
|
| 151 |
def combine_with_background(foreground: Image.Image, background: Image.Image) -> Image.Image:
|
| 152 |
"""전경과 배경 합성 함수"""
|