Spaces:
Runtime error
Runtime error
Download core/pii_guard.py from Modrik-Team/Modrik: direct link, hf CLI and curl.
- Browser
- Download file 617 Bytes
-
https://huggingface.co/spaces/Modrik-Team/Modrik/resolve/main/core/pii_guard.py
- Command line
-
hf download hf://spaces/Modrik-Team/Modrik/core/pii_guard.py
-
curl -L -o pii_guard.py https://huggingface.co/spaces/Modrik-Team/Modrik/resolve/main/core/pii_guard.py
617 Bytes
| import re | |
| # Saudi National ID (10 digits, starts with 1) or Iqama (starts with 2) | |
| _SAUDI_ID = re.compile(r'\b[12]\d{9}\b') | |
| # Saudi IBAN: SA + 22 digits | |
| _IBAN = re.compile(r'\bSA\d{22}\b', re.IGNORECASE) | |
| _PATTERNS = [ | |
| (_SAUDI_ID, "[رقم هوية]"), | |
| (_IBAN, "[رقم IBAN]"), | |
| ] | |
| def redact_pii(text: str) -> tuple[str, int]: | |
| """Redact Saudi IDs and IBANs. Returns (redacted_text, count_redacted).""" | |
| count = 0 | |
| for pattern, replacement in _PATTERNS: | |
| matches = pattern.findall(text) | |
| count += len(matches) | |
| text = pattern.sub(replacement, text) | |
| return text, count | |