diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..d006e26ca0d14f53f614ed618ce3cdb92ff59a14 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +*.pth filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.task filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.jpg filter=lfs diff=lfs merge=lfs -text +*.jpeg filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..41280c2d69b3540997d0322e87800110fb293a57 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Environment and Virtual Environments +venv/ +env/ +.env +__pycache__/ +*.pyc + +# IDEs and Editors +.vscode/ +.idea/ +*.swp + +# OS Files +.DS_Store +Thumbs.db + +# Frontend +frontend/node_modules/ +frontend/dist/ + +# Backend Output Caches +backend/uploads/ +backend/test_out/ +backend/reports/ + +*.log + +# Vite Cache +frontend/.vite/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..57c7c07c03fdb936b3eddd70df511e4b9349cfc5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +FROM python:3.10-slim + +# Install system dependencies needed for OpenCV, Librosa, and PyTorch +RUN apt-get update && apt-get install -y \ + ffmpeg \ + libsm6 \ + libxext6 \ + libgl1 \ + libgles2 \ + libegl1 \ + libmagic1 \ + && rm -rf /var/lib/apt/lists/* + +# Set up Hugging Face required non-root user +RUN useradd -m -u 1000 user +USER user + +# Set environment variables +ENV HOME=/home/user \ + PATH=/home/user/.local/bin:$PATH \ + PYTHONUNBUFFERED=1 \ + HF_HOME=/tmp/.cache/huggingface + +WORKDIR $HOME/app/backend + +# Install CPU-only PyTorch FIRST to save space +RUN pip install --no-cache-dir \ + torch torchvision --index-url https://download.pytorch.org/whl/cpu + +# Copy requirements and install remaining dependencies +COPY --chown=user:user backend/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt && \ + pip uninstall -y opencv-python opencv-python-headless opencv-contrib-python 2>/dev/null || true; \ + pip install --no-cache-dir opencv-contrib-python-headless + +# Copy the backend source code +COPY --chown=user:user backend/ . + +# Create dynamic directories +RUN mkdir -p uploads reports weights + +# Expose port 7860 for Hugging Face +EXPOSE 7860 + +# Start FastAPI via Uvicorn +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..467e164f0cb682ff843e6385f003dfe18d2670ec --- /dev/null +++ b/README.md @@ -0,0 +1,437 @@ +--- +title: Deepfake Forensics API +emoji: 🚀 +colorFrom: purple +colorTo: blue +sdk: docker +pinned: false +app_port: 7860 +--- +# Deepfake Forensics & Explainable AI (XAI) Engine + +
An Enterprise-Grade, Multi-Modal Ensemble System for Detecting AI-Generated Media, Digital Manipulation, and Deepfakes.
+ +Your analysis history is stored securely in your browser.
+Analyze your first media file to see it here.
+ ++ {file ? `Target: ${file.name}` : 'Establishing secure connection...'} +
++ Real cameras capture high frequencies naturally. AI generators produce mathematically "smooth" pixels. We use FFT and DCT to detect this unnatural lack of high-frequency energy. +
++ Images have a baked-in Bayer filter pattern (CFA) and uniform JPEG compression. We analyze Error Level Analysis (ELA) and missing CFA Artifacts to expose splicing. +
++ We track 468 facial landmarks across every frame to measure micro-jitters, unnatural head pose variations, and blinking anomalies that human eyes cannot detect. +
++ We process audio through a lightweight PyTorch 2D-CNN to calculate voice spoofing probability, while measuring lip-sync desynchronization using a dual-stream SyncNet. +
++ Real humans have a micro-pulse that changes facial skin tone slightly with every heartbeat. AI struggles to synthesize this coherent remote Photoplethysmography (rPPG) signal. +
++ The lighting environments reflected in the left and right corneas must match perfectly. We analyze these 2D specular reflections to identify inconsistencies generated by GANs/Diffusion models. +
++ We automatically extract and analyze the EXIF payload, detecting manipulation software signatures (Photoshop, Stable Diffusion), stripped metadata, and suspicious timestamps. +
++ Instead of rigid thresholds, a fully trained Multi-Layer Perceptron (MLP) evaluates all 15 visual, biological, and acoustic sensors to determine an ironclad, explainable final verdict. +
++ An enterprise-grade, multi-modal pipeline for synthetic media detection. + Upload any video or image to generate comprehensive visual evidence and a court-ready PDF report. +
++ Our forensic engine doesn't just guess. It breaks down media frame-by-frame, combining cutting-edge classification with explainable AI to show you exactly why a video is authentic or manipulated. +
+You upload a video or image. Our engine automatically extracts the audio track (if present), detects faces using MTCNN, and splits the video into a sequence of normalized, high-resolution frames.
+The extracted faces are passed through our fine-tuned EfficientNet-B4 neural network. This model has been specifically trained on massive deepfake datasets (like FaceForensics++) to detect subtle, pixel-level manipulation artifacts.
+Instead of a "black box" answer, we use GradCAM (Gradient-weighted Class Activation Mapping) and SHAP values. These algorithms generate heatmaps directly on the image, highlighting the exact pixels and regions the AI looked at to make its decision.
+For videos, manipulating the face often breaks the synchronization between the person's lip movements and the spoken audio track. Our SyncNet implementation calculates the offset/delay, acting as a powerful secondary check for lip-sync deepfakes.
+All multimodal signals (visual artifacts, audio-visual sync, and explainability maps) are synthesized into a final confidence score. You receive a court-grade forensic report detailing the findings.
++ Our platform utilizes a multi-modal ensemble of fine-tuned deep learning models. + Below you can explore the architecture, hyperparameter configurations, and empirical evaluation metrics + for each sub-network. +
++ {model.description} +
+ ++ This metric requires extremely high-resolution, clear, and well-lit closeups of the eyes to function correctly. If the person is far away, the image is blurry, or lighting is extremely dim, the anomaly score may be inaccurate or highly elevated. Its weight in the final ensemble calculation is heavily reduced to prevent false positives. +
++ {result.corneal_analysis.suppression_reason} The mathematical anomaly score was aggressively reduced to prevent a false positive. +
+{payload[0].payload.fullName}
++ {payload[0].value}% {payload[0].payload.direction} +
+The Meta-Classifier acts as the final "Judge". It does not look at the video pixels; instead, it analyzes the numerical scores generated by all the independent physical and biological sensors.
++ Frequency analysis mathematically decomposes an image into its constituent wave frequencies. Real cameras capture a natural balance of low frequencies (smooth gradients like skin) and high frequencies (sharp edges, pores, and natural sensor noise). AI-generated deepfakes often struggle to reproduce this microscopic high-frequency detail, resulting in an image that is mathematically "too smooth" at the pixel level. +
+ + {showFullSpectralInfo && ( + <> ++ Note: Blurry or low-quality laptop webcam photos will naturally have low high-frequency energy due to built-in camera denoising, which is why our XAI engine cross-references multiple sensors! +
+ > + )} + + +Visualization unavailable
++ {result.face_geometry.face_geometry_interpretation} +
+No face detected in the analyzed frame.
++ Arrows indicate the dominant 2D illumination direction extracted from image gradients. +
+| Noise Variance | ++ {result.noise_analysis?.noise_variance !== undefined ? result.noise_analysis.noise_variance.toFixed(2) : 'N/A'} + | +
| Anomaly Score | ++ {(result.noise_score * 100).toFixed(1)}% + | +
+ A very low noise variance typically indicates synthetic smoothing by a generative AI model. +
+The core neural network scans the raw pixels of the image looking for deepfake artifacts like blending errors, unnatural textures, and warping.
+What this score means: A score of {(result.nn_score * 100).toFixed(1)}% indicates the base neural network's raw assessment of synthetic manipulation, before any other physical or biological forensic sensors are consulted.
+Heatmap unavailable
++ {label !== undefined ? `Frame ${label}` : 'Data Point'} +
+ {payload.map((entry, index) => ( ++ What Happened: {explanation.what_happened} +
++ Why: {explanation.why_it_happened} +
+