| |
|
| | from fastapi import FastAPI
|
| | from pydantic import BaseModel
|
| | from utils import mask_pii, unmask_pii
|
| | from models import load_model
|
| |
|
| |
|
| |
|
| | app = FastAPI()
|
| |
|
| |
|
| | model = load_model("model/classifier.pkl")
|
| |
|
| |
|
| | class EmailRequest(BaseModel):
|
| | email_body: str
|
| |
|
| |
|
| | @app.post("/predict")
|
| | def classify_email(req: EmailRequest):
|
| | email_text = req.email_body
|
| |
|
| |
|
| | masked_text, entities = mask_pii(email_text)
|
| |
|
| |
|
| | category = model.predict([masked_text])[0]
|
| |
|
| |
|
| | response = {
|
| | "input_email_body": email_text,
|
| | "list_of_masked_entities": entities,
|
| | "masked_email": masked_text,
|
| | "category_of_the_email": category
|
| | }
|
| |
|
| | return response
|
| |
|