MCPcopy
hub / github.com/jina-ai/discoart

github.com/jina-ai/discoart @v0.12.1 sqlite

repository ↗ · DeepWiki ↗ · release v0.12.1 ↗
115 symbols 496 edges 26 files 4 documented · 3%
README

Create compelling Disco Diffusion artworks in one line

PyPI Docker Cloud Build Status Open in Google Colab

DiscoArt is an elegant way of creating compelling Disco Diffusion[*] artworks for generative artists, AI enthusiasts and hard-core developers. DiscoArt has a modern & professional API with a beautiful codebase, ensuring high usability and maintainability. It introduces handy features such as result recovery and persistence, gRPC/HTTP serving w/o TLS, post-analysis, easing the integration to larger cross-modal or multi-modal applications.

[*] Disco Diffusion is a Google Colab Notebook that leverages CLIP-Guided Diffusion to allow one to create compelling and beautiful images from text prompts.

💯 Best-in-class: industry-level engineering, top-notch code quality, lean dependencies, small RAM/VRAM footprint; important bug fixes, feature improvements vs. the original DD5.6.

👼 Available to all: smooth install for self-hosting, Google Colab free tier, non-GUI (IPython) environment, and CLI! No brainfuck, no dependency hell, no stackoverflow.

🎨 Focus on create not code: one-liner create() with a Pythonic interface, autocompletion in IDE, and powerful features. Fetch real-time results anywhere anytime, no more worry on session outrage on Google Colab. Set initial state easily for more efficient parameter exploration.

🏭 Ready for integration & production: built on top of DocArray data structure, enjoy smooth integration with Jina, CLIP-as-service and other cross-/multi-modal applications.

☁️ As-a-service: simply python -m discoart serve, DiscoArt is now a high-performance low-latency service supports gRPC/HTTP/websockets and TLS. Scaling up/down is one-line; Cloud-native features e.g. Kubernetes, Prometheus and Grafana is one-line. Unbelievable simple thanks to Jina.

Gallery with prompts

Do you see the discoart-id in each tweet? To get the config & prompts, simply:

from discoart import show_config

show_config('discoart-id')

Install

Python 3.7+ and CUDA-enabled PyTorch is required.

pip install discoart

This applies to both self-hosting, Google Colab, system integration, non-GUI environments.

GUI

DiscoArt is the infrastructure for creating Disco Diffusion artworks. The built-in Jupyter Notebook support gives you basic yet limited user experience, e.g. it does not offer any intuitive GUI for prompt scheduling. Note that DiscoArt is developer-centric and API-first, hence improving consumer-facing experience is out of the scope. There are services, platforms and products (not Jina AI affiliated) that already integrate DiscoArt as a service and provide nice GUI on top of it, e.g. Fever Dreams, Replicate, RunPod and Renderflux.

Click to see third-party GUI

  • Fever Dreams: a free community-powered service with nice GUI and gallery, where people generate and share their DiscoArt artworks, prompts and configs.
  • Replicate: a free form-based GUI of DiscoArt with sandbox user experience and the visualizations.
  • RunPod: a paid GPU cloud provider that runs DiscoArt container with a simple and clean GUI to visualize the configs and creations.
  • Renderflux: a paid creative art platform that wraps DiscoArt and provides end-to-end GUI for creation management.

Please be aware that these platforms, products or companies are not affiliated with Jina AI. They define their own terms of services, paywall and data and privacy policies, which are not in the scope of DiscoArt MIT License.

Get Started

Open in Google Colab

Create artworks

from discoart import create

da = create()

That's it! It will create with the default text prompts and parameters.

Set prompts and parameters

Supported parameters are listed here. You can specify them in create():

from discoart import create

da = create(
    text_prompts='A painting of sea cliffs in a tumultuous storm, Trending on ArtStation.',
    init_image='https://d2vyhzeko0lke5.cloudfront.net/2f4f6dfa5a05e078469ebe57e77b72f0.png',
    skip_steps=100,
)

