Skip to content

OwaisSafa/Image-Forensic

Repository files navigation

πŸ” Image Forensics Tool

A powerful, AI-driven image forensics analysis platform that combines state-of-the-art machine learning models to detect image tampering, AI-generated content, perform facial analysis, and enable reverse image search. Built with React frontend and Python FastAPI backend.

License Python React FastAPI

✨ Features

πŸ” Advanced Tamper Detection

  • TruFor Model: State-of-the-art image forgery detection
  • Detection Types: Copy-move, splicing, and other manipulations
  • Output: Integrity scores with confidence levels and localization maps

πŸ€– AI Generation Detection

  • SDXL Detector: Detects AI-generated images with high accuracy
  • Confidence Scoring: Provides generation probability scores
  • Model: Hugging Face Transformers-based detection

πŸ‘₯ Comprehensive Face Analysis

  • InsightFace Model: Advanced facial analysis capabilities
  • Features:
    • Age estimation with confidence scores
    • Gender detection
    • Facial keypoint detection (5-point landmarks)
    • Emotion analysis (happy/sad/neutral)
  • High Accuracy: Buffalo_L model for reliable results

πŸ“Š Metadata & EXIF Analysis

  • Complete Extraction: Camera settings, timestamps, GPS data
  • Smart Handling: Graceful handling of images without EXIF data
  • User Guidance: Helpful messages for images from social media/screenshots
  • Note: Many images from social media have EXIF data stripped for privacy

πŸ” Reverse Image Search

  • Multiple Engines: Google Lens, Bing, Yandex, TinEye
  • Dynamic URLs: Automatically adapts to any deployment environment
  • Public Access: Works with Cloudflare Tunnel and cloud providers

πŸ› οΈ Technology Stack

Frontend

  • React 18 with TypeScript
  • Vite for fast development and building
  • Tailwind CSS for modern, responsive design
  • Framer Motion for smooth animations
  • Lucide React for beautiful icons

Backend

  • Python 3.10+ with FastAPI
  • PyTorch for deep learning inference
  • OpenCV for image processing
  • NumPy for numerical computations
  • Uvicorn ASGI server

AI/ML Models

  • TruFor: Image forgery detection and localization
  • InsightFace: Face detection and analysis
  • SDXL Detector: AI generation detection
  • Custom Emotion Analysis: Keypoint-based facial expression analysis

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Git

Installation

  1. Clone the repository
git clone https://github.com/owaissafa/Image-Forensic.git
cd Image-Forensic
  1. Run the setup script
chmod +x setup.sh
./setup.sh

Note: The repository includes AI model files but not the virtual environment to keep the repository size manageable. Large model files are handled by Git LFS for efficient storage. The setup.sh script will create the virtual environment when you first run it. Some AI models like SDXL detector are downloaded automatically by their respective libraries on first use.

  1. Start the application
chmod +x start.sh
./start.sh

The setup script will automatically:

  • Install system dependencies
  • Set up Python virtual environment
  • Install backend requirements
  • Install frontend dependencies
  • Download and install Cloudflare Tunnel

🌐 Deployment Options

Local Development

  • Backend runs on http://localhost:8000
  • Frontend runs on http://localhost:5173
  • Automatic service discovery

Cloudflare Tunnel (Recommended)

  • Automatic Setup: Included in the start script
  • Public Access: Access from anywhere in the world
  • HTTPS: Secure connections automatically
  • Dynamic URLs: Automatically detects tunnel URLs

Manual Setup (Alternative)

# Backend setup
cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

# Frontend setup
cd ..
npm install

# Start services
cd backend && source venv/bin/activate && python app.py &
npm run dev &

πŸ“ Project Structure

Image-Forensic/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ api/                 # FastAPI routes
β”‚   β”œβ”€β”€ config/              # Configuration management
β”‚   β”œβ”€β”€ models/              # AI models and weights
β”‚   β”œβ”€β”€ services/            # Analysis services
β”‚   β”œβ”€β”€ utils/               # Utility functions
β”‚   └── app.py              # FastAPI application
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”œβ”€β”€ types/              # TypeScript definitions
β”‚   └── App.tsx            # Main application
β”œβ”€β”€ setup.sh               # One-time setup script
β”œβ”€β”€ start.sh               # Application startup script
└── README.md

πŸ”§ Configuration

Automatic Configuration

The system requires zero manual configuration for most deployments:

  • Local Development: Works automatically
  • Cloudflare Tunnel: Detects tunnel URLs from headers
  • Cloud Providers: Detects environment and gets public IP
  • Platform Deployments: Reads platform environment variables

Manual Override (Optional)

If needed, set environment variables:

# For custom domain
export PUBLIC_BASE_URL=https://yourdomain.com

# For Cloudflare Tunnel
export CLOUDFLARE_TUNNEL_URL=https://your-tunnel.trycloudflare.com

Backend Configuration

The backend automatically detects and uses:

  • GPU acceleration if available (CUDA)
  • CPU optimization with multi-threading
  • Model caching for faster inference
  • Dynamic public URLs for any deployment

🎯 Usage

  1. Upload an Image: Drag and drop or click to upload any image
  2. Automatic Analysis: The system will run all analysis types
  3. View Results: Check each tab for detailed results
  4. Reverse Search: Use the search engines to find similar images online

Analysis Types

  • Tamper Detection: Check for image manipulation
  • AI Detection: Determine if image is AI-generated
  • Face Analysis: Get age, gender, and emotion data
  • Metadata: View EXIF data and camera information
  • Reverse Search: Find similar images online

πŸ” Troubleshooting

Common Issues

EXIF Data Not Found

  • This is normal for images from social media or screenshots
  • Try uploading images directly from cameras for best results
  • The system provides helpful guidance messages

Frontend Not Loading

  • Check if port 5173 is available
  • The system automatically detects alternative ports
  • Ensure all dependencies are installed

Cloudflare Tunnel Issues

  • The tunnel is automatically configured in start.sh
  • Check the cloudflare.log for any errors
  • Ensure cloudflared is properly installed

Model Download Issues

  • Models are downloaded automatically on first use
  • Check internet connection for initial downloads
  • Models are cached locally for future use

System Requirements

Minimum

  • 4GB RAM
  • 2GB free disk space
  • Python 3.10+
  • Node.js 18+

Recommended

  • 8GB RAM
  • 5GB free disk space
  • GPU with CUDA support (optional)

Model Downloads

The following AI models are included in the repository:

  • TruFor: ~200MB - Included in repository
  • InsightFace: ~500MB - Included in repository

The following models are downloaded automatically on first use:

  • SDXL Detector: ~1.5GB - Downloaded by Hugging Face Transformers

Note: First-time setup may take 2-3 minutes depending on your internet connection.

Git LFS

This repository uses Git Large File Storage (LFS) to handle large AI model files efficiently. When cloning the repository, you may need to install Git LFS:

# Install Git LFS (if not already installed)
git lfs install

# Clone the repository
git clone https://github.com/owaissafa/Image-Forensic.git
cd Image-Forensic

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ€– AI-Assisted Development

This project was developed with significant assistance from AI tools:

  • Code Generation: AI helped generate boilerplate code, API endpoints, and React components
  • Debugging: AI assisted in identifying and fixing complex issues like Cloudflare tunnel configuration
  • Documentation: AI helped create comprehensive documentation and README files
  • Problem Solving: AI provided solutions for deployment challenges and system integration
  • Code Optimization: AI suggested improvements for performance and user experience

πŸ™ Acknowledgments

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section above
  2. Review the logs in the project directory
  3. Open an issue on GitHub with detailed information

Made with ❀️ by owaissafa

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published