import logging import torch from diffusers import StableDiffusionPipeline, DPMSolverMultistepSchedule from towhee.operator import PyOperator log = logging.getLogger(PyOperator) class StableDiffusion(PyOperator): def __init__(self,model_id='stabilityai/stable-diffusion-2-1'): self._model_id=model_id def __call__(self, prompt:str): self.pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32) # pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) image = pipe(prompt).images[0] return image