|
| 1 | +# VLM (Vision Language Model) Image Comparison |
| 2 | + |
| 3 | +AI-powered semantic image comparison using Vision Language Models via Ollama. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +### 1. Install & Start Ollama |
| 8 | + |
| 9 | +```bash |
| 10 | +# Install (macOS) |
| 11 | +brew install ollama |
| 12 | + |
| 13 | +# Start Ollama |
| 14 | +ollama serve |
| 15 | +``` |
| 16 | + |
| 17 | +### 2. Download a Model |
| 18 | + |
| 19 | +```bash |
| 20 | +# Recommended for accuracy |
| 21 | +ollama pull llava:7b |
| 22 | + |
| 23 | +# Or for speed (smaller, less accurate) |
| 24 | +ollama pull moondream |
| 25 | +``` |
| 26 | + |
| 27 | +### 3. Configure Backend |
| 28 | + |
| 29 | +Add to `.env`: |
| 30 | +```bash |
| 31 | +OLLAMA_BASE_URL=http://localhost:11434 |
| 32 | +``` |
| 33 | + |
| 34 | +### 4. Use VLM in Project |
| 35 | + |
| 36 | +Set project's image comparison to `vlm` with config: |
| 37 | +```json |
| 38 | +{ |
| 39 | + "model": "llava:7b", |
| 40 | + "temperature": 0.1 |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +Optional custom prompt: |
| 45 | +```json |
| 46 | +{ |
| 47 | + "model": "llava:7b", |
| 48 | + "prompt": "Focus on button colors and text changes", |
| 49 | + "temperature": 0.1 |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Recommended Models |
| 54 | + |
| 55 | +| Model | Size | Speed | Accuracy | Best For | |
| 56 | +|-------|------|-------|----------|----------| |
| 57 | +| `llava:7b` | 4.7GB | ⚡⚡ | ⭐⭐⭐ | **Recommended** - best balance | |
| 58 | +| `llava:13b` | 8GB | ⚡ | ⭐⭐⭐⭐ | Best accuracy | |
| 59 | +| `moondream` | 1.7GB | ⚡⚡⚡ | ⭐⭐ | Fast, may hallucinate | |
| 60 | +| `minicpm-v` | 5.5GB | ⚡⚡ | ⭐⭐⭐ | Good alternative | |
| 61 | + |
| 62 | +## Configuration |
| 63 | + |
| 64 | +| Option | Type | Default | Description | |
| 65 | +|--------|------|---------|-------------| |
| 66 | +| `model` | string | `moondream` | Ollama vision model name | |
| 67 | +| `prompt` | string | `""` | Custom context prepended to system prompt | |
| 68 | +| `temperature` | number | `0.1` | Lower = more consistent results | |
| 69 | + |
| 70 | +## How It Works |
| 71 | + |
| 72 | +1. VLM analyzes both images semantically |
| 73 | +2. Returns `YES` (pass) or `NO` (fail) based on meaningful differences |
| 74 | +3. Ignores technical differences (anti-aliasing, sub-pixel, minor spacing) |
| 75 | +4. Provides description of differences found |
| 76 | + |
| 77 | +## API Endpoints |
| 78 | + |
| 79 | +```bash |
| 80 | +# List available models |
| 81 | +GET /ollama/models |
| 82 | + |
| 83 | +# Compare two images (for testing) |
| 84 | +POST /ollama/compare?model=llava:7b&prompt=<prompt>&temperature=0.1 |
| 85 | +``` |
| 86 | + |
| 87 | +**Example:** |
| 88 | +```bash |
| 89 | +curl -X POST "http://localhost:3000/ollama/compare?model=llava:7b&prompt=Are%20these%20images%20the%20same&temperature=0.1" \ |
| 90 | + -F "images=@baseline.png" \ |
| 91 | + -F "images=@comparison.png" |
| 92 | +``` |
0 commit comments