tonyassi commited on
Commit
a1deaea
1 Parent(s): 3ceed42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -6,7 +6,14 @@ from PIL import Image, ImageOps
6
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
7
  pipeline = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True).to("cuda")
8
 
 
 
 
 
 
9
 
 
 
10
  def divisible_by_8(image):
11
  width, height = image.size
12
 
@@ -24,8 +31,10 @@ def generate(image_editor, prompt, neg_prompt, strength, guidance):
24
  image = image_editor['background'].convert('RGB')
25
  image.thumbnail((1024, 1024))
26
  image = divisible_by_8(image)
 
27
 
28
  layer = image_editor["layers"][0].resize(image.size)
 
29
 
30
  mask = Image.new("RGBA", image.size, "WHITE")
31
  mask.paste(layer, (0, 0), layer)
 
6
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
7
  pipeline = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True).to("cuda")
8
 
9
+ def squarify_image(img):
10
+ if(img.height > img.width): bg_size = img.height
11
+ else: bg_size = img.width
12
+ bg = Image.new(mode="RGB", size=(bg_size,bg_size), color="white")
13
+ bg.paste(img, ( int((bg.width - bg.width)/2), 0) )
14
 
15
+ return bg
16
+
17
  def divisible_by_8(image):
18
  width, height = image.size
19
 
 
31
  image = image_editor['background'].convert('RGB')
32
  image.thumbnail((1024, 1024))
33
  image = divisible_by_8(image)
34
+ image = squarify_image(image)
35
 
36
  layer = image_editor["layers"][0].resize(image.size)
37
+ layer = squarify_image(layer)
38
 
39
  mask = Image.new("RGBA", image.size, "WHITE")
40
  mask.paste(layer, (0, 0), layer)