File size: 319 Bytes
1b6cdab |
1 2 3 4 5 6 7 8 9 10 11 |
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"]} |