In case you forgot a parameter, just lookup the cheatsheet at anytime:

from discoart import cheatsheet

cheatsheet()

The difference on the parameters between DiscoArt and DD5.6 is explained here.

Visualize results

Final results and intermediate results are created under the current working directory, i.e.

./{name-docarray}/{i}-done.png
./{name-docarray}/{i}-step-{j}.png
./{name-docarray}/{i}-progress.png
./{name-docarray}/{i}-progress.gif
./{name-docarray}/da.protobuf.lz4

where:

  • name-docarray is the name of the run, you can specify it otherwise it is a random name.
  • i-* is up to the value of n_batches.
  • *-done-* is the final image on done.
  • *-step-* is the intermediate image at certain step, updated in real-time.
  • *-progress.png is the sprite image of all intermediate results so far, updated in real-time.
  • *-progress.gif is the animated gif of all intermediate results so far, updated in real-time.
  • da.protobuf.lz4 is the compressed protobuf of all intermediate results so far, updated in real-time.

The save frequency is controlled by save_rate.

Moreover, create() returns da, a DocumentArray-type object. It contains the following information: - All arguments passed to create() function, including seed, text prompts and model parameters. - 4 generated image and its intermediate steps' images, where 4 is determined by n_batches and is the default value.

This allows you to further post-process, analyze, export the results with powerful DocArray API.

Images are stored as Data URI in .uri, to save the first image as a local file:

da[0].save_uri_to_file('discoart-result.png')

To save all final images:

for idx, d in enumerate(da):
    d.save_uri_to_file(f'discoart-result-{idx}.png')

You can also display all four final images in a grid:

da.plot_image_sprites(skip_empty=True, show_index=True, keep_aspect_ratio=True)

Or display them one by one:

for d in da:
    d.display()

Or take one particular run:

da[0].display()

Visualize intermediate steps

You can also zoom into a run (say the first run) and check out intermediate steps:

da[0].chunks.plot_image_sprites(
    skip_empty=True, show_index=True, keep_aspect_ratio=True
)

You can .display() the chunks one by one, or save one via .save_uri_to_file(), or save all intermediate steps as a GIF:

da[0].chunks.save_gif(
    'lighthouse.gif', show_index=True, inline_display=True, size_ratio=0.5
)

Note that >=0.7.14, a 20FPS gif is generated which includes all intermedidate steps.

Show/save/load configs

To show the config of a Document/DocumentArray,

from discoart import show_config

show_config(da)  # show the config of the first run
show_config(da[3])  # show the config of the fourth run
show_config(
    'discoart-06030a0198843332edc554ffebfbf288'
)  # show the config of the run with a known DocArray ID

To save the config of a Document/DocumentArray,

from discoart import save_config

save_config(da, 'my.yml')  # save the config of the first run
save_config(da[3], 'my.yml')  # save the config of the fourth run

To run create from a YAML config of Document/DocumentArray,

from discoart import create, load_config

config = load_config('my.yml')
create(**config)

You can also export the config as an SVG image:

from discoart.config import save_config_svg

save_config_svg(da)

One can also generate runnable Python code directly from the config:

from discoart.config import export_python

export_python(da)

Pull results anywhere anytime

If you are a free-tier Google Colab user, one annoy thing is the lost of sessions from time to time. Or sometimes you just early stop the run as the first image is not good enough, and a keyboard interrupt will prevent .create() to return any result. Either case, you can easily recover the results by pulling the last session ID.

  1. Find the session ID. It appears on top of the image.

  2. Pull the result via that ID on any machine at any time, not necessarily on Google Colab: ```python from docarray import DocumentArray

    da = DocumentArray.pull('discoart-3205998582') ```

Reuse a Document as initial state

Consider a Document as a self-contained data with config and image, one can use it as the initial state for the future run. Its .tags will be used as the initial parameters; .uri if presented will be used as the initial image.

