comfylib


Namecomfylib JSON
Version 0.0.5 PyPI version JSON
download
home_page
SummaryStable Diffusion library, based on the implementation in ComfyUI
upload_time2023-03-18 02:52:42
maintainer
docs_urlNone
authorcomfyanonymous
requires_python>=3.9
license
keywords stable diffusion
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # This is a work in progress

All the talk about having a reliable interface below is aspirational.  The
interface is in flux at the moment, and no guarantee of the master branch
working are made, yet.  Soon.

This was initially planned to be a fork of ComfyUI, with regular merges from
upstream.  However, we are quickly realizing that's impractical, given the
rapid development in the ComfyUI codebase.  So, this is a hard fork.  We will
make a strong effort to keep parity, but we will also be going our own way here
and the implementation will probably end up quite different.

----

This is the [ComfyUI](https://github.com/comfyanonymous/ComfyUI), but without
the UI.  It's stripped down and packaged as a library, for use in other projects.

ComfyUI is actively maintained (as of writing), and has implementations of a
lot of the cool cutting-edge Stable Diffusion stuff.

In order to provide a consistent API, an interface layer has
been added.  Directly importing names not in the API should be considered
dangerous.  A best effort will be made to keep this library apace with the
implementation in ComfyUI (though this will get harder over time as the
implemntations diverge) so the backend implementation might change drastically
between minor versions.

The interface layer will be consistent within a major version of the library,
so that's what you should rely on.

# Design goals

1. The API should expose the same breadth of functionality available by using
the node editor in ComfyUI.
2. Opaque types should be preferred.  Rather than pass tensors around, we're
going to wrap them in objects that hide the implementation.  This gives us
maximum flexibility to keep the API the same, while also incorporating new
developments.
3. Explicit behavior should be prferred over implicit behavior.  As a library,
we shouldn't make assumptions about how the user wants to, for example,
sanitize inputs or manage VRAM.  At the cost of requiring a bit more work to
use, we should raise exceptions when we get bad input, offer an interface for
moving things to and from VRAM, etc.
4. The API should be should be typed as strictly as possible.  Enums should be
used instead of strings, when applicable, etc.
5. The interface layer should have complete test coverage.

# Installation

You can install from github:

```
pip3 install git+https://github.com/adodge/ComfyLib
```

You may also be able to install from PyPi, but that process will be clarified
when this project is more stable.

# Example

```python3
import comfy.stable_diffusion
import comfy.latent_image

config = comfy.stable_diffusion.CheckpointConfig.from_built_in(comfy.stable_diffusion.BuiltInCheckpointConfigName.V1)

# Read in a checkpoint
sd, clip, vae = comfy.stable_diffusion.load_checkpoint(
    config=config,
    checkpoint_filepath="v1-5-pruned-emaonly.safetensors",
    embedding_directory=None,
)

# CLIP encode a prompt
pos = clip.encode("an astronaut")
neg = clip.encode("")

# Run the sampler
latent0 = comfy.latent_image.LatentImage.empty(512, 512)
latent1 = sd.sample(positive=pos, negative=neg, latent_image=latent0, seed=42, steps=20, cfg_strength=7,
                 sampler=comfy.stable_diffusion.Sampler.SAMPLE_EULER, scheduler=comfy.stable_diffusion.Scheduler.NORMAL,
                 denoise_strength=1.0)

# Run the VAE to get a Pillow Image
image = vae.decode(latent_image=latent1)

# Save that to a file
image.save("out.png")
```

# API

## Models

### StableDiffusionModel
### CLIPModel
### VAEModel

## Data

### RGBImage
### GreyscaleImage
### LatentImage
### Conditioning

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "comfylib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "stable diffusion",
    "author": "comfyanonymous",
    "author_email": "Alex Dodge <alexdodge@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ab/d8/d3055647259a9e166b2f3368753539822d4ee3e45b7cb53b0713a229bcee/comfylib-0.0.5.tar.gz",
    "platform": null,
    "description": "# This is a work in progress\n\nAll the talk about having a reliable interface below is aspirational.  The\ninterface is in flux at the moment, and no guarantee of the master branch\nworking are made, yet.  Soon.\n\nThis was initially planned to be a fork of ComfyUI, with regular merges from\nupstream.  However, we are quickly realizing that's impractical, given the\nrapid development in the ComfyUI codebase.  So, this is a hard fork.  We will\nmake a strong effort to keep parity, but we will also be going our own way here\nand the implementation will probably end up quite different.\n\n----\n\nThis is the [ComfyUI](https://github.com/comfyanonymous/ComfyUI), but without\nthe UI.  It's stripped down and packaged as a library, for use in other projects.\n\nComfyUI is actively maintained (as of writing), and has implementations of a\nlot of the cool cutting-edge Stable Diffusion stuff.\n\nIn order to provide a consistent API, an interface layer has\nbeen added.  Directly importing names not in the API should be considered\ndangerous.  A best effort will be made to keep this library apace with the\nimplementation in ComfyUI (though this will get harder over time as the\nimplemntations diverge) so the backend implementation might change drastically\nbetween minor versions.\n\nThe interface layer will be consistent within a major version of the library,\nso that's what you should rely on.\n\n# Design goals\n\n1. The API should expose the same breadth of functionality available by using\nthe node editor in ComfyUI.\n2. Opaque types should be preferred.  Rather than pass tensors around, we're\ngoing to wrap them in objects that hide the implementation.  This gives us\nmaximum flexibility to keep the API the same, while also incorporating new\ndevelopments.\n3. Explicit behavior should be prferred over implicit behavior.  As a library,\nwe shouldn't make assumptions about how the user wants to, for example,\nsanitize inputs or manage VRAM.  At the cost of requiring a bit more work to\nuse, we should raise exceptions when we get bad input, offer an interface for\nmoving things to and from VRAM, etc.\n4. The API should be should be typed as strictly as possible.  Enums should be\nused instead of strings, when applicable, etc.\n5. The interface layer should have complete test coverage.\n\n# Installation\n\nYou can install from github:\n\n```\npip3 install git+https://github.com/adodge/ComfyLib\n```\n\nYou may also be able to install from PyPi, but that process will be clarified\nwhen this project is more stable.\n\n# Example\n\n```python3\nimport comfy.stable_diffusion\nimport comfy.latent_image\n\nconfig = comfy.stable_diffusion.CheckpointConfig.from_built_in(comfy.stable_diffusion.BuiltInCheckpointConfigName.V1)\n\n# Read in a checkpoint\nsd, clip, vae = comfy.stable_diffusion.load_checkpoint(\n    config=config,\n    checkpoint_filepath=\"v1-5-pruned-emaonly.safetensors\",\n    embedding_directory=None,\n)\n\n# CLIP encode a prompt\npos = clip.encode(\"an astronaut\")\nneg = clip.encode(\"\")\n\n# Run the sampler\nlatent0 = comfy.latent_image.LatentImage.empty(512, 512)\nlatent1 = sd.sample(positive=pos, negative=neg, latent_image=latent0, seed=42, steps=20, cfg_strength=7,\n                 sampler=comfy.stable_diffusion.Sampler.SAMPLE_EULER, scheduler=comfy.stable_diffusion.Scheduler.NORMAL,\n                 denoise_strength=1.0)\n\n# Run the VAE to get a Pillow Image\nimage = vae.decode(latent_image=latent1)\n\n# Save that to a file\nimage.save(\"out.png\")\n```\n\n# API\n\n## Models\n\n### StableDiffusionModel\n### CLIPModel\n### VAEModel\n\n## Data\n\n### RGBImage\n### GreyscaleImage\n### LatentImage\n### Conditioning\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Stable Diffusion library, based on the implementation in ComfyUI",
    "version": "0.0.5",
    "split_keywords": [
        "stable",
        "diffusion"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "776456f0d85856bdf9ee6140cd37e9481b6ef0992b7511cd3b269747bcb40488",
                "md5": "0b25add840abe981863d65847afa5615",
                "sha256": "1099733efabfe296bf4651fa45901c26390e44111a1c031192b3fd2c8b617da6"
            },
            "downloads": -1,
            "filename": "comfylib-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b25add840abe981863d65847afa5615",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 724127,
            "upload_time": "2023-03-18T02:52:36",
            "upload_time_iso_8601": "2023-03-18T02:52:36.723475Z",
            "url": "https://files.pythonhosted.org/packages/77/64/56f0d85856bdf9ee6140cd37e9481b6ef0992b7511cd3b269747bcb40488/comfylib-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abd8d3055647259a9e166b2f3368753539822d4ee3e45b7cb53b0713a229bcee",
                "md5": "0301bba5df50d0901055a827fd9e4309",
                "sha256": "1aeced0621da732b7f1f42cc23438bf036814c0cd08c69d6765be33163371621"
            },
            "downloads": -1,
            "filename": "comfylib-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "0301bba5df50d0901055a827fd9e4309",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 679746,
            "upload_time": "2023-03-18T02:52:42",
            "upload_time_iso_8601": "2023-03-18T02:52:42.419228Z",
            "url": "https://files.pythonhosted.org/packages/ab/d8/d3055647259a9e166b2f3368753539822d4ee3e45b7cb53b0713a229bcee/comfylib-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-18 02:52:42",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "comfylib"
}
        
Elapsed time: 0.04469s