from diffusers import DiffusionPipeline from typing import Any, Dict, List import torch class EndpointHandler: def __init__(self, path=""): self.pipeline = DiffusionPipeline.from_pretrained( path, torch_dtype=torch.bfloat16 ).to("cuda") def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: inputs = data.pop("inputs") prompt = inputs.pop("prompt", "dog") guidance_scale = inputs.pop("guidance_scale", 4.5) num_inference_steps = inputs.pop("num_inference_steps", 28) seed = inputs.pop("seed", 0) prediction = self.pipeline( prompt, negative_prompt="bad quality, worse quality, deformed", guidance_scale=guidance_scale, num_inference_steps=num_inference_steps, generator=torch.manual_seed(seed) ).images[0] return prediction