suryanshp1's picture
Upload 3 files
a0c3867 verified
raw
history blame
596 Bytes
from fastapi import FastAPI
from tranformers import pipeline
## create a new FastAPI app instance
app=FastAPI()
# initialize text generation pipeline
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
@app.get("/")
def home():
return {"message": "Welcome to home page!"}
# Define a function to handle the GET request at '/generate'
@app.get("/generate")
def generate(text: str):
# Generate text using the pipeline
generated_text = pipe(text)
# Return the generated text
return {"output": generated_text[0]["generated_text"]}