Spaces:
Sleeping
Sleeping
Commit
·
bb24e55
1
Parent(s):
8aedd45
Add DeepGuard deepfake detection app with XceptionTransfer model
Browse files- .gitattributes +1 -0
- README.md +65 -6
- app.py +135 -0
- deepfake_model.keras +3 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.keras filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,14 +1,73 @@
|
|
| 1 |
---
|
| 2 |
-
title: DeepGuard
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: DeepGuard AI Face Authenticator
|
| 3 |
+
emoji: 🛡️
|
| 4 |
+
colorFrom: green
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
+
tags:
|
| 12 |
+
- deepfake-detection
|
| 13 |
+
- computer-vision
|
| 14 |
+
- tensorflow
|
| 15 |
+
- mlops
|
| 16 |
+
short_description: Deepfake face detection using XceptionTransfer with 88% accuracy
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# DeepGuard: AI Face Authenticator
|
| 20 |
+
|
| 21 |
+
A production-grade deep learning system for detecting AI-generated (deepfake) faces, built with a complete MLOps pipeline.
|
| 22 |
+
|
| 23 |
+
## Overview
|
| 24 |
+
|
| 25 |
+
DeepGuard leverages transfer learning with the Xception architecture to identify synthetic faces generated by GANs (Generative Adversarial Networks). The model achieves 88% accuracy with a 95% ROC-AUC score on StyleGAN-generated content.
|
| 26 |
+
|
| 27 |
+
## Model Performance
|
| 28 |
+
|
| 29 |
+
| Metric | Value |
|
| 30 |
+
|--------|-------|
|
| 31 |
+
| Test Accuracy | 88% |
|
| 32 |
+
| ROC-AUC Score | 95% |
|
| 33 |
+
| Training Dataset | 140,000 images |
|
| 34 |
+
| Architecture | XceptionTransfer |
|
| 35 |
+
| Input Resolution | 128x128 pixels |
|
| 36 |
+
|
| 37 |
+
## FFT Frequency Analysis Interpretation
|
| 38 |
+
|
| 39 |
+
The Fast Fourier Transform visualization provides forensic insight into image authenticity.
|
| 40 |
+
|
| 41 |
+
| Pattern | Interpretation |
|
| 42 |
+
|---------|----------------|
|
| 43 |
+
| Bright center spot | Normal low-frequency content (smooth areas) |
|
| 44 |
+
| Radiating spokes | Edge directions in the original image |
|
| 45 |
+
| Random noise distribution | Natural texture typical of real photographs |
|
| 46 |
+
| Grid or cross artifacts | Potential GAN fingerprint indicating synthetic generation |
|
| 47 |
+
|
| 48 |
+
Note: GAN artifacts in the frequency domain are subtle and serve as a supplementary forensic tool.
|
| 49 |
+
|
| 50 |
+
## Known Limitations
|
| 51 |
+
|
| 52 |
+
This model is trained on StyleGAN-generated faces. Detection accuracy may be reduced for:
|
| 53 |
+
|
| 54 |
+
- Images from diffusion models (Stable Diffusion, Midjourney, DALL-E)
|
| 55 |
+
- Non-face subjects or full-body photographs
|
| 56 |
+
- Heavily compressed or filtered images
|
| 57 |
+
|
| 58 |
+
## MLOps Pipeline
|
| 59 |
+
|
| 60 |
+
| Component | Technology |
|
| 61 |
+
|-----------|------------|
|
| 62 |
+
| Data Versioning | DVC |
|
| 63 |
+
| Experiment Tracking | MLflow + DagsHub |
|
| 64 |
+
| Model Training | TensorFlow / Keras |
|
| 65 |
+
| Deployment | Hugging Face Spaces |
|
| 66 |
+
|
| 67 |
+
## Repository
|
| 68 |
+
|
| 69 |
+
[GitHub: DeepGuard-MLOps-Pipeline](https://github.com/HarshTomar1234/DeepGuard-MLOps-Pipeline)
|
| 70 |
+
|
| 71 |
+
## License
|
| 72 |
+
|
| 73 |
+
MIT License
|
app.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load model
|
| 7 |
+
print("Loading DeepGuard model...")
|
| 8 |
+
model = tf.keras.models.load_model("deepfake_model.keras")
|
| 9 |
+
print("Model loaded successfully!")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def generate_fft(image):
|
| 13 |
+
"""Generate FFT magnitude spectrum visualization."""
|
| 14 |
+
try:
|
| 15 |
+
img_gray = image.convert('L').resize((128, 128))
|
| 16 |
+
img_array = np.array(img_gray, dtype=np.float32)
|
| 17 |
+
f_transform = np.fft.fft2(img_array)
|
| 18 |
+
f_shift = np.fft.fftshift(f_transform)
|
| 19 |
+
magnitude = np.abs(f_shift)
|
| 20 |
+
magnitude = np.log1p(magnitude)
|
| 21 |
+
magnitude = ((magnitude - magnitude.min()) / (magnitude.max() - magnitude.min()) * 255).astype(np.uint8)
|
| 22 |
+
return Image.fromarray(magnitude)
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"FFT Error: {e}")
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def predict(image):
|
| 29 |
+
"""Main prediction function."""
|
| 30 |
+
if image is None:
|
| 31 |
+
return None, "Please upload an image", None
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
img = image.convert('RGB').resize((128, 128))
|
| 35 |
+
img_array = np.array(img) / 255.0
|
| 36 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 37 |
+
|
| 38 |
+
prediction = float(model.predict(img_array, verbose=0)[0][0])
|
| 39 |
+
|
| 40 |
+
if prediction > 0.5:
|
| 41 |
+
label = "FAKE (AI Generated)"
|
| 42 |
+
confidence = prediction * 100
|
| 43 |
+
else:
|
| 44 |
+
label = "REAL (Authentic)"
|
| 45 |
+
confidence = (1 - prediction) * 100
|
| 46 |
+
|
| 47 |
+
result_text = f"""
|
| 48 |
+
## Detection Result: {label}
|
| 49 |
+
|
| 50 |
+
**Confidence:** {confidence:.2f}%
|
| 51 |
+
|
| 52 |
+
**Raw Model Score:** {prediction:.6f}
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
### Interpretation
|
| 57 |
+
- Score > 0.5: Model detects GAN artifacts = FAKE
|
| 58 |
+
- Score < 0.5: No GAN artifacts detected = REAL
|
| 59 |
+
|
| 60 |
+
### Important Note
|
| 61 |
+
This model is trained on StyleGAN-generated faces and may not accurately detect images from modern diffusion models (Stable Diffusion, Midjourney, DALL-E).
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
fft_image = generate_fft(image)
|
| 65 |
+
return result_text, fft_image
|
| 66 |
+
|
| 67 |
+
except Exception as e:
|
| 68 |
+
return f"Error: {str(e)}", None
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
with gr.Blocks(
|
| 72 |
+
title="DeepGuard - AI Face Authenticator",
|
| 73 |
+
theme=gr.themes.Base(primary_hue="green", secondary_hue="blue", neutral_hue="gray")
|
| 74 |
+
) as demo:
|
| 75 |
+
|
| 76 |
+
gr.HTML("""
|
| 77 |
+
<div style="text-align: center; margin-bottom: 1rem;">
|
| 78 |
+
<h1 style="color: #00f260; font-size: 2.5rem;">DeepGuard</h1>
|
| 79 |
+
<p style="color: #888;">AI Face Authenticator - Deepfake Detection</p>
|
| 80 |
+
</div>
|
| 81 |
+
""")
|
| 82 |
+
|
| 83 |
+
with gr.Row():
|
| 84 |
+
with gr.Column(scale=1):
|
| 85 |
+
input_image = gr.Image(label="Upload Image", type="pil", height=300)
|
| 86 |
+
analyze_btn = gr.Button("Analyze Image", variant="primary", size="lg")
|
| 87 |
+
|
| 88 |
+
with gr.Row():
|
| 89 |
+
with gr.Column(scale=2):
|
| 90 |
+
result_output = gr.Markdown(label="Detection Result")
|
| 91 |
+
with gr.Column(scale=1):
|
| 92 |
+
fft_output = gr.Image(label="FFT Frequency Analysis", height=200)
|
| 93 |
+
|
| 94 |
+
with gr.Accordion("How It Works", open=False):
|
| 95 |
+
gr.Markdown("""
|
| 96 |
+
### XceptionTransfer Deep Learning Model
|
| 97 |
+
|
| 98 |
+
- **Architecture:** Transfer learning with Xception backbone
|
| 99 |
+
- **Training Data:** 140,000 real and GAN-generated faces
|
| 100 |
+
- **Accuracy:** 88% on test dataset
|
| 101 |
+
- **ROC-AUC:** 95%
|
| 102 |
+
""")
|
| 103 |
+
|
| 104 |
+
with gr.Accordion("FFT Interpretation Guide", open=False):
|
| 105 |
+
gr.Markdown("""
|
| 106 |
+
| Pattern | Interpretation |
|
| 107 |
+
|---------|----------------|
|
| 108 |
+
| Bright center spot | Normal low-frequency content |
|
| 109 |
+
| Radiating spokes | Edge directions in original image |
|
| 110 |
+
| Random noise distribution | Natural texture (real photos) |
|
| 111 |
+
| Grid or cross artifacts | Potential GAN fingerprint |
|
| 112 |
+
|
| 113 |
+
*GAN artifacts in FFT are subtle and require trained interpretation.*
|
| 114 |
+
""")
|
| 115 |
+
|
| 116 |
+
with gr.Accordion("Model Limitations", open=False):
|
| 117 |
+
gr.Markdown("""
|
| 118 |
+
This model is trained on StyleGAN-generated faces only.
|
| 119 |
+
|
| 120 |
+
It may NOT accurately detect:
|
| 121 |
+
- Stable Diffusion / Midjourney / DALL-E images
|
| 122 |
+
- Non-face subjects
|
| 123 |
+
- Heavily edited images
|
| 124 |
+
""")
|
| 125 |
+
|
| 126 |
+
gr.HTML("""<div style="text-align: center; margin-top: 2rem; color: #666;">
|
| 127 |
+
Built with TensorFlow and MLflow | DeepGuard MLOps Pipeline
|
| 128 |
+
</div>""")
|
| 129 |
+
|
| 130 |
+
analyze_btn.click(fn=predict, inputs=input_image, outputs=[result_output, fft_output])
|
| 131 |
+
input_image.change(fn=predict, inputs=input_image, outputs=[result_output, fft_output])
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
demo.launch()
|
deepfake_model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e3b3d51181f4d1fa2678b6b822ba9e4becf67bb72231dfc693d42f1aff491dc3
|
| 3 |
+
size 169750460
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.0
|
| 2 |
+
tensorflow==2.17.0
|
| 3 |
+
numpy>=1.24.0
|
| 4 |
+
Pillow>=10.0.0
|