Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,14 +6,31 @@ 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 |
def generate(image_editor, prompt, neg_prompt, strength, guidance):
|
| 10 |
image = image_editor['background'].convert('RGB')
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
mask = ImageOps.invert(mask.convert('L'))
|
| 14 |
|
| 15 |
-
image.thumbnail((1024, 1024))
|
| 16 |
-
mask.thumbnail((1024, 1024))
|
| 17 |
|
| 18 |
final_image = pipeline(prompt=prompt,
|
| 19 |
image=image,
|
|
|
|
| 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 |
+
|
| 13 |
+
# Calculate the new width and height that are divisible by 8
|
| 14 |
+
new_width = (width // 8) * 8
|
| 15 |
+
new_height = (height // 8) * 8
|
| 16 |
+
|
| 17 |
+
# Resize the image
|
| 18 |
+
resized_image = image.resize((new_width, new_height))
|
| 19 |
+
|
| 20 |
+
return resized_image
|
| 21 |
+
|
| 22 |
+
|
| 23 |
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)
|
| 32 |
mask = ImageOps.invert(mask.convert('L'))
|
| 33 |
|
|
|
|
|
|
|
| 34 |
|
| 35 |
final_image = pipeline(prompt=prompt,
|
| 36 |
image=image,
|