File size: 4,209 Bytes
8aeaa33 e14270b 8aeaa33 b60df97 8aeaa33 e14270b 8aeaa33 e14270b 8aeaa33 e14270b 8aeaa33 e14270b 8aeaa33 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | # π Forensic Image Analysis Agent
AI-powered forensic image analysis system that detects AI-generated, manipulated, or deepfake images using vision-capable LLMs and forensic tools.
## π Features
- **Vision Analysis**: Direct image analysis using GPT-5
- **Forensic Tools**: Multiple forensic analysis tools including:
- JPEG compression analysis
- Frequency domain analysis (DCT/FFT)
- Denoiser residual statistics
- Error Level Analysis (ELA)
- TruFor AI-driven forgery detection
- Camera fingerprint extraction (noiseprint)
- **Streaming Output**: Real-time analysis updates
- **Transparent Reasoning**: Detailed explanations of findings
## π Setup for Hugging Face Spaces
### 1. Create a New Space
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
2. Click "Create new Space"
3. Choose:
- **SDK**: Gradio
- **Hardware**: CPU (or GPU if you need faster inference)
- **Visibility**: Public or Private
### 2. Upload Files
Upload these files to your Space:
- `app.py` (main Gradio application)
- `requirements_hf.txt` β copy/rename to `requirements.txt` (HF Spaces compatible dependencies)
- `README.md` (this file)
- `src/` directory (your source code)
- `weights/` directory (optional - TruFor weights will auto-download on first use)
- `example_images/` directory (optional, for examples)
**Note**: TruFor model weights (~500MB) will be automatically downloaded on first use. You can optionally pre-upload them to `weights/trufor/trufor.pth.tar` to skip the download.
### 3. Set API Key
1. Go to your Space settings
2. Navigate to "Variables and secrets"
3. Add a new secret:
- **Name**: `OPENAI_API_KEY`
- **Value**: Your OpenAI API key
### 4. Configure Space
Create or update `.env` file (optional, API key should be set via HF Secrets):
```
OPENAI_API_KEY=your-key-here
```
## π― Usage
1. **Upload an Image**: Click the image upload area or drag & drop an image
2. **Optional Query**: Add a specific question about the image (e.g., "Is this AI-generated?")
3. **Configure Settings**:
- Enable/disable forensic tools
- Choose LLM model (gpt-5.1 recommended)
- Adjust temperature
4. **Analyze**: Click "π Analyze Image" button
5. **View Results**: See detailed analysis with visual description, forensic findings, and conclusion
## βοΈ Configuration
### Models Supported
- `gpt-5.1` (recommended) - Latest vision model
- `gpt-5` - Standard GPT-5
- `gpt-5-mini` - Faster, more cost-effective
- `gpt-5-nano` - Lightweight option
### Forensic Tools
When enabled, the agent can use:
- **analyze_jpeg_compression**: Analyzes JPEG compression artifacts
- **analyze_frequency_domain**: DCT/FFT frequency analysis
- **extract_residuals**: Denoiser residual statistics
- **perform_ela**: Error Level Analysis
- **perform_trufor**: AI-driven forgery detection
- **extract_noiseprint**: Camera fingerprint extraction
- **execute_python_code**: Custom Python analysis
## π Project Structure
```
.
βββ app.py # Gradio UI application
βββ app_requirements.txt # Dependencies for HF Spaces
βββ README.md # This file
βββ src/
β βββ agents/
β β βββ forensic_agent.py
β βββ tools/
β βββ forensic_tools.py
βββ weights/ # Model weights (if any)
```
## π Privacy & Security
- Images are processed temporarily and deleted after analysis
- API keys are stored securely via Hugging Face Secrets
- No data is stored permanently
## π Troubleshooting
### API Key Issues
- Ensure `OPENAI_API_KEY` is set in Space Secrets
- Check that your API key is valid and has credits
### Model Loading Issues
- For TruFor, ensure model weights are in `weights/trufor/`
- Check that all dependencies are installed correctly
### Memory Issues
- Use `gpt-5-mini` for lower memory usage
- Disable forensic tools if running on CPU-only hardware
## π License
[Add your license here]
## π Acknowledgments
- Built with [LangChain](https://www.langchain.com/) and [LangGraph](https://github.com/langchain-ai/langgraph)
- Powered by [OpenAI GPT-5](https://openai.com/)
- UI built with [Gradio](https://www.gradio.app/)
|