Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

Repository files navigation

AI.VisualCompare

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.

⚠️ Experimental Project: This is an experimental project and the architecture may evolve over time. Contributions, ideas, and improvements are very welcome.

πŸš€ Features

  • 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

πŸ› οΈ Tech Stack

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

πŸ“‹ Prerequisites

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)

πŸš€ Quick Start

Option 1: One-Command Startup (Recommended) ⚑

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.sh

This 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:

Option 2: Manual Setup

If you prefer to set up services manually:

2.1 Backend Setup

# 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 8000

The backend API will be available at http://localhost:8000

2.2 Frontend Setup

# 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 dev

The frontend will be available at http://localhost:5173

πŸ“ Project Structure

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

πŸ”§ Configuration

Environment Variables

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.0

API Configuration

The backend provides the following endpoint:

  • POST /compare
    • Purpose: Compare two images using AI
    • Content-Type: multipart/form-data
    • Parameters:
      • base: First image file
      • comparison: Second image file
    • Response: JSON with AI analysis summary

πŸ§ͺ Testing

Backend Testing

cd backend
python test.py

Frontend Testing

cd image-compare-ui
yarn test
# or
npm test

�️ Code Quality & Linting

This project uses automated code quality tools to maintain consistent code standards.

Frontend (React/TypeScript)

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:check

Backend (Python)

cd backend

# Lint code
ruff check .

# Lint and auto-fix issues
ruff check . --fix

# Format code
black .

# Check formatting (no changes)
black --check .

Pre-commit Hooks

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-files

Pre-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

οΏ½πŸ”’ Security Considerations

⚠️ Important Security Notes:

  1. API Key Protection: Never commit your OpenAI API key to version control
  2. File Validation: The current implementation doesn't validate file types or sizes
  3. CORS Configuration: Currently allows all origins - configure for production
  4. Rate Limiting: Consider implementing rate limiting for production use

πŸš€ Deployment

Backend Deployment

For production deployment, consider:

  1. Environment Variables: Use proper environment management
  2. Process Manager: Use Gunicorn or similar for production
  3. Reverse Proxy: Use Nginx or Apache as reverse proxy
  4. HTTPS: Enable SSL/TLS encryption

Example with Gunicorn:

pip install gunicorn
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker

Frontend Deployment

cd image-compare-ui
yarn build
# or
npm run build

The built files will be in the dist/ directory, ready for deployment to any static hosting service.

🀝 Contributing

πŸŽ‰ Contributions Welcome! This is an experimental project and we welcome all kinds of contributions, from bug fixes to new features and documentation improvements.

How to Contribute

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

Development Guidelines

  • 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

Areas for Contribution

  • 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

Getting Help

  • Open an issue for bugs or feature requests
  • Join discussions in pull request comments
  • Check existing issues before creating new ones

πŸ› Known Issues

  1. File Cleanup: Temporary files may not be properly cleaned up in all scenarios
  2. Error Handling: Limited error handling for edge cases
  3. UI Responsiveness: Basic styling may not work well on all screen sizes
  4. API Rate Limits: No handling of OpenAI API rate limits

πŸ”§ Troubleshooting

Startup Script Issues

If you encounter problems with the start.sh script:

Permission Denied

chmod +x start.sh

Port Already in Use

# Check what's using the ports
lsof -i :8000
lsof -i :5173

# Kill the processes if needed
kill -9 <PID>

Python/Node.js Not Found

OpenAI API Key Issues

  1. Edit backend/.env
  2. Replace your_openai_api_key_here with your actual API key
  3. Restart the services

Dependencies Installation Fails

# 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

Script Hangs or Freezes

  • Press Ctrl+C to stop all services
  • Check if ports are available
  • Restart your terminal and try again

General Issues

Backend Won't Start

  • Check if virtual environment is activated
  • Verify OpenAI API key is set
  • Check port 8000 availability

Frontend Won't Start

  • Check if Node.js dependencies are installed
  • Verify port 5173 availability
  • Check for syntax errors in React components

API Connection Errors

πŸ“ TODO

βœ… Completed

  • 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

πŸ”„ In Progress / Planned

  • 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

πŸ“„ License

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

πŸ†˜ Support

If you encounter any issues or have questions:

  1. Check the Issues page for existing problems
  2. Create a new issue with detailed information
  3. Include error messages, steps to reproduce, and environment details

πŸ™ Acknowledgments

  • 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.

πŸ€– AI Provider Setup

This tool supports multiple AI providers for image comparison:

OpenAI GPT-4 Vision (Default - Paid)

  • Cost: $0.01-0.03 per image
  • Setup: Add your OpenAI API key to .env:
    OPENAI_API_KEY=your_openai_api_key_here
    

Google Gemini Pro Vision (Free)

  • Cost: Free - 1500 requests/day
  • Setup:
    1. Get a free API key from Google AI Studio
    2. Add to .env:
    GEMINI_API_KEY=your_gemini_api_key_here
    

Installation

Install the required dependencies:

cd backend
pip install google-generativeai

Usage

  • 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

Environment Variables

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.0

πŸ”„ API Endpoints

The 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 file
      • comparison: Second image file
      • instructions: 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 file
      • comparison: Second image file
      • instructions: 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages