radames commited on
Commit
46f091b
1 Parent(s): 660e8f8

crop image to square

Browse files
Files changed (1) hide show
  1. app.py +5 -12
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 pad_image(image):
 
70
  w, h = image.size
71
- if w == h:
72
- return image
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 = pad_image(init_image).convert("RGB").resize((512, 512))
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(