Team Ai
Apppublic

nimraaslam7777/github

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
app.py26 linesDownload Raw Back to root
1from fastapi import FastAPI2from transformers import pipeline3 4## create a new FASTAPI app instance5app=FastAPI()6 7# Initialize the text generation pipeline8pipe = pipeline("text2text-generation", model="google/flan-t5-small")9 10 11@app.get("/")12def home():13    return {"message":"Hello World"}14 15# Define a function to handle the GET request at `/generate`16 17 18@app.get("/generate")19def generate(text:str):20    ## use the pipeline to generate text from given input text21    output=pipe(text)22 23    ## return the generate text in Json reposne24    return {"output":output[0]['generated_text']}25 26