example directory

Requirements

Requires the “NAI_USERNAME” and “NAI_PASSWORD” values provided via environment variables. They can be provided through a .env file at the root of the project.

The “NAI_PROXY” environment variable is also supported to inject a proxy address.

Usage

If you have the novelai-api package installed via pip :

python example/<filename>

If you don’t have the novelai-api package installed, or you’re actively developing on the project :

poetry run python example/<filename>

Remember to run poetry install before running the example, if not already done.

Content

download_modules.py

Example of how to download and decrypt modules from the provided account

download_presets.py

Example of how to download and decompress shelves from the provided account

download_shelves.py

Example of how to download and decompress shelves from the provided account

download_stories_and_content.py

Example of how to download and decrypt stories from the provided account

generate_controlnet_masks.py

Example of how to query the controlnet masks for an image

It expects an image “results/image.png” to exist and will generate the resulting masks in this same folder
NOTE: Currently the returned mask is wrong due to an image conversion in frontend (see [issue 15])

generate_image.py

Example of how to generate an image

The resulting images will be placed in a folder named “results”

generate_image_test_samplers.py

Test on which sampler currently work. It will create one image per sampler

The resulting images will be placed in a folder named “results”

generate_image_with_controlnet.py

Example of how to generate an image with a Control Net

The resulting image will be placed in a folder named “results”
NOTE: Currently the returned mask is wrong due to an image conversion in frontend (see [issue 15])

generate_image_with_img2img.py

Example of how to generate an image with img2img

The resulting image will be placed in a folder named “results”

generate_text.py

Example of how to generate a text

The resulting text will be directed to the standard error output (stderr)

generate_voice.py

Example of how to generate a voice (TTS - Text To Speech)

The resulting audio sample will be placed in a folder named “results”
The input is limited to 1000 characters (it will cut at 1000 in backend)

login.py

Example of how to login on the provided account

login_with_proxy.py

Example of how to login on the provided account with a proxy

suggest_tags.py

Example of tag suggestion for image gen

The result will be directed to the standard error output (stderr)

upscale_image.py

Example of how to upscale an image

It expects an image “results/image.png” to exist and will generate the resulting masks in this same folder
The image should be 512x768 by default, modify image_size to change it

Reference