Team Ai
Apppublic

hishn12/Email_Classification_without_LLM

sourceHugging Facemitupdated 1y agoView on Hugging Face
1likes
text_processor.py34 linesDownload Raw Back to root
1from typing import Dict, Tuple2from detector import PIIDetector3from masker import PIIMasker4from logger import setup_logger5 6logger = setup_logger(__name__)7 8 9class TextProcessor:10    """Coordinates PII detection and masking process (Regex Only)."""11 12    def __init__(13            self,14            detector: PIIDetector,15            masker: PIIMasker16    ):17        self.detector = detector18        self.masker = masker19 20    def process(self, text: str) -> Tuple[str, Dict]:21        """Process text to detect and mask PII."""22        try:23            # Detect PII using regex patterns24            pii_findings = self.detector.detect(text)25 26            # Mask PII entities27            masked_text = self.masker.mask(text, pii_findings)28 29            return masked_text, pii_findings30 31        except Exception as e:32            logger.error(f"Text processing error: {e}")33            return text, {}34