Author: Mehmet Serhat Ozdursun
A modern web application for AI-powered visual comparison of images using multiple AI engines including OpenAI GPT-4 Vision, Google Gemini, and OpenCV. This tool helps QA engineers and developers quickly identify visual differences between two images while intelligently filtering out dynamic content.
- AI-Powered Comparison: Uses OpenAI GPT-4 Vision API for intelligent image analysis
- Dynamic Content Filtering: Automatically ignores changes in dates, prices, product names, and screen sizes
- Modern Web Interface: Built with React 19, TypeScript, and Vite
- FastAPI Backend: High-performance Python backend with async support
- Real-time Processing: Immediate feedback with loading states
- Cross-Platform: Works on any modern web browser
| Component | Technology | Purpose |
|---|---|---|
| Frontend | React 19 + TypeScript + Vite | Modern, fast web interface |
| Backend | FastAPI + Python 3.11+ | High-performance API server |
| AI Engine | OpenAI GPT-4 Vision API | Intelligent image comparison |
| Styling | CSS3 | Clean, responsive design |
| HTTP Client | Axios | Reliable API communication |
Before you begin, ensure you have the following installed:
- Python 3.11 or higher
- Node.js 18 or higher
- Yarn or npm package manager
- OpenAI API Key (required for image comparison)
The easiest way to get started is using our automated startup script:
# Clone the repository
git clone <your-repository-url>
cd AI.VisualCompare
# Make the startup script executable (first time only)
chmod +x start.sh
# Start both backend and frontend with one command
./start.shThis script will:
- β Check all prerequisites (Python, Node.js, etc.)
- β Create virtual environment and install dependencies
- β Set up environment variables automatically
- β Start both backend API and frontend website
- β Provide colored status messages
- β Handle graceful shutdown with Ctrl+C
Services will be available at:
- π Frontend: http://localhost:5173
- π‘ Backend API: http://localhost:8000
- π API Documentation: http://localhost:8000/docs
If you prefer to set up services manually:
# Navigate to backend directory
cd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
# Create a .env file in the backend directory
echo "OPENAI_API_KEY=your_openai_api_key_here" > .env
echo "PORT=8000" >> .env
# Start the backend server
uvicorn main:app --reload --port 8000The backend API will be available at http://localhost:8000
# Open a new terminal and navigate to frontend directory
cd image-compare-ui
# Install dependencies
yarn install
# or
npm install
# Start the development server
yarn dev
# or
npm run devThe frontend will be available at http://localhost:5173
AI.VisualCompare/
βββ backend/
β βββ main.py # FastAPI application entry point
β βββ compare.py # Image comparison logic using OpenAI
β βββ requirements.txt # Python dependencies
β βββ test.py # Basic test file
β βββ .env # Environment variables (auto-created)
β βββ venv/ # Python virtual environment (auto-created)
βββ image-compare-ui/
β βββ src/
β β βββ components/
β β β βββ ImageUploader.tsx # Main upload component
β β βββ App.tsx # Main application component
β β βββ App.css # Application styles
β β βββ main.tsx # Application entry point
β βββ public/ # Static assets
β βββ package.json # Node.js dependencies
β βββ vite.config.ts # Vite configuration
βββ start.sh # π One-command startup script
βββ README.md # This file
Create a .env file in the backend/ directory:
# Required: Your OpenAI API key
OPENAI_API_KEY=sk-your-openai-api-key-here
# Optional: Server configuration
PORT=8000
HOST=0.0.0.0The backend provides the following endpoint:
- POST
/compare- Purpose: Compare two images using AI
- Content-Type:
multipart/form-data - Parameters:
base: First image filecomparison: Second image file
- Response: JSON with AI analysis summary
cd backend
python test.pycd image-compare-ui
yarn test
# or
npm testThis project uses automated code quality tools to maintain consistent code standards.
cd image-compare-ui
# Lint code
yarn lint
# Lint and auto-fix issues
yarn lint:fix
# Format code
yarn format
# Check formatting (no changes)
yarn format:checkcd backend
# Lint code
ruff check .
# Lint and auto-fix issues
ruff check . --fix
# Format code
black .
# Check formatting (no changes)
black --check .To ensure code quality before commits, install pre-commit hooks:
# Install pre-commit (one-time setup)
pip install pre-commit
# Install hooks in the repository
pre-commit install
# Run hooks on all files
pre-commit run --all-filesPre-commit hooks will automatically:
- Remove trailing whitespace
- Format Python code with Black
- Lint Python code with Ruff
- Lint and format frontend code with ESLint and Prettier
- API Key Protection: Never commit your OpenAI API key to version control
- File Validation: The current implementation doesn't validate file types or sizes
- CORS Configuration: Currently allows all origins - configure for production
- Rate Limiting: Consider implementing rate limiting for production use
For production deployment, consider:
- Environment Variables: Use proper environment management
- Process Manager: Use Gunicorn or similar for production
- Reverse Proxy: Use Nginx or Apache as reverse proxy
- HTTPS: Enable SSL/TLS encryption
Example with Gunicorn:
pip install gunicorn
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorkercd image-compare-ui
yarn build
# or
npm run buildThe built files will be in the dist/ directory, ready for deployment to any static hosting service.
π Contributions Welcome! This is an experimental project and we welcome all kinds of contributions, from bug fixes to new features and documentation improvements.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Code Quality: Run linting and formatting before committing (see Code Quality & Linting)
- Follow TypeScript best practices
- Add proper error handling
- Include tests for new features
- Update documentation as needed
- Use meaningful commit messages
- New AI Engines: Add support for additional AI providers (Claude, DALL-E, etc.)
- UI Improvements: Enhance the user interface and user experience
- Performance: Optimize image processing and API calls
- Testing: Add comprehensive test coverage
- Documentation: Improve setup instructions and API documentation
- Bug Fixes: Report and fix any issues you encounter
- Open an issue for bugs or feature requests
- Join discussions in pull request comments
- Check existing issues before creating new ones
- File Cleanup: Temporary files may not be properly cleaned up in all scenarios
- Error Handling: Limited error handling for edge cases
- UI Responsiveness: Basic styling may not work well on all screen sizes
- API Rate Limits: No handling of OpenAI API rate limits
If you encounter problems with the start.sh script:
chmod +x start.sh# Check what's using the ports
lsof -i :8000
lsof -i :5173
# Kill the processes if needed
kill -9 <PID>- Install Python 3.11+ from python.org
- Install Node.js 18+ from nodejs.org
- Edit
backend/.env - Replace
your_openai_api_key_herewith your actual API key - Restart the services
# For backend issues
cd backend
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
# For frontend issues
cd image-compare-ui
rm -rf node_modules package-lock.json
npm install
# or
yarn install- Press
Ctrl+Cto stop all services - Check if ports are available
- Restart your terminal and try again
- Check if virtual environment is activated
- Verify OpenAI API key is set
- Check port 8000 availability
- Check if Node.js dependencies are installed
- Verify port 5173 availability
- Check for syntax errors in React components
- Ensure backend is running on port 8000
- Check CORS configuration
- Verify API URL in frontend (default: http://localhost:8000)
- Add comprehensive error handling
- Implement file type and size validation
- Add progress indicators
- Improve UI/UX design
- Add one-command startup script
- Implement proper environment configuration
- Add image preview functionality
- Implement drag-and-drop upload
- Add comprehensive test coverage
- Implement proper CORS configuration
- Add Docker support
- Implement rate limiting
- Add image history/management
- Implement user authentication
- Add Windows batch script (.bat) for startup
- Add automated testing pipeline
- Implement image caching
- Add batch image comparison
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the Issues page for existing problems
- Create a new issue with detailed information
- Include error messages, steps to reproduce, and environment details
- OpenAI for providing the GPT-4 Vision API
- FastAPI team for the excellent web framework
- React team for the amazing frontend library
- Vite team for the fast build tool
Note: This tool is designed for QA and development purposes. Always respect image copyright and usage rights when comparing images.
This tool supports multiple AI providers for image comparison:
- Cost: $0.01-0.03 per image
- Setup: Add your OpenAI API key to
.env:OPENAI_API_KEY=your_openai_api_key_here
- Cost: Free - 1500 requests/day
- Setup:
- Get a free API key from Google AI Studio
- Add to
.env:
GEMINI_API_KEY=your_gemini_api_key_here
Install the required dependencies:
cd backend
pip install google-generativeai- Default: Uses OpenAI GPT-4 Vision
- Free Option: Select "Google Gemini Pro Vision" in the UI
- Both providers offer similar quality analysis with different pricing models
Update your .env file to include both API keys:
# OpenAI (Paid)
OPENAI_API_KEY=your_openai_api_key_here
# Google Gemini (Free)
GEMINI_API_KEY=your_gemini_api_key_here
# Optional: Server configuration
PORT=8000
HOST=0.0.0.0The backend provides the following endpoints:
-
POST
/compare(OpenAI)- Purpose: Compare two images using OpenAI GPT-4 Vision
- Content-Type:
multipart/form-data - Parameters:
base: First image filecomparison: Second image fileinstructions: Optional custom instructions
- Response: JSON with AI analysis summary
-
POST
/compare-gemini(Google Gemini)- Purpose: Compare two images using Google Gemini Pro Vision
- Content-Type:
multipart/form-data - Parameters:
base: First image filecomparison: Second image fileinstructions: Optional custom instructions
- Response: JSON with AI analysis summary
-
GET
/health- Purpose: Check API health and provider configuration
- Response: JSON with status and provider availability