Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ 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):
|
10 |
image = image_editor['background'].convert('RGB')
|
11 |
mask = Image.new("RGBA", image_editor["layers"][0].size, "WHITE")
|
12 |
mask.paste(image_editor["layers"][0], (0, 0), image_editor["layers"][0])
|
@@ -15,7 +15,9 @@ def generate(image_editor):
|
|
15 |
image.thumbnail((1024, 1024))
|
16 |
mask.thumbnail((1024, 1024))
|
17 |
|
18 |
-
|
|
|
|
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
gr.Markdown("""
|
@@ -26,6 +28,7 @@ with gr.Blocks() as demo:
|
|
26 |
with gr.Row():
|
27 |
with gr.Column():
|
28 |
sketch_pad = gr.ImageMask(type='pil', label='Inpaint')
|
|
|
29 |
generate_button = gr.Button("Generate")
|
30 |
with gr.Column():
|
31 |
version_gallery = gr.Gallery(label="Versions")
|
@@ -41,6 +44,6 @@ with gr.Blocks() as demo:
|
|
41 |
out2 = gr.Image()
|
42 |
out3 = gr.Image()
|
43 |
|
44 |
-
generate_button.click(fn=generate, inputs=sketch_pad, outputs=[sketch_pad, out1, out2])
|
45 |
|
46 |
demo.launch()
|
|
|
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):
|
10 |
image = image_editor['background'].convert('RGB')
|
11 |
mask = Image.new("RGBA", image_editor["layers"][0].size, "WHITE")
|
12 |
mask.paste(image_editor["layers"][0], (0, 0), image_editor["layers"][0])
|
|
|
15 |
image.thumbnail((1024, 1024))
|
16 |
mask.thumbnail((1024, 1024))
|
17 |
|
18 |
+
final_image = pipeline(prompt=prompt, image=image, mask_image=mask).images[0]
|
19 |
+
|
20 |
+
return image_editor, image, mask, final_image
|
21 |
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("""
|
|
|
28 |
with gr.Row():
|
29 |
with gr.Column():
|
30 |
sketch_pad = gr.ImageMask(type='pil', label='Inpaint')
|
31 |
+
prompt = gr.Textbox()
|
32 |
generate_button = gr.Button("Generate")
|
33 |
with gr.Column():
|
34 |
version_gallery = gr.Gallery(label="Versions")
|
|
|
44 |
out2 = gr.Image()
|
45 |
out3 = gr.Image()
|
46 |
|
47 |
+
generate_button.click(fn=generate, inputs=[sketch_pad,prompt], outputs=[sketch_pad, out1, out2, out3])
|
48 |
|
49 |
demo.launch()
|