stable-diffusion-prompt-parser

command module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

README

stable-diffusion-prompt-parser

Stable Diffusion Prompt Parser

Installation

$ go get -u github.com/junte/stable-diffusion-prompt-parser 

Supported prompt syntax

  • tags with default weight (dog, dog,cat)
  • tags with increased weight ((dog), ((dog)))
  • tags with decreased weight ([dog], [[dog]])
  • tags with custom weight ((dog:1.5), (cat:0.5))
  • lora models with default and custom multiplier (<lora:filename>, <lora:filename:1.5>)
  • hypernet models with default and custom multiplier (<hypernet:filename>, <hypernet:filename:1.5>)

Examples

Parse prompt
package main

import "github.com/junte/stable-diffusion-prompt-parser/src/parser"

func main() {
    prompt := "landscape from the Moon, (realistic, detailed:1.5), <lora:file>, <hypernet:file:1.5>"
    parser := parser.NewPromptParser()
    parsed, err := parser.ParsePrompt(prompt)
}

parsed:

{
  "Tags": [
    {
      "Tag": "landscape from the Moon",
      "Weight": 1
    },
    {
      "Tag": "realistic",
      "Weight": 1.5
    },
    {
      "Tag": "detailed",
      "Weight": 1.5
    }
  ],
  "Loras": [
    {
      "Filename": "file",
      "Multiplier": 1
    }
  ],
  "Hypernets": [
    {
      "Filename": "file",
      "Multiplier": 1.5
    }
  ]
}
Beautify prompt
package main

import "github.com/junte/stable-diffusion-prompt-parser/src/parser"

func main() {
    prompt := "landscape,,,, moon, ( realistic,detailed:1, 5), <hypernet:file:1. 5>"
    parser := parser.NewPromptParser()
    beautified, err := parser.BeautifyPrompt(prompt)
}

beautified:

landscape, moon (realistic, detailed:1.5) <hypernet:file:1.5>

Build

Use following make rules for build binary and run

$ make build
$ ./bin/prompt_linux_x64 < <(echo "landscape from the Moon")
$ ./bin/prompt_mac_amd64 < <(echo "landscape from the Moon")
$ ./bin/prompt_mac_arm64 < <(echo "landscape from the Moon")

Or use following command to build binary for desirable platform (use valid combinations of $GOOS and $GOARCH from here: https://go.dev/doc/install/source#environment)

$ GOOS=linux GOARCH=386 go build -ldflags "-s -w" -o bin/prompt main.go

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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