smart_asset_analyser 0.1.0 copy "smart_asset_analyser: ^0.1.0" to clipboard
smart_asset_analyser: ^0.1.0 copied to clipboard

A Flutter package to detect visually identical and similar assets using Deep Visual Embeddings (CLIP). Supports images, SVGs, and Lottie animations with interactive HTML reports.

Flutter Asset Analyser #

A powerful Flutter package that detects visually identical and similar assets in your Flutter project using Deep Visual Embeddings (CLIP).

Features #

  • 🔍 Deep Visual Embeddings: Uses CLIP model for accurate visual similarity detection
  • 🖼️ Multiple Asset Types: Supports images (PNG, JPG, WebP), SVGs, and Lottie JSON animations
  • 📊 Interactive HTML Report: Beautiful, filterable HTML report with similarity percentages
  • Fast Processing: Efficient batch processing with caching
  • 🎯 Configurable: Customizable similarity thresholds and filters

Quick Start #

1. Install Python Dependencies (One-time) #

cd /path/to/analyser
pip install -r requirements.txt

2. Add to Your Flutter Project #

Add to your Flutter project's pubspec.yaml:

dev_dependencies:
  analyser:
    path: /absolute/path/to/analyser

Then:

cd /path/to/your/flutter/project
flutter pub get

3. Run the Analyser #

dart run analyser:analyse assets

4. View Results #

Open asset_report.html in your browser!

Usage Examples #

# Basic analysis
dart run analyser:analyse assets

# Only images
dart run analyser:analyse assets --types images

# Higher similarity threshold
dart run analyser:analyse assets --threshold 0.95 --min-similarity 95

# Custom output location
dart run analyser:analyse assets --output reports/duplicates.html

# Exclude test assets
dart run analyser:analyse assets --exclude "**/test/**"

Command Options #

dart run analyser:analyse assets [options]

Options:
  --threshold <0.0-1.0>      Similarity threshold (default: 0.85)
  --min-similarity <0-100>    Minimum similarity percentage (default: 85)
  --output <path>             Output HTML file path (default: asset_report.html)
  --types <types>              Asset types: images,svgs,lottie (comma-separated, default: all)
  --exclude <pattern>          Exclude files matching pattern (glob)
  --project-path <path>        Flutter project path (default: current directory)
  --python-path <path>         Path to Python executable (default: python3)
  --use-server                 Use HTTP server mode for Python bridge (faster)
  --server-port <port>         HTTP server port (default: 8000)
  --cache-embeddings           Cache embeddings to disk (default: true)

How It Works #

  1. Asset Discovery: Scans pubspec.yaml and assets/ folders to find all assets
  2. Processing:
    • Images: Direct processing
    • SVGs: Rasterized to PNG images
    • Lottie: Key frames extracted and processed
  3. Embedding Generation: Uses CLIP model (via Python) to generate visual embeddings
  4. Similarity Calculation: Compares embeddings using cosine similarity
  5. Report Generation: Creates an interactive HTML report with filtering options

Report Features #

The generated HTML report includes:

  • Statistics Dashboard: Total assets, groups, pairs, potential savings
  • Interactive Filters:
    • Similarity percentage slider (0-100%)
    • Asset type filter (Images, SVGs, Lottie)
    • Search by filename
  • Visual Comparison: Side-by-side comparison with similarity percentage
  • Group View: All similar assets grouped together

Supported Asset Types #

  • Images: PNG, JPG, JPEG, WebP, GIF, BMP
  • SVGs: Scalable Vector Graphics (rasterized for comparison)
  • Lottie: JSON animation files (key frames extracted and averaged)

Prerequisites #

  • Python 3.8+ with pip
  • Dart SDK 3.0+
  • Flutter project with assets

Installation Details #

Python Dependencies #

The package requires:

  • torch - PyTorch for CLIP model
  • transformers or clip-by-openai - CLIP implementation
  • pillow - Image processing
  • cairosvg - SVG rasterization
  • python-lottie - Lottie frame extraction

Install with:

pip install -r requirements.txt

Note: First run will download CLIP model (~150MB) automatically.

Alternative: Direct Execution #

You can run without adding to pubspec.yaml:

cd /path/to/analyser
dart run bin/analyser.dart analyse assets --project-path /path/to/your/flutter/project

Troubleshooting #

Python Not Found #

dart run analyser:analyse assets --python-path /usr/local/bin/python3

Missing Dependencies #

pip install -r requirements.txt

CLIP Model Download Issues #

  • Check internet connection
  • Ensure sufficient disk space (~200MB)
  • Try running Python service manually to see detailed errors

Documentation #

  • QUICK_START.md - Quick setup guide
  • USAGE.md - Detailed usage instructions
  • EXAMPLE.md - Complete walkthrough example
  • SETUP.md - Detailed setup guide
  • IMPLEMENTATION_PLAN.md - Technical details

Performance Tips #

  1. Use Caching: Embeddings are cached by default for faster subsequent runs
  2. HTTP Server Mode: Use --use-server for large projects (keeps model in memory)
  3. Filter Types: Only analyze what you need with --types
  4. Exclude Patterns: Skip unnecessary files with --exclude

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

MIT License

1
likes
0
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package to detect visually identical and similar assets using Deep Visual Embeddings (CLIP). Supports images, SVGs, and Lottie animations with interactive HTML reports.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, collection, http, image, package_config, path, xml, yaml

More

Packages that depend on smart_asset_analyser