File size: 613 Bytes
433d05b
 
 
 
 
 
 
 
 
 
 
 
ba9bf2d
433d05b
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI
from transformers import pipeline

# create a new Fastapi instance
app = FastAPI()

# initialize the text generation pipeline
pipe = pipeline("text2text-generation", model="google/flan-t5-small")

# define the endpoint for this application
@app.get("/")
def home():
    return ({"message":"hello world!"})

# define a function to handle the GET request at '/generate'
@app.get("/generate")
def generate(text:str):
    # use the pipeline to generate text from given input text
    result = pipe(text)
    # return the generated text 
    return {"output": result[0]['generated_text']}