import React, { useState } from 'react'; import { Upload, FileText, RefreshCw, Cpu, Zap, AlertTriangle, Terminal, Play } from 'lucide-react'; import { Progress } from '../components/Progress'; import { Slider } from '../components/Slider'; import { BackButton } from '../components/BackButton'; import { cn } from '../lib/utils'; import { endpoints, getAuthHeaders } from '../lib/api'; const LEVEL_DESCRIPTIONS = [ { title: "Level 0: Pass-Through / Convert", desc: "No redaction applied. Converts document structure or image format cleanly.", badge: "Neutral", color: "text-slate-400" }, { title: "Level 1: Ultra-Fast Regex Rules", desc: "Instantly masks structured text (Emails, PAN, Aadhaar) across all documents via fast OCR.", badge: "Regex Fast", color: "text-blue-400" }, { title: "Level 2: Lightweight AI NER", desc: "Uses spaCy NER to identify names, locations, and organizations with low latency across all documents.", badge: "spaCy Small", color: "text-indigo-400" }, { title: "Level 3: Enhanced AI NER + Faces", desc: "High-precision entity detection via spaCy medium NLP. For PDFs & Images: automatically detects and blurs Human Faces.", badge: "spaCy Medium + Faces", color: "text-blue-400" }, { title: "Level 4: Advanced Domain NER + Signatures", desc: "Broad semantic masking using spaCy domain pipeline. For PDFs & Images: blurs Human Faces and Handwritten Signatures.", badge: "spaCy Best + Signatures", color: "text-purple-400" }, { title: "Level 5: Maximum Deep Learning + Biometrics", desc: "RoBERTa transformers for text/data files. For PDFs & Images: Total Biometric Redaction (Faces, Signatures, Stamps & Fingerprints).", badge: "Total Biometric AI", color: "text-red-400 font-bold" }, ]; export function PDFRedaction() { const [file, setFile] = useState(null); const [redactionLevel, setRedactionLevel] = useState([2]); const [progress, setProgress] = useState(0); const [isProcessing, setIsProcessing] = useState(false); const [isDragging, setIsDragging] = useState(false); const currentLevel = redactionLevel[0]; const levelInfo = LEVEL_DESCRIPTIONS[currentLevel] || LEVEL_DESCRIPTIONS[0]; const handleFileSelect = (selectedFile: File) => { setFile(selectedFile); setProgress(0); const interval = setInterval(() => { setProgress((prev) => { if (prev >= 100) { clearInterval(interval); return 100; } return prev + 15; }); }, 150); }; const handleFileUpload = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (file) handleFileSelect(file); }; const handleDrop = (event: React.DragEvent) => { event.preventDefault(); setIsDragging(false); const file = event.dataTransfer.files?.[0]; if (file) handleFileSelect(file); }; const handleRedact = async () => { if (isProcessing || !file) return; setIsProcessing(true); const formData = new FormData(); formData.append("file", file); formData.append("redaction_level", currentLevel.toString()); formData.append("mode", "mask"); try { const response = await fetch(endpoints.redactFile, { method: "POST", headers: getAuthHeaders(), body: formData, }); if (response.ok) { const blob = await response.blob(); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = `redactx_${file.name}`; link.click(); } else { const err = await response.json().catch(() => ({ detail: "Unknown server error" })); alert(`Redaction failed: ${err.detail || 'Server rejected file processing'}`); } } catch (error) { console.error("Error redacting file:", error); alert("Error communicating with RE-DACT backend server. Ensure backend is running."); } finally { setIsProcessing(false); } }; return (
{/* Top SOC Critical Alert Banner */}
DOCUMENT OCR SANITIZER
Escalation: Level {currentLevel} Offline Tesseract OCR: ACTIVE

Document & Image OCR Redaction

Sanitize PDF documents, Excel sheets, Word files, PowerPoint presentations, Images, and Logs using offline AI.

MULTI-FORMAT OCR ENGINE
{/* Dropzone */}
{ e.preventDefault(); setIsDragging(true); }} onDragLeave={() => setIsDragging(false)} onDrop={handleDrop} className={cn( "border border-dashed rounded-sm p-10 transition-all flex flex-col items-center justify-center text-center cursor-pointer group font-mono", isDragging ? "border-red-500 bg-red-950/20" : "border-slate-800 hover:border-slate-700 bg-slate-950" )} >
{['PDF', 'DOCX', 'XLSX', 'PPTX', 'CSV', 'TXT', 'LOG', 'PNG', 'JPG'].map((fmt) => ( {fmt} ))}
{file && (
{/* File Info & Upload Progress */}

{file.name}

{(file.size / 1024).toFixed(1)} KB • {file.type || 'Document'}

File Readiness {progress}%
{/* Redaction Level Slider */}
Redaction Scale {levelInfo.badge}
Level {currentLevel} of 5

{levelInfo.title}

{levelInfo.desc}

{/* Action Button */}
)}
); }