Infinite Image Browsing (IIB)

repository·main·Indexed 20 days ago

https://github.com/zanllp/infinite-image-browsing

A high-performance image and video browser for AI-generated media supporting Stable Diffusion, ComfyUI, Fooocus, and NovelAI. It features semantic search, AI-powered organization (Smart Organize), and TikTok-style browsing. IIB can be installed as an SD-webui extension, a standalone Python program, a desktop application, or integrated as a library via iframe. It includes experimental natural language categorization and RAG-style search using OpenAI-compatible providers or TwelveLabs Marengo.

Tokens
21.8K
Snippets
32
Records
112
Agent score
78%

What's inside Infinite Image Browsing

  1. Understand Natural Language Search caching and incremental updates

    main

    To minimize costs and processing time, the system uses incremental updates and caching for embeddings and titles.

    1. Embedding Cache (image_embedding)

    Embeddings are stored in the image_embedding table keyed by image_id. An image is skipped during updates if it has the same model, same text_hash, and an existing vec is present.

    Re-vectorization logic: text_hash = sha256(f"{normalize_version}:{prompt_text}")

    • prompt_text: Extracted and optionally normalized text.
    • normalize_version: A code-derived fingerprint of the normalization rules used.

    To force a rebuild: Pass force=true to build_iib_output_embeddings or force_embed=true to cluster_iib_output_job_start.

    2. Title Cache (topic_title_cache)

    Titles and keywords are stored in the topic_title_cache table keyed by cluster_hash.

    Cache Hit Rule: When use_title_cache=true and force_title=false, titles are reused. The cluster_hash includes:

    • Member image IDs (sorted)
    • Embedding model, threshold, min_cluster_size
    • title_model, output lang
    • Normalization fingerprint (normalize_version) and mode

    To force regeneration: Pass force_title=true.

  2. Use Smart Organize for AI-powered file management

    main

    The Smart Organize feature uses AI to automatically group and rename images based on their content.

    Capabilities:

    • Semantic Clustering: Groups images using AI embeddings based on prompt semantics.
    • Auto-Generated Folder Names: Creates meaningful folder names in your preferred language.
    • Workflow: Allows you to preview the proposed organization before applying changes. You can choose to either move or copy files and set a minimum cluster size.

    Requirements: To use this feature, you must provide the following environment variables and have the required Python dependencies installed:

    • OPENAI_BASE_URL
    • OPENAI_API_KEY
    • Python packages: numpy, hnswlib.
  3. Performance tips for IIB operations

    main

    To optimize performance when using the IIB API:

    1. Limit scope: Use the folder_paths parameter to restrict searches to specific directories whenever possible.
    2. Use batch endpoints: For operations involving multiple items, prefer image_geninfo_batch and batch_update_image_tag over individual calls.
    3. Implement pagination: Always use pagination for large result sets to avoid heavy payloads.
    4. Targeted updates: Use update_image_data for specific folders instead of triggering a full rebuild_index.
  4. Optimize IIB performance with caching and CLI flags

    main

    To improve image loading speeds and performance, you can use the following methods:

    • Pre-generate assets: Use the CLI flags --generate_video_cover and --generate_image_cache to pre-generate thumbnails and video covers.
    • Custom Cache Directory: Specify a custom directory for cache files using the IIB_CACHE_DIR environment variable.
    • Thumbnail Settings: By default, IIB uses 512px thumbnails. You can adjust the thumbnail resolution in the Global Settings page and control the grid image width (range: 64px to 1024px).
  5. Configure TypeScript for .vue imports

    main

    Because TypeScript does not natively handle .vue imports, this project uses vue-tsc for type checking instead of tsc.

    To enable type awareness in your editor, you must use the TypeScript Vue Plugin (Volar). For better performance, you can enable Take Over Mode in Volar by following these steps:

    1. Disable the built-in TypeScript extension:
      • Open the VSCode command palette and run Extensions: Show Built-in Extensions.
      • Find TypeScript and JavaScript Language Features, right-click it, and select Disable (Workspace).
    2. Reload the VSCode window by running Developer: Reload Window from the command palette.
  6. Use IIB with AI Assistants

    main

    To use IIB with an AI assistant, follow these two steps:

    1. Start the IIB Service

    Run the IIB server on a specific port:

    python app.py --port <port>

    2. Interact with the AI

    Once the service is running, you can give the AI assistant natural language instructions for various tasks:

    Search & Filtering:

    • "Find all images with 'sunset' in the prompt"
    • "Show images generated using model X"
    • "Find images marked as 'favorite'"
    • "Search for high-quality landscape images"

    Tag Management:

    • "Tag these images as 'high-quality'"
    • "Remove the 'test' tag from all images"
    • "Add a 'portrait' tag to images containing people"

    File Organization:

    • "Organize my downloads folder by theme"
    • "Move all landscape images to a separate folder"

    Information Retrieval:

    • "Show the generation parameters for this image"
    • "What prompts were used for these images?"
    • "Compare the settings of these two images"
  7. Generate URL-encoded search queries for browsers

    main

    When generating URLs to open the Infinite Image Browsing interface in a user's browser, you must follow these encoding rules:

    1. JSON Props: The props parameter must be a URL-encoded JSON object.
    2. Non-ASCII characters: Characters like Chinese or Japanese must be UTF-8 percent-encoded within the JSON string.
    3. Regex Flag: To use regex in the UI via a URL, ensure the JSON object includes "isRegex":true.

    Encoding Reference:

    JSON PropsURL Encoded
    {"substr":"sunset"}%7B%22substr%22%3A%22sunset%22%7D
    {"substr":"(词1|词2)","isRegex":true}%7B%22substr%22%3A%22(%E8%AF%8D1%7C%E8%AF%8D2)%22%2C%22isRegex%22%3Atrue%7D
    {"substr":"a|b","isRegex":true}%7B%22substr%22%3A%22(a%7Cb)%22%2C%22isRegex%22%3Atrue%7D
  8. Install Infinite Image Browsing as an SD-WebUI Extension

    main

    To use IIB within the Stable Diffusion WebUI environment:

    1. Open the Extensions tab in SD-WebUI.
    2. Select the Install from URL option.
    3. Enter the following URL: https://github.com/zanllp/sd-webui-infinite-image-browsing.
    4. Click the Install button.
    5. Once installation is complete, click Apply and restart UI.
  9. Install Infinite Image Browsing (IIB) as a desktop application

    main

    For users who do not want to use SD-webui or Python, a compiled desktop application is available. This version also supports ComfyUI, Fooocus, and NovelAI.

    1. Go to the releases section of the repository.
    2. Download and install the appropriate version for your OS.

    Note: If your antivirus flags the executable, it is likely a false positive. For Windows users, the pyinstaller version typically has a lower false positive rate.

  10. Workflow: Organize a messy folder using AI

    main

    To automatically organize images into a destination folder using AI, follow this three-step process:

    1. Start organization: Call POST /db/organize_files_start. You must provide folder_paths, dest_folder, a similarity threshold, lang, and an action (e.g., move). This returns a job_id.
    2. Poll status: Use GET /db/organize_files_status?job_id=<job_id> to check the progress. Wait until the status is completed.
    3. Confirm execution: Once completed, call POST /db/organize_files_confirm with the job_id to finalize the changes.
    # 1. Start AI organization
    curl -X POST http://127.0.0.1:<port>/infinite_image_browsing/db/organize_files_start \
      -H "Content-Type: application/json" \
      -d '{
        "folder_paths": ["/Downloads/ai-images"],
        "dest_folder": "/Pictures/organized",
        "threshold": 0.85,
        "lang": "en",
        "action": "move"
      }'
    # Returns: {"job_id": "abc123"}
    
    # 2. Poll for completion
    curl "http://127.0.0.1:<port>/infinite_image_browsing/db/organize_files_status?job_id=abc123"
    # Wait until status is "completed"
    
    # 3. Confirm and execute
    curl -X POST http://127.0.0.1:<port>/infinite_image_browsing/db/organize_files_confirm \
      -H "Content-Type: application/json" \
      -d '{"job_id": "abc123"}'
  11. Workflow: Add a new folder to the library

    main

    To include a new directory in the IIB index, follow these steps:

    1. Add the path: Use POST /db/extra_paths with the path and desired types (e.g., ["scanned"]).
    2. Update image data: Trigger an index update for that specific folder using POST /db/update_image_data with the path.
    3. Verify: Search for images in that folder using POST /db/search_by_substr with the folder_paths parameter to ensure they are indexed.
    # 1. Add path
    curl -X POST http://127.0.0.1:<port>/infinite_image_browsing/db/extra_paths \
      -H "Content-Type: application/json" \
      -d '{"path": "/new/image/folder", "types": ["scanned"]}'
    
    # 2. Trigger index update
    curl -X POST http://127.0.0.1:<port>/infinite_image_browsing/db/update_image_data \
      -H "Content-Type: application/json" \
      -d '{"path": "/new/image/folder"}'
    
    # 3. Verify images are indexed
    curl -X POST http://127.0.0.1:<port>/infinite_image_browsing/db/search_by_substr \
      -H "Content-Type: application/json" \
      -d '{"surstr": "", "folder_paths": ["/new/image/folder"], "cursor": "", "size": 10}'