BrightFameLabs commited on
Commit
767e9a8
1 Parent(s): 05012eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
9
+
10
+ # Define a function to handle the GET request at `/generate`
11
+ @app.get("/generate")
12
+ def generate(text: str):
13
+ """
14
+ Using the text2text-generation pipeline from `transformers`, generate text
15
+ from the given input text. The model used is `google/flan-t5-small`, which
16
+ can be found [here](https://huggingface.co/google/flan-t5-small).
17
+ """
18
+ # Use the pipeline to generate text from the given input text
19
+ output = pipe(text)
20
+
21
+ # Return the generated text in a JSON response
22
+ return {"output": output[0]["generated_text"]}