omarkham commited on
Commit
cc47fc6
·
1 Parent(s): 6f6bd65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ #Create a new FastAPI app instance
5
+ app = FastAPI()
6
+
7
+ #Initialize the text generation pipeline
8
+ #This function will be able to generate text
9
+ #given an input
10
+ pipe = pipeline("text2text-generation",
11
+ model="google/flan-t5-small")
12
+
13
+ @app.get("/generate")
14
+ def generate(text: str):
15
+ #Use the pipeline to generate text from the given input text
16
+ output = pipe(text)
17
+
18
+ #Return the generated text in a JSON response
19
+ return {"output": output[0]["generated_text"]}