karimbenharrak
commited on
Update handler.py
Browse files- handler.py +4 -7
handler.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from typing import Dict, List, Any
|
2 |
import torch
|
3 |
-
from diffusers import
|
4 |
from PIL import Image
|
5 |
import base64
|
6 |
from io import BytesIO
|
@@ -15,12 +15,8 @@ if device.type != 'cuda':
|
|
15 |
class EndpointHandler():
|
16 |
def __init__(self, path=""):
|
17 |
|
18 |
-
#self.fast_pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16").to("cuda")
|
19 |
-
#self.generator = torch.Generator(device="cuda").manual_seed(0)
|
20 |
-
|
21 |
-
|
22 |
self.smooth_pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
23 |
-
"stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16
|
24 |
)
|
25 |
self.smooth_pipe.to("cuda")
|
26 |
|
@@ -38,7 +34,8 @@ class EndpointHandler():
|
|
38 |
|
39 |
if encoded_image is not None:
|
40 |
image = self.decode_base64_image(encoded_image)
|
41 |
-
|
|
|
42 |
|
43 |
return out
|
44 |
|
|
|
1 |
from typing import Dict, List, Any
|
2 |
import torch
|
3 |
+
from diffusers import StableDiffusionXLImg2ImgPipeline
|
4 |
from PIL import Image
|
5 |
import base64
|
6 |
from io import BytesIO
|
|
|
15 |
class EndpointHandler():
|
16 |
def __init__(self, path=""):
|
17 |
|
|
|
|
|
|
|
|
|
18 |
self.smooth_pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
19 |
+
"stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16
|
20 |
)
|
21 |
self.smooth_pipe.to("cuda")
|
22 |
|
|
|
34 |
|
35 |
if encoded_image is not None:
|
36 |
image = self.decode_base64_image(encoded_image)
|
37 |
+
self.smooth_pipe.enable_xformers_memory_efficient_attention()
|
38 |
+
out = self.smooth_pipe(prompt, image=image, ).images[0]
|
39 |
|
40 |
return out
|
41 |
|