-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
26 lines (21 loc) · 757 Bytes
/
server.py
File metadata and controls
26 lines (21 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from fastapi import FastAPI, Query
from pydantic import BaseModel
from typing import List
from utils import classify_text, fetch_latest_messages_and_classify, to_dataframe, load_model
load_model()
app = FastAPI(title="Email Threat Detector API")
class PredictRequest(BaseModel):
text: str
@app.post("/predict_email")
def predict_email(req: PredictRequest):
res = classify_text(req.text)
return {
"label": res["label"],
"confidence": round(res["confidence"] * 100, 2),
"probs": res["probs"],
"labels": res["labels"]
}
@app.get("/scan_gmail")
def scan_gmail(limit: int = Query(10, ge=1, le=50)):
items = fetch_latest_messages_and_classify(limit=limit)
return {"count": len(items), "emails": items}