fffiloni commited on
Commit
d9a10ae
1 Parent(s): 4686696

Update app_with_diffusers.py

Browse files
Files changed (1) hide show
  1. app_with_diffusers.py +23 -0
app_with_diffusers.py CHANGED
@@ -13,6 +13,29 @@ from schedulers.lcm_single_step_scheduler import LCMSingleStepScheduler
13
  from module.ip_adapter.utils import load_adapter_to_pipe
14
  from pipelines.sdxl_instantir import InstantIRPipeline
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # prepare models under ./models
17
  instantir_path = f'./models'
18
 
 
13
  from module.ip_adapter.utils import load_adapter_to_pipe
14
  from pipelines.sdxl_instantir import InstantIRPipeline
15
 
16
+ def resize_img(input_image, max_side=1280, min_side=1024, size=None,
17
+ pad_to_max_side=False, mode=Image.BILINEAR, base_pixel_number=64):
18
+
19
+ w, h = input_image.size
20
+ if size is not None:
21
+ w_resize_new, h_resize_new = size
22
+ else:
23
+ # ratio = min_side / min(h, w)
24
+ # w, h = round(ratio*w), round(ratio*h)
25
+ ratio = max_side / max(h, w)
26
+ input_image = input_image.resize([round(ratio*w), round(ratio*h)], mode)
27
+ w_resize_new = (round(ratio * w) // base_pixel_number) * base_pixel_number
28
+ h_resize_new = (round(ratio * h) // base_pixel_number) * base_pixel_number
29
+ input_image = input_image.resize([w_resize_new, h_resize_new], mode)
30
+
31
+ if pad_to_max_side:
32
+ res = np.ones([max_side, max_side, 3], dtype=np.uint8) * 255
33
+ offset_x = (max_side - w_resize_new) // 2
34
+ offset_y = (max_side - h_resize_new) // 2
35
+ res[offset_y:offset_y+h_resize_new, offset_x:offset_x+w_resize_new] = np.array(input_image)
36
+ input_image = Image.fromarray(res)
37
+ return input_image
38
+
39
  # prepare models under ./models
40
  instantir_path = f'./models'
41