import { useRef, useState, useCallback } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Upload, FileImage, FileVideo, AlertCircle, Sparkles } from 'lucide-react'; import CameraCapture from './CameraCapture'; import styles from './UploadZone.module.css'; const MAX_SIZE_MB = 200; const ACCEPTED_IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/webp', 'image/gif', 'image/tiff', 'image/avif']; const ACCEPTED_VIDEO_TYPES = ['video/mp4', 'video/webm', 'video/quicktime', 'video/x-msvideo', 'video/avi']; export default function UploadZone({ onFileSelect, error }) { const inputRef = useRef(null); const [isDragging, setIsDragging] = useState(false); const [dragType, setDragType] = useState(null); const [validationError, setValidationError] = useState(null); const validateFile = useCallback((file) => { if (!file) return 'No file selected'; const isImage = ACCEPTED_IMAGE_TYPES.includes(file.type) || file.type.startsWith('image/'); const isVideo = ACCEPTED_VIDEO_TYPES.includes(file.type) || file.type.startsWith('video/'); if (!isImage && !isVideo) return 'Unsupported file format. Please use an image or video file.'; if (file.size > MAX_SIZE_MB * 1024 * 1024) return `File is too large. Maximum size is ${MAX_SIZE_MB} MB.`; return null; }, []); const handleDragOver = useCallback((event) => { event.preventDefault(); const file = event.dataTransfer?.items?.[0]; if (!file) return; setIsDragging(true); if (file.type.startsWith('image/')) setDragType('image'); else if (file.type.startsWith('video/')) setDragType('video'); else setDragType('invalid'); }, []); const handleDragLeave = useCallback((event) => { event.preventDefault(); setIsDragging(false); setDragType(null); }, []); const handleDrop = useCallback((event) => { event.preventDefault(); setIsDragging(false); setDragType(null); const file = event.dataTransfer?.files?.[0]; if (!file) return; const validation = validateFile(file); if (validation) { setValidationError(validation); return; } setValidationError(null); onFileSelect(file); }, [validateFile, onFileSelect]); const handleInputChange = useCallback((event) => { const file = event.target.files?.[0]; if (!file) return; const validation = validateFile(file); if (validation) { setValidationError(validation); return; } setValidationError(null); onFileSelect(file); }, [validateFile, onFileSelect]); const handleClick = () => { setValidationError(null); inputRef.current?.click(); }; return (
Upload an image or video for multi-model forensic analysis. UAIDE detects deepfakes, GAN artifacts, and AI-generated content using Grad-CAM heatmaps and frequency analysis.
Unsupported format
Drop images or video files only
> ) : ( <>Release to analyse
{dragType === 'video' ? 'Video file detected' : 'Image file detected'}
> )}Drag & drop your media here
or browse files
Max file size: {MAX_SIZE_MB} MB