GhulamJillani's picture
Update app.py
2f3c12c verified
from fastapi import FastAPI
from transformers import pipeline
## create a new FastAPI App instance
app = FastAPI()
# Initialize the text generation pipeline
pipe = pipeline('text2text-generation', model='google/fan-t5-small')
@app.get("/")
def home():
return {"message": "Hello World"}
# Define a function to hancle the GET request as '/generate'
@app.get("/generate")
def generate_text(prompt: str):
## use the pipeline to generate text from given input prompt
output = pipe(prompt, max_length=50, do_sample=True, temperature=0.6)
## return the generate text in JSON format
return {"output": output[0]['generated_text']}