# utils/verifier.py from lettucedetect.models.inference import HallucinationDetector import logging from typing import List, Dict, Optional logger = logging.getLogger(__name__) class DischargeVerifier: def __init__(self): """Initialize the hallucination detector.""" try: self.detector = HallucinationDetector( method="transformer", model_path="KRLabsOrg/lettucedect-base-modernbert-en-v1", ) logger.info("Hallucination detector initialized successfully") except Exception as e: logger.error(f"Failed to initialize hallucination detector: {str(e)}") raise def create_interactive_text(self, text: str, spans: List[Dict[str, int | float]]) -> str: """Create interactive HTML with highlighting and hover effects.""" html_text = text for span in sorted(spans, key=lambda x: x["start"], reverse=True): span_text = text[span["start"]:span["end"]] highlighted_span = ( f'{span_text}' ) html_text = ( html_text[:span["start"]] + highlighted_span + html_text[span["end"]:] ) return f"""