Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,28 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
# Disable xformers if needed
|
| 9 |
+
torch.backends.cuda.enable_flash_sdp(False)
|
| 10 |
+
torch.backends.cuda.enable_mem_efficient_sdp(False)
|
| 11 |
+
|
| 12 |
+
# Load model
|
| 13 |
+
model = pipeline(
|
| 14 |
+
"text-classification",
|
| 15 |
+
model="win2win/3-epochs-classifier-ver2",
|
| 16 |
+
device="cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
class Request(BaseModel):
|
| 20 |
+
text: str
|
| 21 |
+
|
| 22 |
+
@app.post("/predict")
|
| 23 |
+
async def predict(request: Request):
|
| 24 |
+
return model(request.text)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
import uvicorn
|
| 28 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|