Spaces:
Runtime error
Runtime error
Download api.py from UB2002/email_classification: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/UB2002/email_classification/resolve/main/api.py
- Command line
-
hf download hf://spaces/UB2002/email_classification/api.py
-
curl -L -o api.py https://huggingface.co/spaces/UB2002/email_classification/resolve/main/api.py
1.03 kB
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel | |
| from typing import List, Dict | |
| from utils import mask_pii, demask_pii | |
| from models import classify_email | |
| app = FastAPI() | |
| class Entity(BaseModel): | |
| position: List[int] | |
| classification: str | |
| entity: str | |
| class RequestBody(BaseModel): | |
| email_body: str | |
| class ResponseBody(BaseModel): | |
| input_email_body: str | |
| list_of_masked_entities: List[Entity] | |
| masked_email: str | |
| category_of_the_email: str | |
| def index(): | |
| return "hello world" | |
| def classify_email_endpoint(req: RequestBody): | |
| text = req.email_body | |
| if not text: | |
| raise HTTPException(status_code=400, detail="Empty email body") | |
| masked_text, entities = mask_pii(text) | |
| category = classify_email(masked_text) | |
| return ResponseBody( | |
| input_email_body=text, | |
| list_of_masked_entities=entities, | |
| masked_email=masked_text, | |
| category_of_the_email=category, | |
| ) |