Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,21 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
### Create a new FastAPI instance
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
### Initialize the text generation pipeline
|
| 8 |
+
pipe = pipeline(
|
| 9 |
+
task="text2text-generation",
|
| 10 |
+
model="google-t5/t5-base"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
@app.get("/")
|
| 14 |
+
def home():
|
| 15 |
+
return {"message": "Hello world"}
|
| 16 |
+
|
| 17 |
+
### Define a function to handle GET request at '/generate'
|
| 18 |
+
@app.get("/generate")
|
| 19 |
+
def generate(text: str):
|
| 20 |
+
output = pipe(text)
|
| 21 |
+
return {"output": output[0]['generated_text']}
|
|
|
|
|
|