File size: 528 Bytes
9aacd06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 transformers import pipeline

#create fastapi instance
app = FastApi()

#initilize the text pipeline
# Use a pipeline as a high-level helper


pipe = pipeline("text2text-generation", model="google/flan-t5-small")

@app.get(/)
def home():
    return {"retuen mess : hello world"}
#defin function get handle the get requests
@app.get(/generate)
def generate(text:str):
    #using the pipeline
    output = pipe(text)

    ##retuen the text in json
    return{"output":output[0]["generate_text"]}