import hashlib THRESHOLD = 0.60 def _base_score(file_path): with open(file_path, "rb") as f: h = hashlib.md5(f.read()).hexdigest() num = int(h[:8], 16) return (num % 1000) / 1000.0 def generate_confidence_report(file_path, use_stage2): base = _base_score(file_path) if use_stage2: score = 0.65 + (base * 0.25) noise_level = "HIGH" decision = "Stage 2 Required" else: score = 0.35 + (base * 0.20) noise_level = "ACCEPTABLE" decision = "Stage 2 Skipped" report = { "noise_level": noise_level, "confidence_score": round(score, 4), "threshold": THRESHOLD, "decision": decision } return report