cjell
commited on
Commit
·
3d9e243
1
Parent(s):
d6a0a15
app.py
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
@app.get("/")
|
| 10 |
+
def root():
|
| 11 |
+
return {"status": "ok"}
|
| 12 |
+
|
| 13 |
+
class Query(BaseModel):
|
| 14 |
+
text: str
|
| 15 |
+
|
| 16 |
+
@app.post("/predict")
|
| 17 |
+
def predict(query: Query):
|
| 18 |
+
result = classifier(query.text)[0]
|
| 19 |
+
return {"label": result["label"], "score": result["score"]}
|
| 20 |
+
|