novelai_api.ImagePreset

class ImageModel[source]

Bases: enum.Enum

Image model for low_level.suggest_tags() and low_level.generate_image()

Anime_Curated = 'safe-diffusion'
Anime_Full = 'nai-diffusion'
Furry = 'nai-diffusion-furry'
Inpainting_Anime_Curated = 'safe-diffusion-inpainting'
Inpainting_Anime_Full = 'nai-diffusion-inpainting'
Inpainting_Furry = 'furry-diffusion-inpainting'
Anime_v2 = 'nai-diffusion-2'
Anime_v3 = 'nai-diffusion-3'
Inpainting_Anime_v3 = 'nai-diffusion-3-inpainting'
Furry_v3 = 'nai-diffusion-furry-3'
Inpainting_Furry_v3 = 'nai-diffusion-furry-3-inpainting'
Anime_v4_preview = 'nai-diffusion-4-curated-preview'
class ControlNetModel[source]

Bases: enum.Enum

ControlNet Model for ImagePreset.controlnet_model and low_level.generate_controlnet_mask()

Palette_Swap = 'hed'
Form_Lock = 'midas'
Scribbler = 'fake_scribble'
Building_Control = 'mlsd'
Landscaper = 'uniformer'
class ImageResolution[source]

Bases: enum.Enum

Image resolution for ImagePreset.resolution

Wallpaper_Portrait = (1088, 1920)
Wallpaper_Landscape = (1920, 1088)
Small_Portrait = (384, 640)
Small_Landscape = (640, 384)
Small_Square = (512, 512)
Normal_Portrait = (512, 768)
Normal_Landscape = (768, 512)
Normal_Square = (640, 640)
Large_Portrait = (512, 1024)
Large_Landscape = (1024, 512)
Large_Square = (1024, 1024)
Small_Portrait_v2 = (512, 768)
Small_Landscape_v2 = (768, 512)
Small_Square_v2 = (640, 640)
Normal_Portrait_v2 = (832, 1216)
Normal_Landscape_v2 = (1216, 832)
Normal_Square_v2 = (1024, 1024)
Large_Portrait_v2 = (1024, 1536)
Large_Landscape_v2 = (1536, 1024)
Large_Square_v2 = (1472, 1472)
Small_Portrait_v3 = (512, 768)
Small_Landscape_v3 = (768, 512)
Small_Square_v3 = (640, 640)
Normal_Portrait_v3 = (832, 1216)
Normal_Landscape_v3 = (1216, 832)
Normal_Square_v3 = (1024, 1024)
Large_Portrait_v3 = (1024, 1536)
Large_Landscape_v3 = (1536, 1024)
Large_Square_v3 = (1472, 1472)
Small_Portrait_v4 = (512, 768)
Small_Landscape_v4 = (768, 512)
Small_Square_v4 = (640, 640)
Normal_Portrait_v4 = (832, 1216)
Normal_Landscape_v4 = (1216, 832)
Normal_Square_v4 = (1024, 1024)
Large_Portrait_v4 = (1024, 1536)
Large_Landscape_v4 = (1536, 1024)
Large_Square_v4 = (1472, 1472)
class ImageSampler[source]

Bases: enum.Enum

Sampler for ImagePreset.sampler

k_lms = 'k_lms'
k_euler = 'k_euler'
k_euler_ancestral = 'k_euler_ancestral'
k_heun = 'k_heun'
plms = 'plms'
ddim = 'ddim'
ddim_v3 = 'ddim_v3'
nai_smea = 'nai_smea'
nai_smea_dyn = 'nai_smea_dyn'
k_dpmpp_2m = 'k_dpmpp_2m'
k_dpmpp_2m_sde = 'k_dpmpp_2m_sde'
k_dpmpp_2s_ancestral = 'k_dpmpp_2s_ancestral'
k_dpmpp_sde = 'k_dpmpp_sde'
k_dpm_2 = 'k_dpm_2'
k_dpm_2_ancestral = 'k_dpm_2_ancestral'
k_dpm_adaptive = 'k_dpm_adaptive'
k_dpm_fast = 'k_dpm_fast'
class UCPreset[source]

Bases: enum.Enum

Default UC preset for ImagePreset.uc_preset

Preset_Low_Quality_Bad_Anatomy = 0
Preset_Low_Quality = 1
Preset_Bad_Anatomy = 2
Preset_None = 3
Preset_Heavy = 4
Preset_Light = 5
class ImageGenerationType[source]

Bases: enum.Enum

Image generation type for low_level.generate_image

NORMAL = 'generate'
IMG2IMG = 'img2img'
INPAINTING = 'infill'
class ImagePreset[source]

Bases: object

quality_toggle: bool

https://docs.novelai.net/image/qualitytags.html

auto_smea: bool

Automatically uses SMEA when image is above 1 megapixel

resolution: novelai_api.ImagePreset.ImageResolution | Tuple[int, int]

Resolution of the image to generate as ImageResolution or a (width, height) tuple

uc_preset: novelai_api.ImagePreset.UCPreset | None

Default UC to prepend to the UC

