space-nuko / sd-model-manager

GNU General Public License v3.0
9 stars 2 forks source link

sd-model-manager

A desktop application and companion web server for browsing and managing Stable Diffusion models (embeddings, LoRAs, etc.) and their metadata.

Can be used standalone with the included frontend, embedded into ComfyUI for use with their ecosystem, or repurposed as an independent API server.

NOTE: Still alpha-quality for the time being, please back up your data frequently!

Features

Display all your models with thumbnails in a gallery view:

Screenshot

Search and browse a list of all your models with metadata:

Screenshot

Generate new previews for your models from within the GUI:

Screenshot

NOTE: To generate previews from the GUI, you should have an instance of ComfyUI running in the backend. To be able to show ComfyUI generation previews in the popup, start the ComfyUI server with the argument --preview-method auto.

Installation

First install the requirements:

# Required
pip install -r requirements/gui.txt

# Optional, if developing
pip install -r requirements/development.txt

Next edit config.yml to contain your model paths:

listen: 0.0.0.0
port: 7779
model-paths:
  - "C:/path/to/loras"

Then the built-in GUI can be run as follows:

python client.py

To run the API server standalone with hot reloading:

adev runserver -p 7779 main.py

Your model metadata will be saved to model_database.db in case you want to backup/inspect it.

ComfyUI Extension

You can use this repo as a ComfyUI extension to embed the server into its existing API. Simply clone/move this repo into the custom_nodes folder of your ComfyUI installation, install the requirements into your virtualenv, then start ComfyUI as usual.

cd /c/ComfyUI

# be sure to activate your ComfyUI virtualenv before installing requirements 
source venv/Scripts/activate

git clone https://github.com/space-nuko/sd-model-manager custom_nodes/sd-model-manager
pushd custom_nodes/sd-model-manager
pip install -r requirements/gui.txt
popd

python main.py --preview-method auto

To connect to the model management server when it's running under ComfyUI, use this command:

python client.py --mode comfyui

NOTE: In this mode, all API routes will be moved under a models/ namespace, like http://localhost:8188/models/api/v1/loras.

Usage

Search Query Syntax

When searching for models, you can use some special syntax to filter your results.

Basic Searches

An unqualified search term like some text will search for the text in the model's name or filepath.

You can search by a fuzzy value with qualifiers like id:123 or name:"detailed lighting".

Additionally, for numeric queries you can use comparison operators like rating:>=7. The full list of operators:

Any search qualifier can be negated by prepending - to the front: -name:"bad quality"

Some criteria can also be used with the has: qualifier to check for existence of the field: has:image

List of Qualifiers

Strings:

Numbers:

Has:

Ordering

You can sort the results returned from the database with the order: qualifier: order:rating

To reverse the order: order:reverse:rating

List of Ordering Types

API Reference

The following examples assume standalone mode with the default configuration (port 7779). If running the server with the ComfyUI integration, prepend /models to all routes.

GET /api/v1/loras

List all LoRAs.

Query Parameters

Example

GET http://localhost:7779/api/v1/loras?limit=10
{
  "paging": {
    "next": ">",
    "current": ">",
    "previous": "<",
    "limit": 1
  },
  "data": [
    {
      "id": 1,
      "name": "Test LoRA",
      "author": "space-nuko",
      "network_module": "networks.lora",
      "learning_rate": 0.0001
      "text_encoder_lr": 0.00005
      "unet_lr": 0.00005
      // ...
    }
  ]
}

GET /api/v1/lora/{id}

Get information for one LoRA.

Query Parameters

(None)

Example

GET http://localhost:7779/api/v1/lora/1
{
  "data": {
    "id": 1,
    "name": "Test LoRA",
    "author": "space-nuko",
    "network_module": "networks.lora",
    "learning_rate": 0.0001
    "text_encoder_lr": 0.00005
    "unet_lr": 0.00005
    // ...
  }
}

PATCH /api/v1/lora/{id}

Update information for one LoRA.

Body Parameters

Example

PATCH http://localhost:7779/api/v1/lora/1
{
  "changes": {
    "display_name": "New Name",
    "version": "V2",
    "rating": 5,
    "preview_images": [
      {
        "filepath": "C:/path/to/image.png"
      }
    ]
  }
}
{
  "status": "ok",
  "fields_updated": 4
}

GET /api/v1/preview_image/{id}

Get information for one preview image.

Query Parameters

(None)

Example

GET http://localhost:7779/api/v1/preview_image/1
{
  "data": {
    "id": 1,
    "filepath": "C:/path/to/image.png",
    "is_autogenerated": false
  }
}

GET /api/v1/preview_image/{id}/view

Download the image file represented by a preview image.

Query Parameters

(None)

Example

GET http://localhost:7779/api/v1/preview_image/1/view
<binary data>