nateraw commited on
Commit
c420857
β€’
1 Parent(s): 8b9305c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+
5
+ description = """
6
+ ## Text Generation with πŸ€— transformers, FastAPI, and Docker
7
+
8
+ This app shows how to do text generation with Flan-T5 using FastAPI in a Docker Space πŸš€
9
+
10
+ Check out the [`/generate`](#/default/generate_generate_get) endpoint below to try it out!
11
+ """
12
+
13
+ # NOTE - we configure docs_url to serve the interactive Docs at the root path
14
+ # of the app. This way, we can use the docs as a landing page for the app on Spaces.
15
+ app = FastAPI(docs_url="/", description=description)
16
+
17
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
18
+
19
+
20
+ @app.get("/generate")
21
+ def generate(text: str):
22
+ """
23
+ Using the text2text-generation pipeline from `transformers`, generate text
24
+ from the given input text. The model used is `google/flan-t5-small`, which
25
+ can be found [here](https://huggingface.co/google/flan-t5-small).
26
+ """
27
+ output = pipe(text)
28
+ return {"output": output[0]["generated_text"]}