-
Notifications
You must be signed in to change notification settings - Fork 12
Example
Meonako edited this page Dec 15, 2022
·
33 revisions
package main
import (
"fmt"
"image/png"
"os"
"github.com/Meonako/webui-api"
"text/tabwriter"
)
func main() {
API := api.New(api.Config{
UseDefault: true,
})
resp, err := API.Text2Image(api.Txt2Image{
Prompt: api.BuildPrompt(
"solo", "cute", "adorable", "innocent",
"blush", "girly", "narrow waist", "absurdly long hair",
"(pink hair)", "hair ornament", "pink eyes", "hair flower",
),
//
// Or you can pass a long string
//
// Prompt: "solo, cute, adorable, innocent, blush, girly, narrow waist, absurdly long hair, (pink hair), hair ornament, pink eyes, hair flower",
//
// Or you can do this
//
// Prompt: "solo, cute, adorable, innocent" +
// "blush, girly, narrow waist, absurdly long hair" +
// "(pink hair), hair ornament, pink eyes, hair flower",
//
NegativePrompt: api.BuildPrompt(
"sketch by bad-artist", "lowres", "bad anatomy",
"bad hands", "text", "error", "missing fingers",
"extra digit", "fewer digits", "cropped",
"worst quality", "low quality", "normal quality",
"jpeg artifacts", "signature", "watermark",
"username", "blurry", "simple background",
"(track suit)", "(jacket)", "(name tag)",
"(sleeveless), (shoes), (socks), hat",
"covered navel, clothes lift, clothes pull, (head out of frame)",
),
})
if err != nil {
panic(err)
}
writer := tabwriter.NewWriter(os.Stdout, 1, 1, 3, ' ', 0)
fmt.Fprintf(writer, "Steps\t|\t%v\n", resp.Parameters.Steps)
fmt.Fprintf(writer, "Sampler Name\t|\t%v\n", resp.Parameters.SamplerName)
fmt.Fprintf(writer, "Sampler Index\t|\t%v\n", resp.Parameters.SamplerIndex)
fmt.Fprintf(writer, "Width\t|\t%v\n", resp.Parameters.Width)
fmt.Fprintf(writer, "Height\t|\t%v\n", resp.Parameters.Height)
writer.Flush()
readers, err := resp.MakeBytesReader()
if err != nil {
panic(err)
}
for index, reader := range readers {
file, err := os.OpenFile(fmt.Sprintf("Image (%v).png", index), os.O_WRONLY|os.O_CREATE, 0777)
if err != nil {
panic(err)
}
defer file.Close()
img, err := png.Decode(reader)
if err != nil {
panic(err)
}
err = png.Encode(file, img)
if err != nil {
panic(err)
}
}
}The output should be like this

and you'll have file named "Image (0).png" in your root folder
package main
import (
"fmt"
"os"
"text/tabwriter"
"github.com/Meonako/webui-api"
)
func main() {
API := api.New(api.Config{
UseDefault: true,
})
progress, err := API.Progress()
if err != nil {
panic(err)
}
writer := tabwriter.NewWriter(os.Stdout, 1, 1, 3, ' ', 0)
fmt.Fprintf(writer, "Progress\t|\t%v\n", progress.GetProgress(""))
fmt.Fprintf(writer, "ETA Name\t|\t%v\n", progress.GetETA())
fmt.Fprintf(writer, "Current Steps\t|\t%v\n", progress.State.CurrentStep)
fmt.Fprintf(writer, "Target Sampling Steps\t|\t%v\n", progress.State.TargetSamplingSteps)
fmt.Fprintf(writer, "Job\t|\t%v\n", progress.State.Job)
fmt.Fprintf(writer, "Job No\t|\t%v\n", progress.State.JobNo)
fmt.Fprintf(writer, "Job Count\t|\t%v\n", progress.State.JobCount)
fmt.Fprintf(writer, "Interrupted\t|\t%v\n", progress.State.Interrupted)
fmt.Fprintf(writer, "Skipped\t|\t%v\n", progress.State.Skipped)
writer.Flush()
}Expect Output
