Update handler.py
Browse files- handler.py +13 -12
handler.py
CHANGED
@@ -27,11 +27,12 @@ class EndpointHandler():
|
|
27 |
|
28 |
# load StableDiffusionInpaintPipeline pipeline
|
29 |
self.pipe = AutoPipelineForInpainting.from_pretrained(
|
30 |
-
"
|
|
|
31 |
torch_dtype=torch.float16,
|
32 |
)
|
33 |
# use DPMSolverMultistepScheduler
|
34 |
-
|
35 |
|
36 |
self.pipe.enable_model_cpu_offload()
|
37 |
|
@@ -40,10 +41,15 @@ class EndpointHandler():
|
|
40 |
# move to device
|
41 |
self.pipe = self.pipe.to(device)
|
42 |
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
-
|
|
|
|
|
47 |
|
48 |
|
49 |
|
@@ -98,15 +104,13 @@ class EndpointHandler():
|
|
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
|
102 |
|
103 |
print("1st pipeline part successful!")
|
104 |
|
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(
|
112 |
prompt=prompt,
|
@@ -121,8 +125,6 @@ class EndpointHandler():
|
|
121 |
|
122 |
print("2nd pipeline part successful!")
|
123 |
|
124 |
-
self.pipe3.enable_xformers_memory_efficient_attention()
|
125 |
-
|
126 |
image2 = self.pipe3(
|
127 |
prompt=prompt,
|
128 |
image=image,
|
@@ -132,10 +134,9 @@ class EndpointHandler():
|
|
132 |
).images[0]
|
133 |
|
134 |
print("3rd pipeline part successful!")
|
135 |
-
"""
|
136 |
|
137 |
# return first generate PIL image
|
138 |
-
return
|
139 |
|
140 |
# helper to decode input image
|
141 |
def decode_base64_image(self, image_string):
|
|
|
27 |
|
28 |
# load StableDiffusionInpaintPipeline pipeline
|
29 |
self.pipe = AutoPipelineForInpainting.from_pretrained(
|
30 |
+
"runwayml/stable-diffusion-inpainting",
|
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.enable_model_cpu_offload()
|
38 |
|
|
|
41 |
# move to device
|
42 |
self.pipe = self.pipe.to(device)
|
43 |
|
44 |
+
self.pipe2 = AutoPipelineForInpainting.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
45 |
+
self.pipe2.enable_model_cpu_offload()
|
46 |
+
self.pipe2.enable_xformers_memory_efficient_attention()
|
47 |
+
|
48 |
+
self.pipe2.to("cuda")
|
49 |
|
50 |
+
self.pipe3 = AutoPipelineForImage2Image.from_pipe(self.pipe2)
|
51 |
+
self.pipe3.enable_model_cpu_offload()
|
52 |
+
self.pipe3.enable_xformers_memory_efficient_attention()
|
53 |
|
54 |
|
55 |
|
|
|
104 |
#pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16").to("cuda")
|
105 |
|
106 |
# run inference pipeline
|
107 |
+
out = self.pipe(prompt=prompt, negative_prompt=negative_prompt, image=image, mask_image=mask_image)
|
108 |
|
109 |
print("1st pipeline part successful!")
|
110 |
|
111 |
image = out.images[0].resize((1024, 1024))
|
112 |
|
113 |
print("image resizing successful!")
|
|
|
|
|
114 |
|
115 |
image = self.pipe2(
|
116 |
prompt=prompt,
|
|
|
125 |
|
126 |
print("2nd pipeline part successful!")
|
127 |
|
|
|
|
|
128 |
image2 = self.pipe3(
|
129 |
prompt=prompt,
|
130 |
image=image,
|
|
|
134 |
).images[0]
|
135 |
|
136 |
print("3rd pipeline part successful!")
|
|
|
137 |
|
138 |
# return first generate PIL image
|
139 |
+
return image2
|
140 |
|
141 |
# helper to decode input image
|
142 |
def decode_base64_image(self, image_string):
|