stability AI components

Engineering Notes

You need to have stability_sdk installed to use this component. You can install it with:

pip install chainfury[stability]
# or to install all the components, note this will keep on growing
pip install chainfury[all]
chainfury.components.stability.stability_text_to_image(text_prompts: str | List[str] | List[Dict[str, str | float]], stability_api_key: Secret = '', stability_host: str = 'grpc.stability.ai:443', height: int = 768, width: int = 768, cfg_scale: float = 7, engine: str = 'stable-diffusion-768-v2-1', start_schedule: float = 1.0, end_schedule: float = 0.01, sampler: str = '', samples: int = 1, seed: int = 0, steps: int = 50, style_preset: str = '', *, prefix: str = 'nbx-cf-component-stability-text-to-image', max_retries: int = 3, retry_delay: int = 1) List[str][source]

Generate an image from text prompts using the Stability API.

Parameters:
  • text_prompts (List[Dict[str, Union[str, float]]]) – An array of text prompts to use for generation. Given a text prompt with the text “A lighthouse on a cliff” and a weight of 0.5, it would be represented as: [{“text”: “A lighthouse on a cliff”, “weight”: 0.5}]

  • stability_api_key (Secret) – Your Stability API key. If not provided, we’ll try to use the STABILITY_KEY environment variable.

  • stability_host (str) – The Stability API host to use. Default: “grpc.stability.ai:443”.

  • height (int) – Height of the image in pixels. Must be in increments of 64 and pass the following validation: For 768 engines: 589,824 ≤ height * width ≤ 1,048,576 All other engines: 262,144 ≤ height * width ≤ 1,048,576

  • width (int) – Width of the image in pixels. Must be in increments of 64 and pass the following validation: For 768 engines: 589,824 ≤ height * width ≤ 1,048,576 All other engines: 262,144 ≤ height * width ≤ 1,048,576

  • cfg_scale (float) – How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt). Default: 7.

  • sampler (str) – Which sampler to use for the diffusion process. If this value is omitted we’ll automatically select an appropriate sampler for you.

  • samples (int) – Number of images to generate. Default: 1.

  • seed (int) – Random noise seed (omit this option or use 0 for a random seed). Default: 0.

  • steps (int) – Number of diffusion steps to run. Default: 50.

  • style_preset (str) – Pass in a style preset to guide the image model towards a particular style. This list of style presets is subject to change.

  • prefix (str) – Prefix to use for the generated images. Default: “nbx-cf-component-stability-text-to-image/”.

Returns:

A list of base64-encoded PNG images.

Return type:

List[str]