🛡️ Defakepy: Open Source Deepfake & AI Detection Library
Defakepy is a powerful, open-source forensic suite for detecting AI-generated content across text, audio, and video. It uses an ensemble of statistical, biological, and cryptographic techniques to produce a human-readable Trust Score.
⚖️ Disclaimer: Detection is probabilistic, not absolute. Defakepy is a tool to assist human judgment, not replace it.
✨ Key Features
| Feature | Method | Detects |
|---|---|---|
| Text Forensics | RoBERTa binary classifier | LLM-generated prose (GPT-4, Claude, Llama) |
| Image Analysis | ViT (Vision Transformer) classifier | AI-generated images (Midjourney, DALL-E, SD) |
| Video Analysis | Eye Aspect Ratio (EAR) | Unnatural blinking in face videos |
| Audio Forensics | MFCC Spectral Analysis | AI voice cloning & synthetic speech |
| Provenance Check | C2PA Metadata | Missing/invalid digital watermarks |
🚀 Installation
Defakepy is "Lite by Default" — the core package is tiny and installs instantly. Install only the features you need.
Core (Instant)
pip install defakepy
Feature Extras
Install only what your use case requires:
| Extra | Command | What it enables |
|---|---|---|
| Text | pip install "defakepy[text]" |
torch + transformers for text AI detection |
| Image | pip install "defakepy[image]" |
ViT classifier for AI image detection |
| Audio | pip install "defakepy[audio]" |
librosa + scipy for cloned voice detection |
| Vision | pip install "defakepy[vision]" |
dlib + opencv for deepfake video detection |
| Provenance | pip install "defakepy[provenance]" |
c2pa-python for digital signature checks |
| Full | pip install "defakepy[full]" |
Everything above combined |
� Usage
1. Python API
Analyze a String of Text
from defakepy import ForensicScanner
scanner = ForensicScanner()
text = """Artificial intelligence has rapidly transformed numerous industries,
offering unprecedented efficiencies and capabilities that were unimaginable before."""
report = scanner.text_engine.analyze(text)
print(f"AI Generated: {report['is_ai']}")
print(f"AI Probability: {report['ai_probability'] * 100:.1f}%") # e.g., 87.3%
print(f"Burstiness: {report['burstiness']:.2f}") # Sentence variety
print(f"Confidence: {report['confidence']}%")
Analyze an Image File
scanner = ForensicScanner()
report = scanner.image_engine.analyze("suspicious_photo.jpg")
print(f"AI Generated: {report['is_ai']}")
print(f"AI Probability: {report['ai_probability'] * 100:.1f}%")
print(f"Confidence: {report['confidence']}%")
Analyze an Audio File
scanner = ForensicScanner()
report = scanner.audio_engine.analyze("voice_clip.wav")
print(f"Synthetic Voice: {report['is_synthetic']}")
print(f"Confidence: {report['confidence']}%")
Analyze a Video File
scanner = ForensicScanner()
report = scanner.vision_engine.analyze("interview.mp4")
print(f"Suspicious: {report['is_suspicious']}")
print(f"Blink Count: {report['blink_count']}")
print(f"Confidence: {report['confidence']}%")
All-in-One File Scan
Automatically detects file type and runs the appropriate engine:
scanner = ForensicScanner()
report = scanner.scan_file("suspicious_video.mp4")
print(f"Trust Score: {report['trust_score']}/100")
print(f"Status: {'CLEAR' if report['trust_score'] > 70 else 'SUSPICIOUS'}")
for flag in report.get('flags', []):
print(f" [!] {flag}")
2. Command-Line Interface (CLI)
Basic Scan
defakepy-scan --input suspicious_video.mp4
Output as JSON (for scripting/automation)
defakepy-scan --input my_article.txt --json
Check Version
defakepy-scan --version
Example CLI Output
========================================
🛡️ DEFAKEPY FORENSIC REPORT
========================================
File: suspicious_video.mp4
Type: VIDEO
Provenance: Unsigned
Trust Score: 45/100
----------------------------------------
STATUS: SUSPICIOUS
FLAGS:
[!] Biological Anomaly: Low/Zero Blink Rate
[!] Audio Anomaly: Synthetic Spectral Signature
[!] Metadata Trace: Missing C2PA/Digital Signature
========================================
📊 Understanding the Output
Trust Score
- > 70 → ✅ CLEAR: No significant anomalies found.
- 40–70 → ⚠️ SUSPICIOUS: One or more anomalies detected. Review recommended.
- < 40 → 🚨 CRITICAL: Multiple strong indicators of AI generation or manipulation.
Text Analysis: ai_probability
The text engine returns an ai_probability score (0.0 = human, 1.0 = AI), powered by a fine-tuned RoBERTa classifier (Hello-SimpleAI/chatgpt-detector-roberta). A result > 60% is flagged as AI.
⚠️ Limitation: AI text detection is still an open research problem. Adversarial prompting (e.g., "rewrite this to sound more human"), paraphrasing tools, or fine-tuned models can evade any classifier. Treat the result as a signal to investigate further, not a verdict.
Flags Explained
| Flag | What it Means |
|---|---|
Biological Anomaly: Low/Zero Blink Rate |
A real human blinks 15–20 times per minute. AI-generated videos often have zero or near-zero blinks. |
Audio Anomaly: Synthetic Spectral Signature |
Real voices have natural variation and imperfections. Cloned voices are spectrally "too smooth." |
Metadata Trace: Missing C2PA/Digital Signature |
Authentic media from cameras/publishers carries a C2PA watermark. Its absence is a weak signal but worth flagging. |
🛠️ Troubleshooting
ReadTimeoutError during installation
Your network timed out while downloading a large file. Run with an extended timeout:
pip install --default-timeout=1000 "defakepy[full]"
dlib build failure on Windows
dlib requires CMake and a C++ compiler. Install CMake from cmake.org, select "Add CMake to the system PATH", restart your terminal, then try again.
ImportError: torch is not installed
You're using the text engine without installing the text extra. Fix:
pip install "defakepy[text]"
🤝 Contributing
Contributions are welcome! See CONTRIBUTING.md to get started.
📄 License
Distributed under the MIT License. See LICENSE for details.
Metadata
Release files for defakepy 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| defakepy-0.1.6.tar.gz | 14.0 kB | Without provenance | Details for defakepy-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| defakepy-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for defakepy-0.1.6-py3-none-any.whl |
Total release size: 27.1 kB
Release files / defakepy-0.1.6.tar.gz
| Download URL | defakepy-0.1.6.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d6db7be848f39155460c4c79775a36748107758f77bd6cfe22e6254fec67aad
|
|
BLAKE2b-256 checksum How to use checksums |
88b5319dddc6a691bc8ec01b83c97a843bd3ce8c5f44b8a10593e1cbb1d681ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / defakepy-0.1.6-py3-none-any.whl
| Download URL | defakepy-0.1.6-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38557b2c71049c0226a42c7481d9665182f10e550459f11072da22e72f4ca075
|
|
BLAKE2b-256 checksum How to use checksums |
ad3ec3f567ad252bc0e89048df20e7f12bc210dc451ea9932a7d0afc29d14ee2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Security for defakepy 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.