Spaces:
Running
on
A10G
Running
on
A10G
crop image to square
Browse files
app.py
CHANGED
@@ -66,23 +66,16 @@ i2i_pipe.to(device=torch_device, dtype=torch_dtype).to(device)
|
|
66 |
i2i_pipe.set_progress_bar_config(disable=True)
|
67 |
|
68 |
|
69 |
-
def
|
|
|
70 |
w, h = image.size
|
71 |
-
|
72 |
-
|
73 |
-
elif w > h:
|
74 |
-
new_image = Image.new(image.mode, (w, w), (0, 0, 0))
|
75 |
-
new_image.paste(image, (0, (w - h) // 2))
|
76 |
-
return new_image
|
77 |
-
else:
|
78 |
-
new_image = Image.new(image.mode, (h, h), (0, 0, 0))
|
79 |
-
new_image.paste(image, ((h - w) // 2, 0))
|
80 |
-
return new_image
|
81 |
|
82 |
|
83 |
async def predict(init_image, prompt, strength, steps, seed=1231231):
|
84 |
if init_image is not None:
|
85 |
-
init_image =
|
86 |
generator = torch.manual_seed(seed)
|
87 |
last_time = time.time()
|
88 |
results = i2i_pipe(
|
|
|
66 |
i2i_pipe.set_progress_bar_config(disable=True)
|
67 |
|
68 |
|
69 |
+
def resize_crop(image, size=512):
|
70 |
+
image = image.convert("RGB")
|
71 |
w, h = image.size
|
72 |
+
image = image.resize((size, int(size * (h / w))), Image.BICUBIC)
|
73 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
|
76 |
async def predict(init_image, prompt, strength, steps, seed=1231231):
|
77 |
if init_image is not None:
|
78 |
+
init_image = resize_crop(init_image)
|
79 |
generator = torch.manual_seed(seed)
|
80 |
last_time = time.time()
|
81 |
results = i2i_pipe(
|