dgoot commited on
Commit
aac78db
1 Parent(s): a7a042b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -5,12 +5,13 @@ import spaces
5
  import torch
6
  from diffusers import AutoPipelineForInpainting
7
  from loguru import logger
8
- from PIL import Image
9
 
10
  SUPPORTED_MODELS = [
11
  "stabilityai/sdxl-turbo",
12
  "stabilityai/stable-diffusion-3-medium-diffusers",
13
  "stabilityai/stable-diffusion-xl-base-1.0",
 
14
  "timbrooks/instruct-pix2pix",
15
  ]
16
  DEFAULT_MODEL = "stabilityai/stable-diffusion-xl-base-1.0"
@@ -27,7 +28,7 @@ def load_pipeline(model):
27
 
28
 
29
  logger.debug(f"Loading pipeline: {dict(model=model)}")
30
- pipe = load_pipeline(model).to("cuda")
31
 
32
 
33
  @logger.catch(reraise=True)
@@ -46,10 +47,14 @@ def infer(
46
  )
47
 
48
  init_image: Image.Image = image_editor["background"].convert("RGB")
49
- mask_image: Image.Image = image_editor["layers"][0].convert("RGB")
50
 
51
  # Downscale the image
52
  init_image.thumbnail((1024, 1024))
 
 
 
 
 
53
  mask_image.thumbnail((1024, 1024))
54
 
55
  additional_args = {
 
5
  import torch
6
  from diffusers import AutoPipelineForInpainting
7
  from loguru import logger
8
+ from PIL import Image, ImageChops
9
 
10
  SUPPORTED_MODELS = [
11
  "stabilityai/sdxl-turbo",
12
  "stabilityai/stable-diffusion-3-medium-diffusers",
13
  "stabilityai/stable-diffusion-xl-base-1.0",
14
+ "stable-diffusion-v1-5/stable-diffusion-v1-5",
15
  "timbrooks/instruct-pix2pix",
16
  ]
17
  DEFAULT_MODEL = "stabilityai/stable-diffusion-xl-base-1.0"
 
28
 
29
 
30
  logger.debug(f"Loading pipeline: {dict(model=model)}")
31
+ pipe = load_pipeline(model).to("cuda" if torch.cuda.is_available() else "mps")
32
 
33
 
34
  @logger.catch(reraise=True)
 
47
  )
48
 
49
  init_image: Image.Image = image_editor["background"].convert("RGB")
 
50
 
51
  # Downscale the image
52
  init_image.thumbnail((1024, 1024))
53
+
54
+ mask_layer = image_editor["layers"][0]
55
+ mask_image = Image.new("RGBA", mask_layer.size, "white")
56
+ mask_image = Image.alpha_composite(mask_image, mask_layer).convert("RGB")
57
+ mask_image = ImageChops.invert(mask_image)
58
  mask_image.thumbnail((1024, 1024))
59
 
60
  additional_args = {