This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
61 lines (58 loc) · 1.53 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"fmt"
"time"
"github.com/novitalabs/golang-sdk/request"
"github.com/novitalabs/golang-sdk/types"
"github.com/novitalabs/golang-sdk/util"
)
func main() {
// get your api key refer to https://docs.novita.ai/get-started/
const apiKey = "your-key"
client, err := request.NewClient(apiKey)
if err != nil {
fmt.Printf("new client failed, %v\n", err)
return
}
initImage := "./example/qrcode/qrcode.png"
initImageBase64, err := util.ReadImageToBase64(initImage)
if err != nil {
fmt.Printf("read image failed, %v\n", err)
return
}
txt2ImgReq := &types.Txt2ImgRequest{
Prompt: "a beautify butterfly in the colorful flowers, best quality, best details, masterpiece",
ModelName: "AnythingV5_v5PrtRE.safetensors",
SamplerName: types.DPMPPMKarras,
BatchSize: 1,
NIter: 1,
Steps: 30,
CfgScale: 7,
Height: 512,
Width: 512,
Seed: -1,
ControlNetUnits: []*types.ControlNetUnit{
{
Model: "control_v1p_sd15_qrcode_monster_v2",
Weight: 2.0,
Module: types.None,
InputImage: initImageBase64,
ControlMode: types.Balanced,
ResizeMode: types.JustResize,
GuidanceStart: 0,
GuidanceEnd: 1,
},
},
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
defer cancel()
res, err := client.SyncTxt2img(ctx, txt2ImgReq)
if err != nil {
fmt.Printf("read image failed, %v\n", err)
return
}
for _, s3Url := range res.Data.Imgs {
fmt.Printf("generate image url: %v\n", s3Url)
}
}