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']}