pablozramirez commited on
Commit
be16e56
·
verified ·
1 Parent(s): 24b2c51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from fastapi import FastAPI
3
+ from transformers import pipeline
4
+
5
+
6
+ # NOTE - we configure docs_url to serve the interactive Docs at the root path
7
+ # of the app. This way, we can use the docs as a landing page for the app on Spaces.
8
+ app = FastAPI(docs_url="/")
9
+
10
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
11
+
12
+
13
+ @app.get("/generate")
14
+ def generate(text: str):
15
+ """
16
+ Using the text2text-generation pipeline from `transformers`, generate text
17
+ from the given input text. The model used is `google/flan-t5-small`, which
18
+ can be found [here](https://huggingface.co/google/flan-t5-small).
19
+ """
20
+ output = pipe(text)
21
+ return {"output": output[0]["generated_text"]}