https://github.com/seasonjs/stable-diffusion
pure go for stable-diffusion and support cross-platform.
https://github.com/seasonjs/stable-diffusion
deep-learning ggml go golang hacktoberfest image2image stable-diffusion text2image
Last synced: 3 months ago
JSON representation
pure go for stable-diffusion and support cross-platform.
- Host: GitHub
- URL: https://github.com/seasonjs/stable-diffusion
- Owner: seasonjs
- License: mit
- Created: 2023-09-20T13:23:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-08T08:42:59.000Z (about 1 year ago)
- Last Synced: 2024-02-19T10:11:32.274Z (about 1 year ago)
- Topics: deep-learning, ggml, go, golang, hacktoberfest, image2image, stable-diffusion, text2image
- Language: Go
- Homepage: https://pkg.go.dev/github.com/seasonjs/stable-diffusion
- Size: 26.6 MB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stable-diffusion
pure go ( cgo free ) for stable-diffusion and support cross-platform.
[](https://pkg.go.dev/github.com/seasonjs/stable-diffusion)
sd.go is a wrapper around [stable-diffusion.cpp](https://github.com/leejet/stable-diffusion.cpp), which is an adaption
of ggml.cpp.
![]()
## Installation
```bash
go get github.com/seasonjs/stable-diffusion
```## AutoModel Compatibility
See `deps` folder for dylib compatibility, push request is welcome.
Windows NVIDIA GPU User may need check [cuda architecture](https://developer.nvidia.com/cuda-gpus) to get more information.
Windows AMD/ROCM GPU User may need check [system requirements](https://rocm.docs.amd.com/projects/install-on-windows/en/latest/reference/system-requirements.html) to get more information.
| platform | x32 | x64 | arm | AMD/ROCM | NVIDIA/CUDA |
|----------|-------------|-------------------------|-------------|-----------------|----------------|
| windows | not support | support avx/avx2/avx512 | not support | rocm5.5 support | cuda12 support |
| linux | not support | support | not support | not support | not support |
| darwin | not support | support | support | not support | not support |## AutoModel Dynamic Libraries Disclaimer
#### The Source of dynamic Libraries
These dynamic libraries come from [stable-diffusion.cpp-build release](https://github.com/seasonjs/stable-diffusion.cpp-build/releases), The dynamic library version can be obtained by viewing [stable-diffusion.version file](./deps/stable-diffusion.version)
Anyone can check the consistency of the file by checksum ( MD5 ).#### The Security Of Dynamic Libraries
All I can say is that the creation of the dynamic library is public and does not contain any subjective malicious logic.
If you are worried about the security of the dynamic library during the use process, you can build it yourself.**I and any author related to dynamic libraries do not assume any problems, responsibilities or legal liability during use.**
## Usage
This `stable-diffusion` golang library provide two api `Predict` and `ImagePredict`.
Usually you can use `NewAutoModel`, so you don't need to load the dynamic library.
You can find a complete example in [examples](./exmaples) folder.
Here is a simple example:
```go
package mainimport (
"github.com/seasonjs/hf-hub/api"
sd "github.com/seasonjs/stable-diffusion"
"io"
"os"
)func main() {
options := sd.DefaultOptionsmodel, err := sd.NewAutoModel(options)
if err != nil {
print(err.Error())
return
}
defer model.Close()hapi, err := api.NewApi()
if err != nil {
print(err.Error())
return
}modelPath, err := hapi.Model("justinpinkney/miniSD").Get("miniSD.ckpt")
if err != nil {
print(err.Error())
return
}err = model.LoadFromFile(modelPath)
if err != nil {
print(err.Error())
return
}
var writers []io.Writer
filenames := []string{
"../assets/love_cat0.png",
}
for _, filename := range filenames {
file, err := os.Create(filename)
if err != nil {
print(err.Error())
return
}
defer file.Close()
writers = append(writers, file)
}err = model.Predict("british short hair cat, high quality", sd.DefaultFullParams, writers)
if err != nil {
print(err.Error())
}
}
```## Packaging
To ship a working program that includes this AI, you will need to include the following files:
* libstable-diffusion.dylib / libstable-diffusion.so / stable-diffusion.dll (buildin)
* the model file
* the tokenizer file (buildin)
* cuda runtime library, if you use cuda## Low level API
This package also provide low level Api which is same
as [stable-diffusion-cpp](https://github.com/leejet/stable-diffusion.cpp).
See detail at [stable-diffusion-doc](https://pkg.go.dev/github.com/seasonjs/stable-diffusion).## Thanks
* [stable-diffusion-cpp](https://github.com/leejet/stable-diffusion.cpp)
* [ggml.cpp](https://github.com/leejet/ggml.cpp)
* [purego](https://github.com/ebitengine/purego)## Successful Examples
![]()
![]()
![]()
![]()
![]()
![]()
[//]: # ()
[//]: # (
)
[//]: # ()
## License
Copyright (c) seasonjs. All rights reserved.
Licensed under the MIT License. See License.txt in the project root for license information.