A-man123/text2textdocker
0
1from fastapi import FastAPI2from transformers import pipeline3 4#creat Fastapi app instance5app=FastAPI()6 7#initialize the text generation pipeline8pipe=pipeline("text2text-generation", model="google/flant-t5-small")9 10@app.get("/")11def home():12 return{"message":"hello world"}13 14#define a function to handle the GET request at '/generate'15 16@app.get("/generate")17def generate(text:str):18 ##use the pipeline to generate text from given input text19 output=pipe(text)20 21 #return the generate text in json response22 return{"output":output[0]['generated_text']}