Text Generation
Not-For-All-Audiences
ChatR / 6
ImRasul1's picture
Create 6
1b6cdab verified
raw
history blame contribute delete
319 Bytes
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"]}