Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastApi
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
#create fastapi instance
|
| 5 |
+
app = FastApi()
|
| 6 |
+
|
| 7 |
+
#initilize the text pipeline
|
| 8 |
+
# Use a pipeline as a high-level helper
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 12 |
+
|
| 13 |
+
@app.get(/)
|
| 14 |
+
def home():
|
| 15 |
+
return {"retuen mess : hello world"}
|
| 16 |
+
#defin function get handle the get requests
|
| 17 |
+
@app.get(/generate)
|
| 18 |
+
def generate(text:str):
|
| 19 |
+
#using the pipeline
|
| 20 |
+
output = pipe(text)
|
| 21 |
+
|
| 22 |
+
##retuen the text in json
|
| 23 |
+
return{"output":output[0]["generate_text"]}
|
| 24 |
+
|