Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
from fastapi import FastAPI, Request, HTTPException
|
| 3 |
|
| 4 |
+
app = FastAPI()
|
| 5 |
|
| 6 |
+
generator = pipeline('text2text-generation', model='google/flan-t5-small')
|
| 7 |
|
| 8 |
+
@app.post("/")
|
| 9 |
+
async def generate(request: Request):
|
| 10 |
+
try:
|
| 11 |
+
data = await request.json()
|
| 12 |
+
text = data["text"]
|
| 13 |
+
output = generator(text)
|
| 14 |
+
return {"output": output[0]["generated_text"]}
|
| 15 |
+
except Exception as e:
|
| 16 |
+
raise HTTPException(status_code=500, detail=str(e))
|