forked from Lebenoa/webui-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
158 lines (128 loc) · 2.82 KB
/
config.go
File metadata and controls
158 lines (128 loc) · 2.82 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package api
import (
"strings"
"github.com/Meonako/webui-api/sampler"
)
type Config struct {
// URL to API endpoint (e.g. http://127.0.0.1:7860, https://b645a912.gradio.app)
//
// - Default: http://127.0.0.1:7860
BaseURL string
// API path is stored here
Path *APIPath
// Default Value are store here.
Default *Default
}
type Default struct {
// Sampling Method or Sampler (e.g. Euler a, DPM++ 2M Karras). You can type it in yourself or use built-in Helper Package: sampler
//
// Default: "Euler a"
Sampler string
// Sampling Steps (e.g. 20, 120)
//
// Default: 20
Steps int
// Classifier-Free Guidance Scale (e.g. 7, 12.0)
//
// Default: 7.0
CFGScale float64
// Width of the image (e.g. 512, 1024)
//
// Default: 512
Width int
// Height of the image (e.g. 512, 1024)
//
// Default: 512
Height int
}
type APIPath struct {
// Path to txt2img API
//
// - Default: /sdapi/v1/txt2img
Txt2Img string
// Path to img2img API
//
// - Default: /sdapi/v1/img2img
Img2Img string
// Path to extra single image API
//
// - Default: /sdapi/v1/extra-single-image
ExtraSingle string
// Path to extra batch images API
//
// - Default: /sdapi/v1/extra-batch-images
ExtraBatch string
// Path to png info API
//
// - Default: /sdapi/v1/png-info
PNGInfo string
// Path to progress API
//
// - Default: /sdapi/v1/progress
Progress string
// Path to interrogate API
//
// - Default: /sdapi/v1/interrogate
Interrogate string
// Path to interrupt API
//
// - Default: /sdapi/v1/interrupt
Interrupt string
// Path to skip API
//
// - Default: /sdapi/v1/skip
Skip string
// Path to options API
//
// - Default: /sdapi/v1/options
Options string
// Path to sd-models API
//
// - Default: /sdapi/v1/sd-models
SDModels string
}
var DefaultConfig = Config{
BaseURL: "http://127.0.0.1:7860",
Path: &APIPath{
Txt2Img: "/sdapi/v1/txt2img",
Img2Img: "/sdapi/v1/img2img",
ExtraSingle: "/sdapi/v1/extra-single-image",
ExtraBatch: "/sdapi/v1/extra-batch-images",
PNGInfo: "/sdapi/v1/png-info",
Progress: "/sdapi/v1/progress",
Interrogate: "/sdapi/v1/interrogate",
Interrupt: "/sdapi/v1/interrupt",
Skip: "/sdapi/v1/skip",
Options: "/sdapi/v1/options",
SDModels: "/sdapi/v1/sd-models",
},
}
/*
Default Values.
Sampler = sampler.EULER_A,
Steps = 28,
CFGScale = 7,
Width = 512,
Height = 512,
*/
var DefaultValue = &Default{
Sampler: sampler.EULER_A,
Steps: 20,
CFGScale: 7,
Width: 512,
Height: 512,
}
func setDefault(conf ...Config) Config {
if len(conf) <= 0 {
return DefaultConfig
}
config := conf[0]
if config.BaseURL == "" {
config.BaseURL = DefaultConfig.BaseURL
}
config.BaseURL = strings.TrimSuffix(config.BaseURL, "/")
if config.Path == nil {
config.Path = DefaultConfig.Path
}
return config
}