Update handler.py
Browse files- handler.py +10 -8
handler.py
CHANGED
@@ -24,7 +24,7 @@ class EndpointHandler():
|
|
24 |
# )
|
25 |
# self.smooth_pipe.to("cuda")
|
26 |
|
27 |
-
|
28 |
self.controlnet = ControlNetModel.from_pretrained(
|
29 |
"lllyasviel/control_v11p_sd15_inpaint", torch_dtype=torch.float16
|
30 |
)
|
@@ -36,8 +36,8 @@ class EndpointHandler():
|
|
36 |
self.pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe.scheduler.config)
|
37 |
self.pipe.enable_model_cpu_offload()
|
38 |
self.pipe.enable_xformers_memory_efficient_attention()
|
|
|
39 |
"""
|
40 |
-
|
41 |
# load StableDiffusionInpaintPipeline pipeline
|
42 |
self.pipe = AutoPipelineForInpainting.from_pretrained(
|
43 |
"runwayml/stable-diffusion-inpainting",
|
@@ -45,7 +45,7 @@ class EndpointHandler():
|
|
45 |
torch_dtype=torch.float16,
|
46 |
)
|
47 |
# use DPMSolverMultistepScheduler
|
48 |
-
self.pipe.scheduler =
|
49 |
|
50 |
self.pipe.enable_model_cpu_offload()
|
51 |
|
@@ -63,6 +63,7 @@ class EndpointHandler():
|
|
63 |
self.pipe3 = AutoPipelineForImage2Image.from_pipe(self.pipe2)
|
64 |
#self.pipe3.enable_model_cpu_offload()
|
65 |
self.pipe3.enable_xformers_memory_efficient_attention()
|
|
|
66 |
|
67 |
|
68 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
@@ -114,7 +115,7 @@ class EndpointHandler():
|
|
114 |
"""
|
115 |
|
116 |
#pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16").to("cuda")
|
117 |
-
|
118 |
# run inference pipeline
|
119 |
out = self.pipe(prompt=prompt, negative_prompt=negative_prompt, image=image, mask_image=mask_image, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale)
|
120 |
|
@@ -123,7 +124,7 @@ class EndpointHandler():
|
|
123 |
image = out.images[0].resize((1024, 1024))
|
124 |
|
125 |
print("image resizing successful!")
|
126 |
-
|
127 |
image = self.pipe2(
|
128 |
prompt=prompt,
|
129 |
negative_prompt=negative_prompt,
|
@@ -146,12 +147,13 @@ class EndpointHandler():
|
|
146 |
).images[0]
|
147 |
|
148 |
print("3rd pipeline part successful!")
|
149 |
-
|
150 |
|
151 |
# return first generate PIL image
|
152 |
return image
|
153 |
-
|
154 |
"""
|
|
|
|
|
155 |
control_image = self.make_inpaint_condition(image, mask_image)
|
156 |
|
157 |
# generate image
|
@@ -168,7 +170,7 @@ class EndpointHandler():
|
|
168 |
).images[0]
|
169 |
|
170 |
return image
|
171 |
-
|
172 |
|
173 |
# helper to decode input image
|
174 |
def decode_base64_image(self, image_string):
|
|
|
24 |
# )
|
25 |
# self.smooth_pipe.to("cuda")
|
26 |
|
27 |
+
|
28 |
self.controlnet = ControlNetModel.from_pretrained(
|
29 |
"lllyasviel/control_v11p_sd15_inpaint", torch_dtype=torch.float16
|
30 |
)
|
|
|
36 |
self.pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe.scheduler.config)
|
37 |
self.pipe.enable_model_cpu_offload()
|
38 |
self.pipe.enable_xformers_memory_efficient_attention()
|
39 |
+
|
40 |
"""
|
|
|
41 |
# load StableDiffusionInpaintPipeline pipeline
|
42 |
self.pipe = AutoPipelineForInpainting.from_pretrained(
|
43 |
"runwayml/stable-diffusion-inpainting",
|
|
|
45 |
torch_dtype=torch.float16,
|
46 |
)
|
47 |
# use DPMSolverMultistepScheduler
|
48 |
+
self.pipe.scheduler = DPMSolverMultistepScheduler.from_config(self.pipe.scheduler.config)
|
49 |
|
50 |
self.pipe.enable_model_cpu_offload()
|
51 |
|
|
|
63 |
self.pipe3 = AutoPipelineForImage2Image.from_pipe(self.pipe2)
|
64 |
#self.pipe3.enable_model_cpu_offload()
|
65 |
self.pipe3.enable_xformers_memory_efficient_attention()
|
66 |
+
"""
|
67 |
|
68 |
|
69 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
|
|
115 |
"""
|
116 |
|
117 |
#pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16").to("cuda")
|
118 |
+
"""
|
119 |
# run inference pipeline
|
120 |
out = self.pipe(prompt=prompt, negative_prompt=negative_prompt, image=image, mask_image=mask_image, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale)
|
121 |
|
|
|
124 |
image = out.images[0].resize((1024, 1024))
|
125 |
|
126 |
print("image resizing successful!")
|
127 |
+
|
128 |
image = self.pipe2(
|
129 |
prompt=prompt,
|
130 |
negative_prompt=negative_prompt,
|
|
|
147 |
).images[0]
|
148 |
|
149 |
print("3rd pipeline part successful!")
|
150 |
+
|
151 |
|
152 |
# return first generate PIL image
|
153 |
return image
|
|
|
154 |
"""
|
155 |
+
|
156 |
+
|
157 |
control_image = self.make_inpaint_condition(image, mask_image)
|
158 |
|
159 |
# generate image
|
|
|
170 |
).images[0]
|
171 |
|
172 |
return image
|
173 |
+
|
174 |
|
175 |
# helper to decode input image
|
176 |
def decode_base64_image(self, image_string):
|