from fastapi import FastAPI from diffusers import DiffusionPipeline from transformers import AutoModel #transformers.utils.move_cache() app = FastAPI() # Load the model once when the application starts pipe = DiffusionPipeline.from_pretrained("Norod78/sd15-caricature-portraits-blip-captions") @app.post("/generate/") async def generate_image(prompt: str): image = pipe(prompt).images[0] return image