File size: 596 Bytes
a0c3867
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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"]}