File size: 497 Bytes
d93f45c
b51ba4d
7852f50
 
115f6cd
04b233c
115f6cd
7852f50
b51ba4d
d93f45c
b51ba4d
 
 
 
bea1510
d93f45c
115f6cd
 
93fc612
8450a77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
import requests

from transformers import pipeline, set_seed
generator = pipeline('text-generation', model='gpt2-medium')
set_seed(42)


app = FastAPI()

@app.get("/")
async def docs_redirect():
    return RedirectResponse(url='/docs')

@app.get("/generate")
def generate(text: str):
    output: list[dict] = generator(text, max_length=200, num_return_sequences=1)
    print(output)
    return output[0]["generated_text"]