change pipeline to user StableDiffusionXLPipeling
Browse files- handler.py +3 -3
handler.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
import torch
|
| 3 |
from torch import autocast
|
| 4 |
-
from diffusers import
|
| 5 |
import base64
|
| 6 |
from io import BytesIO
|
| 7 |
|
|
@@ -13,7 +13,7 @@ if device.type != "cuda":
|
|
| 13 |
|
| 14 |
class EndpointHandler():
|
| 15 |
def __init__(self, path="") :
|
| 16 |
-
self.pipe =
|
| 17 |
self.pipe = self.pipe.to(device)
|
| 18 |
|
| 19 |
|
|
@@ -21,7 +21,7 @@ class EndpointHandler():
|
|
| 21 |
inputs = data.pop("inputs", data)
|
| 22 |
|
| 23 |
with autocast(device.type):
|
| 24 |
-
image = self.pipe(inputs, guidance_scale=7.5)[
|
| 25 |
|
| 26 |
buffered = BytesIO()
|
| 27 |
image.save(buffered, format="JPEG")
|
|
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
import torch
|
| 3 |
from torch import autocast
|
| 4 |
+
from diffusers import StableDiffusionXLPipeline
|
| 5 |
import base64
|
| 6 |
from io import BytesIO
|
| 7 |
|
|
|
|
| 13 |
|
| 14 |
class EndpointHandler():
|
| 15 |
def __init__(self, path="") :
|
| 16 |
+
self.pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 17 |
self.pipe = self.pipe.to(device)
|
| 18 |
|
| 19 |
|
|
|
|
| 21 |
inputs = data.pop("inputs", data)
|
| 22 |
|
| 23 |
with autocast(device.type):
|
| 24 |
+
image = self.pipe(inputs, guidance_scale=7.5).images[0]
|
| 25 |
|
| 26 |
buffered = BytesIO()
|
| 27 |
image.save(buffered, format="JPEG")
|