n_samples: int

Number of images to return

seed: int

Random seed to use for the image. The ith image has seed + i for seed

sampler: novelai_api.ImagePreset.ImageSampler

https://docs.novelai.net/image/sampling.html

noise: float

https://docs.novelai.net/image/strengthnoise.html

strength: float

https://docs.novelai.net/image/strengthnoise.html

scale: float

https://docs.novelai.net/image/stepsguidance.html (scale is called Prompt Guidance)

uncond_scale: float

TODO

steps: int

https://docs.novelai.net/image/stepsguidance.html

uc: str

https://docs.novelai.net/image/undesiredcontent.html

smea: bool

Enable SMEA for any sampler (makes Large+ generations manageable)

smea_dyn: bool

Enable SMEA DYN for any sampler if SMEA is enabled (best for Large+, but not Wallpaper resolutions)

image: str

b64-encoded png image for img2img

controlnet_condition: str

Controlnet mask gotten by the generate_controlnet_mask method

controlnet_model: novelai_api.ImagePreset.ControlNetModel

Model to use for the controlnet

controlnet_strength: float

Influence of the chosen controlnet on the image

decrisper: bool

Reduce the deepfrying effects of high scale (https://twitter.com/Birchlabs/status/1582165379832348672)

add_original_image: bool

Prevent seams along the edges of the mask, but may change the image slightly

mask: str

Mask for inpainting (b64-encoded black and white png image, white is the inpainting area)

cfg_rescale: float

https://docs.novelai.net/image/stepsguidance.html#prompt-guidance-rescale

noise_schedule: str

??? (TODO: use an enum ? - valid values: native, karras, exponential, polyexponential)

reference_image: str

b64-encoded png image for Vibe Transfer

reference_information_extracted: float

https://docs.novelai.net/.image/vibetransfer.html#information-extracted

reference_strength: float

https://docs.novelai.net/.image/vibetransfer.html#reference-strength

reference_image_multiple: List[str]

reference_image for multi-vibe transfer

reference_information_extracted_multiple: List[float]

reference_information_extracted for multi-vibe transfer

reference_strength_multiple: List[float]

reference_strength for multi-vibe transfer

variety_plus: bool

https://blog.novelai.net/summer-sampler-update-en-3a34eb32b613

use_coords: bool

Whether the AI should strictly follow the positions of the characters or have some freedom

characters: List[Dict[str, str]]

https://docs.novelai.net/image/multiplecharacters.html#multi-character-prompting See examples/generate_image_v4.py for the format

legacy_v3_extend: bool

Use the old behavior of prompt separation at the 75 tokens mark (can cut words in half)

params_version: int

Revision of the default arguments

deliberate_euler_ancestral_bug: bool

Use the old behavior of noise scheduling with the k_euler_ancestral sampler

prefer_brownian: bool

???

last_seed: int

Seed provided when generating an image with seed 0 (default). Seed is also in metadata, but might be a hassle

classmethod from_file(path: str | bytes | os.PathLike | int) novelai_api.ImagePreset.ImagePreset[source]

Write the preset to a file

Parameters:

path – Path to the file to read the preset from

to_file(path: str | bytes | os.PathLike | int)[source]

Load the preset from a file

Parameters:

path – Path to the file to write the preset to

__init__(*, legacy: bool)[source]

Create an empty ImagePreset. Use the “from_*_config” functions to create a

classmethod from_v1_config()[source]

Create a new ImagePreset with the default settings from the v1 config

classmethod from_v2_config()[source]

Create a new ImagePreset with the default settings from the v2 config

classmethod from_v3_config()[source]

Create a new ImagePreset with the default settings from the v3 config

classmethod from_v3_furry_config()[source]

Create a new ImagePreset with the default settings from the v3 furry config

classmethod from_v4_config()[source]

Create a new ImagePreset with the default settings from the v4 config

classmethod from_default_config(model: novelai_api.ImagePreset.ImageModel) novelai_api.ImagePreset.ImagePreset[source]

Create a new ImagePreset with the default settings inferring the version from the model

Parameters:

model – Model to use

update(values: Dict[str, Any] | None = None, **kwargs) novelai_api.ImagePreset.ImagePreset[source]

Update the settings stored in the preset. Works like dict.update()

copy() novelai_api.ImagePreset.ImagePreset[source]

Create a new ImagePreset instance from the current one

to_settings(model: novelai_api.ImagePreset.ImageModel) Dict[str, Any][source]

Return the values stored in the preset, for a generate_image function

Parameters:

model – Image model to get the settings of

get_max_n_samples()[source]

Get the allowed max value of ImagePreset.n_samples using current preset values

calculate_cost(is_opus: bool, version: int = 1, generation_type: novelai_api.ImagePreset.ImageGenerationType = ImageGenerationType.NORMAL)[source]

Calculate the cost (in Anlas) of generating with the current configuration

Parameters:
  • is_opus – Is the subscription tier Opus ? Account for free generations if so

  • version – Version of the model to use (1, 2, 3)

  • generation_type – Type of generation to do (img2img, txt2img, etc.)