Spaces:
Sleeping
Sleeping
Commit
·
efb707f
1
Parent(s):
bf297c3
Fix perm
Browse files
main.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
-
from utils import mask_pii
|
| 4 |
from models import load_model, classify_email
|
| 5 |
|
| 6 |
app = FastAPI()
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
+
from utils import mask_pii
|
| 4 |
from models import load_model, classify_email
|
| 5 |
|
| 6 |
app = FastAPI()
|
utils.py
CHANGED
|
@@ -55,20 +55,4 @@ def mask_pii(text: str) -> Tuple[str, List[Dict]]:
|
|
| 55 |
placeholder = f"[{entity['classification']}]"
|
| 56 |
masked_text = masked_text[:start] + placeholder + masked_text[end:]
|
| 57 |
|
| 58 |
-
return masked_text, entities
|
| 59 |
-
def demask_pii(masked_text: str, entities: List[Dict]) -> str:
|
| 60 |
-
"""
|
| 61 |
-
Given `masked_text` (with placeholders like “[email]”) and the
|
| 62 |
-
`entities` list (each entry has position, classification, entity),
|
| 63 |
-
restore the original substrings at their exact positions.
|
| 64 |
-
"""
|
| 65 |
-
result = masked_text
|
| 66 |
-
# Sort in ascending order of start‐index, so that earlier replacements
|
| 67 |
-
# don’t break the indices of later ones.
|
| 68 |
-
for ent in sorted(entities, key=lambda x: x["position"][0]):
|
| 69 |
-
start, end = ent["position"]
|
| 70 |
-
placeholder = f"[{ent['classification']}]"
|
| 71 |
-
original = ent["entity"]
|
| 72 |
-
# Replace the placeholder at the exact location with the original text.
|
| 73 |
-
result = result[:start] + original + result[start + len(placeholder):]
|
| 74 |
-
return result
|
|
|
|
| 55 |
placeholder = f"[{entity['classification']}]"
|
| 56 |
masked_text = masked_text[:start] + placeholder + masked_text[end:]
|
| 57 |
|
| 58 |
+
return masked_text, entities
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|