stablediffusion

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package stablediffusion provides utilities to generate images with Stable Diffusion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerRunner

type ContainerRunner interface {
	// Run runs a container with the given image and arguments to completion,
	// and returns its combined output as a byte string.
	Run(ctx context.Context, image string, argv []string) ([]byte, error)
}

ContainerRunner is an interface to run containers.

type XL

type XL struct {
	// contains filtered or unexported fields
}

XL generates images using Stable Diffusion XL.

func NewDockerXL

func NewDockerXL(logger testutil.Logger) *XL

NewDockerXL returns a new Stable Diffusion XL generator using Docker containers on the local machine.

func NewXL

func NewXL(sdxlImage string, runner ContainerRunner) *XL

NewXL returns a new Stable Diffusion XL generator.

func (*XL) Generate

func (xl *XL) Generate(ctx context.Context, prompt *XLPrompt) (*XLImage, error)

Generate generates an image with Stable Diffusion XL.

type XLImage

type XLImage struct {
	Prompt *XLPrompt
	// contains filtered or unexported fields
}

XLImage is an image generated by Stable Diffusion XL.

func (*XLImage) ASCII

func (i *XLImage) ASCII() (string, error)

ASCII returns an ASCII version of the generated image.

func (*XLImage) ColdBaseDuration

func (i *XLImage) ColdBaseDuration() time.Duration

ColdBaseDuration returns time taken to run the base image generation model the first time the image was generated (i.e. the model was cold).

func (*XLImage) ColdRefinerDuration

func (i *XLImage) ColdRefinerDuration() time.Duration

ColdRefinerDuration returns time taken to run the refiner model the first time the image was generated (i.e. the model was cold). Returns -1 if the refiner was not run.

func (*XLImage) Image

func (i *XLImage) Image() (image.Image, error)

Image returns the generated image.

func (*XLImage) TotalDuration

func (i *XLImage) TotalDuration() time.Duration

TotalDuration returns the total time taken to generate the image.

func (*XLImage) WarmBaseDuration

func (i *XLImage) WarmBaseDuration() time.Duration

WarmBaseDuration returns time taken to run the base image generation model the second time the image was generated (i.e. the model was warm).

func (*XLImage) WarmRefinerDuration

func (i *XLImage) WarmRefinerDuration() time.Duration

WarmRefinerDuration returns time taken to run the refiner model the second time the image was generated (i.e. the model was warm). Returns -1 if the refiner was not run.

type XLPrompt

type XLPrompt struct {
	// Query is the text query to generate the image with.
	Query string

	// AllowCPUOffload is whether to allow offloading parts of the model to CPU.
	AllowCPUOffload bool

	// UseRefiner is whether to use the refiner model after the base model.
	// This takes more VRAM and more time but produces a better image.
	UseRefiner bool

	// NoiseFraction is the fraction of noise to seed the image with.
	// Must be between 0.0 and 1.0 inclusively.
	NoiseFraction float64

	// Steps is the number of diffusion steps to run for the base and refiner
	// models. More steps generally means sharper results but more time to
	// generate the image. A reasonable value is between 30 and 50.
	Steps int

	// Warm controls whether the image will be generated while the model is
	// warm. This will double the running time, as the image will still be
	// generated with a cold model first.
	Warm bool
}

XLPrompt is the input to Stable Diffusion XL to generate an image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL