File size: 1,057 Bytes
7d66be2 f18e889 36f36ee f18e889 7a19876 7d66be2 f18e889 e76c41a f18e889 a531f9e 1cb9eb1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import torch
from PIL.Image import Image
from diffusers import StableDiffusionXLPipeline, LCMScheduler
from pipelines.models import TextToImageRequest
from torch import Generator
def load_pipeline() -> StableDiffusionXLPipeline:
pipeline = StableDiffusionXLPipeline.from_pretrained(
"./models/newdream-sdxl-20",
torch_dtype=torch.float16,
local_files_only=True,
).to("cuda")
pipeline.scheduler = LCMScheduler.from_config(pipeline.scheduler.config)
pipeline.load_lora_weights("./models/sdxl-lcmlora-1024-100k-3000steps")
pipeline(prompt="")
return pipeline
def infer(request: TextToImageRequest, pipeline: StableDiffusionXLPipeline) -> Image:
generator = Generator(pipeline.device).manual_seed(request.seed) if request.seed else None
return pipeline(
prompt=request.prompt,
negative_prompt=request.negative_prompt,
width=request.width,
height=request.height,
generator=generator,
num_inference_steps=4,
guidance_scale=1.5,
).images[0]
|