A full-stack web application that uses deep learning to distinguish between real photographs and AI-generated images. The application features a modern React frontend with drag-and-drop functionality and a Flask backend powered by a CNN model for accurate image classification.
- Drag & Drop Interface: Modern, intuitive file upload with drag-and-drop support
- Real-time Prediction: Instant classification of uploaded images
- Image Preview: Visual feedback showing the uploaded image before analysis
- High Accuracy Detection: CNN-based model trained to identify AI-generated content
- Responsive Design: Clean, modern UI that works across all devices
- Loading States: Visual feedback during image processing
- Error Handling: Graceful handling of upload errors and network issues
- Framework: React with TypeScript
- Styling: CSS3 with modern design principles
- State Management: React Hooks (useState, useRef)
- File Handling: FormData API for multipart uploads
- Framework: Flask (Python)
- Deep Learning: TensorFlow/Keras
- Image Processing: PIL (Python Imaging Library)
- Model: Custom CNN (Inception-based architecture)
- API: RESTful endpoints with CORS support
- Architecture: Convolutional Neural Network (CNN)
- Input Size: 224x224 RGB images
- Model File:
inception_model.keras - Training: Binary classification (Real vs AI-generated)
Before running the application, ensure you have:
- Python 3.8+ installed
- Required Python packages:
pip install flask tensorflow pillow flask-cors numpy
- Node.js 16+ and npm installed
- React development environment
- Pre-trained model file (
inception_model.keras) - Model should be placed in the backend directory
- Navigate to backend directory:
cd backend
- Install Python dependencies:
pip install flask tensorflow pillow flask-cors numpy
- Ensure model file is present:
- Place
inception_model.kerasin the backend root directory - Verify
predictImage.pyis configured correctly
- Start the Flask server:
python app.py
Application will be available on http://localhost:5173
- Access the Application:
- Open your browser and go to
http://localhost:5173 - Ensure both frontend and backend servers are running
- Upload an Image:
- Drag & Drop: Drag an image file directly onto the upload area
- Click to Select: Click the upload area to open file picker
- Supported Formats: JPG, JPEG, PNG, GIF
- Get Results:
- Click the "Check" button after uploading
- Wait for the analysis (loading indicator will show)
- View the result: "🧠 The image is AI generated" or "📷 The image is real"
- Frontend Upload: User selects/drops an image file
- File Validation: Client-side validation of file type and size
- API Request: FormData sent to Flask backend via POST request
- Image Preprocessing:
- Convert to RGB format using PIL
- Resize to 224x224 pixels (model input requirement)
- Normalize pixel values (0-1 range)
- Add batch dimension for model input
- CNN Inference: Inception-based model processes the image
- Binary Classification: Model outputs probability score (0-1)
- Result Interpretation:
- Score > 0.5: AI-generated image
- Score ≤ 0.5: Real image
- Response: JSON result sent back to frontend
- Architecture: Inception-based CNN
- Input Shape: (224, 224, 3) - RGB images
- Output: Single probability score (0-1)
- Training Data: Real images vs AI-generated images dataset
- Performance: Optimized for distinguishing modern AI-generated content
Input (224x224x3)
↓
Convolutional Layers (Feature Extraction)
↓
Global Average Pooling
↓
Dense Layers (Classification)
↓
Output (1 neuron, sigmoid activation)
ai-real-image-detector/
├── backend/
│ ├── app.py # Flask application
│ ├── predictImage.py # Image prediction logic
│ ├── inception_model.keras # Pre-trained CNN model
│ └── requirements.txt # Python dependencies
├── frontend/
│ ├── src/
│ │ ├── App.tsx # Main React component
│ │ ├── App.css # Styling
│ │ └── main.tsx # React entry point
│ ├── package.json # Node.js dependencies
│ └── vite.config.ts # Vite configuration
└── README.md # This file
- Description: Upload image for AI vs Real classification
- Content-Type: multipart/form-data
- Parameters:
file: Image file (JPG, PNG, etc.)
- Response:
{
"result": 0, // 0 for real, 1 for AI-generated
"confidence": 0.85
}
- TensorFlow/Keras for the deep learning framework
- React community for frontend development tools
- Flask for the lightweight backend framework
- PIL for efficient image processing
Note: Ensure both frontend and backend servers are running simultaneously for the application to function properly. The model file must be present in the backend directory before starting the server.