scott12355 commited on
Commit
838117b
·
verified ·
1 Parent(s): 6f8a9f6

Update app.py

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