from discoart import create
from docarray import DocumentArray

da = DocumentArray.pull('discoart-3205998582')

create(
    init_document=da[0],
    cut_ic_pow=0.5,
    tv_scale=600,
    cut_overview='[12]*1000',
    cut_innercut='[12]*1000',
    use_secondary_model=False,
)

If you just want to initialize from a known DocArray ID, then simply:

from discoart import create

create(init_document='discoart-3205998582')

Environment variables

You can set environment variables to control the meta-behavior of DiscoArt. The environment variables must be set before importing DiscoArt, either in Bash or in Python via os.environ.

DISCOART_LOG_LEVEL='DEBUG' # more verbose logs
DISCOART_OPTOUT_CLOUD_BACKUP='1' # opt-out from cloud backup
DISCOART_DISABLE_IPYTHON='1' # disable ipython dependency
DISCOART_DISABLE_RESULT_SUMMARY='1' # disable result summary after the run ends
DISCOART_DEFAULT_PARAMETERS_YAML='path/to/your-default.yml' # use a custom default parameters file
DISCOART_CUT_SCHEDULES_YAML='path/to/your-schedules.yml' # use a custom cut schedules file
DISCOART_MODELS_YAML='path/to/your-models.yml' # use a custom list of models file
DISCOART_OUTPUT_DIR='path/to/your-output-dir' # use a custom output directory for all images and results
DISCOART_CACHE_DIR='path/to/your-cache-dir' # use a custom cache directory for models and downloads
DISCOART_DISABLE_REMOTE_MODELS='1' # disable the listing of diffusion models on Github, remote diffusion models allows user to use latest models without updating the codebase.
DISCOART_REMOTE_MODELS_URL='https://yourdomain/models.yml' # use a custom remote URL for fetching models list
DISCOART_DISABLE_CHECK_MODEL_SHA='1' # disable checking local model SHA matches the remote model SHA
DISCOART_DISABLE_TQDM='1' # disable tqdm progress bar on diffusion

CLI

DiscoArt provides two commands create and config that allows you to run DiscoArt from CLI.

python -m discoart create my.yml

which creates artworks from the YAML config file my.yml. You can also do:

cat config.yml | python -m discoart create

So how can I have my own my.yml and what does it look like? That's the second command:

python -m discoart config my.yml

which forks the default YAML config and export them to my.yml. Now you can modify it and run it with python -m discoart create command.

If no output path is specified, then python -m discoart config will print the default config to stdout.

To get help on a command, add --help at the end, e.g.:

python -m discoart create --help

```text usage: python -m discoart create [-h] [YAML_CONFIG_FILE]

positional arguments: YAML_CONFIG_FILE The YAML config file to use, default is stdin.

optional arguments: -h, --help show this hel

Core symbols most depended-on inside this repo

get_prompt_ids
called by 17
discoart/prompt.py
_eval_scheduling_str
called by 12
discoart/helper.py
load_config
called by 10
discoart/config.py
get_output_dir
called by 6
discoart/helper.py
create_perlin_noise
called by 6
discoart/nn/perlin_noises.py
detach_gpu
called by 6
discoart/nn/helper.py
print_args_table
called by 4
discoart/config.py
_extract_config_from_docs
called by 4
discoart/config.py

Shape

Function 82
Method 22
Class 11

Languages

Python100%

Modules by API surface

discoart/helper.py31 symbols
discoart/nn/sec_diff.py16 symbols
discoart/config.py8 symbols
discoart/persist.py7 symbols
discoart/executors.py7 symbols
tests/test_config.py6 symbols
tests/test_prompts.py5 symbols
discoart/nn/perlin_noises.py5 symbols
tests/test_api.py4 symbols
discoart/prompt.py4 symbols
discoart/nn/make_cutouts.py4 symbols
tests/conftest.py3 symbols

For agents

$ claude mcp add discoart \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact