from fastapi import FastAPI from transformers import pipeline app = FastAPI() generator = pipeline("text-generation", model="gpt2") @app.post("/generate/") def generate_text(prompt: str): result = generator(prompt, max_length=50, num_return_sequences=1) return {"generated_text": result[0]["generated_text"]}