Update handler.py
Browse files- handler.py +14 -12
handler.py
CHANGED
|
@@ -27,19 +27,23 @@ class EndpointHandler():
|
|
| 27 |
|
| 28 |
# load StableDiffusionInpaintPipeline pipeline
|
| 29 |
self.pipe = AutoPipelineForInpainting.from_pretrained(
|
| 30 |
-
"
|
| 31 |
-
revision="fp16",
|
| 32 |
torch_dtype=torch.float16,
|
| 33 |
)
|
| 34 |
# use DPMSolverMultistepScheduler
|
| 35 |
-
self.pipe.scheduler = DPMSolverMultistepScheduler.from_config(self.pipe.scheduler.config)
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
self.pipe = self.pipe.to(device)
|
| 38 |
|
| 39 |
-
self.pipe2 = AutoPipelineForInpainting.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 40 |
-
self.pipe2.to("cuda")
|
| 41 |
|
| 42 |
-
self.pipe3 = AutoPipelineForImage2Image.from_pipe(self.pipe2)
|
| 43 |
|
| 44 |
|
| 45 |
|
|
@@ -92,8 +96,6 @@ class EndpointHandler():
|
|
| 92 |
"""
|
| 93 |
|
| 94 |
#pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16").to("cuda")
|
| 95 |
-
|
| 96 |
-
self.pipe.enable_xformers_memory_efficient_attention()
|
| 97 |
|
| 98 |
# run inference pipeline
|
| 99 |
out = self.pipe(prompt=prompt, negative_prompt=negative_prompt, image=image, mask_image=mask_image)
|
|
@@ -103,7 +105,7 @@ class EndpointHandler():
|
|
| 103 |
image = out.images[0].resize((1024, 1024))
|
| 104 |
|
| 105 |
print("image resizing successful!")
|
| 106 |
-
|
| 107 |
self.pipe2.enable_xformers_memory_efficient_attention()
|
| 108 |
|
| 109 |
image = self.pipe2(
|
|
@@ -130,10 +132,10 @@ class EndpointHandler():
|
|
| 130 |
).images[0]
|
| 131 |
|
| 132 |
print("3rd pipeline part successful!")
|
| 133 |
-
|
| 134 |
|
| 135 |
# return first generate PIL image
|
| 136 |
-
return
|
| 137 |
|
| 138 |
# helper to decode input image
|
| 139 |
def decode_base64_image(self, image_string):
|
|
|
|
| 27 |
|
| 28 |
# load StableDiffusionInpaintPipeline pipeline
|
| 29 |
self.pipe = AutoPipelineForInpainting.from_pretrained(
|
| 30 |
+
"kandinsky-community/kandinsky-2-2-decoder-inpaint",
|
|
|
|
| 31 |
torch_dtype=torch.float16,
|
| 32 |
)
|
| 33 |
# use DPMSolverMultistepScheduler
|
| 34 |
+
# self.pipe.scheduler = DPMSolverMultistepScheduler.from_config(self.pipe.scheduler.config)
|
| 35 |
+
|
| 36 |
+
self.pipe.enable_model_cpu_offload()
|
| 37 |
+
|
| 38 |
+
self.pipe.enable_xformers_memory_efficient_attention()
|
| 39 |
+
|
| 40 |
+
# move to device
|
| 41 |
self.pipe = self.pipe.to(device)
|
| 42 |
|
| 43 |
+
# self.pipe2 = AutoPipelineForInpainting.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 44 |
+
# self.pipe2.to("cuda")
|
| 45 |
|
| 46 |
+
# self.pipe3 = AutoPipelineForImage2Image.from_pipe(self.pipe2)
|
| 47 |
|
| 48 |
|
| 49 |
|
|
|
|
| 96 |
"""
|
| 97 |
|
| 98 |
#pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16").to("cuda")
|
|
|
|
|
|
|
| 99 |
|
| 100 |
# run inference pipeline
|
| 101 |
out = self.pipe(prompt=prompt, negative_prompt=negative_prompt, image=image, mask_image=mask_image)
|
|
|
|
| 105 |
image = out.images[0].resize((1024, 1024))
|
| 106 |
|
| 107 |
print("image resizing successful!")
|
| 108 |
+
"""
|
| 109 |
self.pipe2.enable_xformers_memory_efficient_attention()
|
| 110 |
|
| 111 |
image = self.pipe2(
|
|
|
|
| 132 |
).images[0]
|
| 133 |
|
| 134 |
print("3rd pipeline part successful!")
|
| 135 |
+
"""
|
| 136 |
|
| 137 |
# return first generate PIL image
|
| 138 |
+
return image
|
| 139 |
|
| 140 |
# helper to decode input image
|
| 141 |
def decode_base64_image(self, image_string):
|