gosd

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: MIT Imports: 22 Imported by: 0

README

Stable Diffusion for Go

Go Reference

This is a Go wrapper for stable-diffusion.cpp.

It embeds all required C/C++ files into the project and compiles it statically, so there's no need for additional libraries.

Only tested on Linux x64.

Using as a CLI

go install github.com/dennwc/gosd/cmd/gosd@latest
gosd -m ./path/to/model.safetensors -W 256 -H 256 --steps 20 -p "an image of a cat" -o output.png

Using as a library

go get -u github.com/dennwc/gosd

See cmd/gosd for an example.

License

MIT

Documentation

Index

Constants

View Source
const (
	TypeF32     = Type(sdcpp.SD_TYPE_F32)
	TypeF16     = Type(sdcpp.SD_TYPE_F16)
	TypeQ4_0    = Type(sdcpp.SD_TYPE_Q4_0)
	TypeQ4_1    = Type(sdcpp.SD_TYPE_Q4_1)
	TypeQ5_0    = Type(sdcpp.SD_TYPE_Q5_0)
	TypeQ5_1    = Type(sdcpp.SD_TYPE_Q5_1)
	TypeQ8_0    = Type(sdcpp.SD_TYPE_Q8_0)
	TypeQ8_1    = Type(sdcpp.SD_TYPE_Q8_1)
	TypeQ2_K    = Type(sdcpp.SD_TYPE_Q2_K)
	TypeQ3_K    = Type(sdcpp.SD_TYPE_Q3_K)
	TypeQ4_K    = Type(sdcpp.SD_TYPE_Q4_K)
	TypeQ5_K    = Type(sdcpp.SD_TYPE_Q5_K)
	TypeQ6_K    = Type(sdcpp.SD_TYPE_Q6_K)
	TypeQ8_K    = Type(sdcpp.SD_TYPE_Q8_K)
	TypeIQ2_XXS = Type(sdcpp.SD_TYPE_IQ2_XXS)
	TypeI8      = Type(sdcpp.SD_TYPE_I8)
	TypeI16     = Type(sdcpp.SD_TYPE_I16)
	TypeI32     = Type(sdcpp.SD_TYPE_I32)
	TypeDefault = Type(sdcpp.SD_TYPE_COUNT)
)
View Source
const (
	StdDefaultRNG = RNGType(sdcpp.STD_DEFAULT_RNG)
	CUDA_RNG      = RNGType(sdcpp.CUDA_RNG)
)
View Source
const (
	ScheduleDefault = Schedule(sdcpp.DEFAULT)
	Discrete        = Schedule(sdcpp.DISCRETE)
	Karras          = Schedule(sdcpp.KARRAS)
	NSchedules      = Schedule(sdcpp.N_SCHEDULES)
)
View Source
const C = 0

Variables

This section is empty.

Functions

func NewRuntime

func NewRuntime(p RuntimeParams) (runtime.Runtime, error)

func SystemInfo

func SystemInfo() string

Types

type Context

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

func New

func New(p Params) (*Context, error)

func (*Context) Close

func (sd *Context) Close()

func (*Context) TextToImage

func (sd *Context) TextToImage(p TextToImageParams) *image.NRGBA

func (*Context) TextToImages

func (sd *Context) TextToImages(p TextToImageParams) ([]*image.NRGBA, error)

type Params

type Params struct {
	ModelPath       string
	VAEPath         string
	TAESDPath       string
	CtrlNetPath     string
	LoraPath        string
	EmbeddingDir    string
	VAETiling       bool
	FreeImmediately bool
	Threads         int
	Type            Type
	RNG             RNGType
	Schedule        Schedule
	CtrlNetKeepCPU  bool
	Log             *slog.Logger
}

type RNGType

type RNGType int

type RuntimeParams

type RuntimeParams struct {
	ModelDir     string
	EmbeddingDir string
	RNG          RNGType
	Threads      int
	Type         Type
	Log          *slog.Logger
}

type SamplingMethod

type SamplingMethod int

func ParseSamplingMethod

func ParseSamplingMethod(s string) (SamplingMethod, error)

func (SamplingMethod) ID

func (m SamplingMethod) ID() string

func (SamplingMethod) MarshalText

func (m SamplingMethod) MarshalText() ([]byte, error)

func (*SamplingMethod) Parse

func (m *SamplingMethod) Parse(text string) error

func (SamplingMethod) String

func (m SamplingMethod) String() string

func (*SamplingMethod) UnmarshalText

func (m *SamplingMethod) UnmarshalText(text []byte) error

type Schedule

type Schedule int

type TextToImageParams

type TextToImageParams struct {
	Prompt     string
	Negative   string
	ClipSkip   int
	CfgScale   float64
	Width      int
	Height     int
	Sampling   SamplingMethod
	Steps      int
	BatchCount int
	Seed       int64
}

type Type

type Type int

Directories

Path Synopsis
cmd
Package runtime provides common types and interfaces that all Stable Diffusion runtimes share.
Package runtime provides common types and interfaces that all Stable Diffusion runtimes share.
auto
Package auto implements Automatic1111 Stable Diffusion WebUI client.
Package auto implements Automatic1111 Stable Diffusion WebUI client.

Jump to

Keyboard shortcuts

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