@@ -180,29 +180,88 @@ void print_params(SDParams params) {
180
180
181
181
sd_ctx_t * sd_c;
182
182
183
- int load_model (char *model, char *schedule_selected, int threads) {
183
+ sample_method_t sample_method;
184
+
185
+ int load_model (char *model, char * options[], int threads, int diff) {
184
186
fprintf (stderr, " Loading model!\n " );
185
187
188
+ char *stableDiffusionModel = " " ;
189
+ if (diff == 1 ) {
190
+ stableDiffusionModel = model;
191
+ model = " " ;
192
+ }
193
+
194
+ // decode options. Options are in form optname:optvale, or if booleans only optname.
195
+ char *clip_l_path = " " ;
196
+ char *clip_g_path = " " ;
197
+ char *t5xxl_path = " " ;
198
+ char *vae_path = " " ;
199
+ char *scheduler = " " ;
200
+ char *sampler = " " ;
201
+
202
+ // If options is not NULL, parse options
203
+ for (int i = 0 ; options[i] != NULL ; i++) {
204
+ char *optname = strtok (options[i], " :" );
205
+ char *optval = strtok (NULL , " :" );
206
+ if (optval == NULL ) {
207
+ optval = " true" ;
208
+ }
209
+
210
+ if (!strcmp (optname, " clip_l_path" )) {
211
+ clip_l_path = optval;
212
+ }
213
+ if (!strcmp (optname, " clip_g_path" )) {
214
+ clip_g_path = optval;
215
+ }
216
+ if (!strcmp (optname, " t5xxl_path" )) {
217
+ t5xxl_path = optval;
218
+ }
219
+ if (!strcmp (optname, " vae_path" )) {
220
+ vae_path = optval;
221
+ }
222
+ if (!strcmp (optname, " scheduler" )) {
223
+ scheduler = optval;
224
+ }
225
+ if (!strcmp (optname, " sampler" )) {
226
+ sampler = optval;
227
+ }
228
+ }
229
+
230
+ int sample_method_found = -1 ;
231
+ for (int m = 0 ; m < N_SAMPLE_METHODS; m++) {
232
+ if (!strcmp (sampler, sample_method_str[m])) {
233
+ sample_method_found = m;
234
+ }
235
+ }
236
+ if (sample_method_found == -1 ) {
237
+ fprintf (stderr, " Invalid sample method, default to EULER_A!\n " );
238
+ sample_method_found = EULER_A;
239
+ }
240
+ sample_method = (sample_method_t )sample_method_found;
241
+
186
242
int schedule_found = -1 ;
187
243
for (int d = 0 ; d < N_SCHEDULES; d++) {
188
- if (!strcmp (schedule_selected , schedule_str[d])) {
244
+ if (!strcmp (scheduler , schedule_str[d])) {
189
245
schedule_found = d;
246
+ fprintf (stderr, " Found scheduler: %s\n " , scheduler);
247
+
190
248
}
191
249
}
250
+
192
251
if (schedule_found == -1 ) {
193
252
fprintf (stderr, " Invalid scheduler! using DEFAULT\n " );
194
253
schedule_found = DEFAULT;
195
254
}
196
255
197
-
198
256
schedule_t schedule = (schedule_t )schedule_found;
199
-
257
+
258
+ fprintf (stderr, " Creating context\n " );
200
259
sd_ctx_t * sd_ctx = new_sd_ctx (model,
201
- " " ,
202
- " " ,
203
- " " ,
204
- " " ,
205
- " " ,
260
+ clip_l_path ,
261
+ clip_g_path ,
262
+ t5xxl_path ,
263
+ stableDiffusionModel ,
264
+ vae_path ,
206
265
" " ,
207
266
" " ,
208
267
" " ,
@@ -221,38 +280,26 @@ int load_model(char *model, char *schedule_selected, int threads) {
221
280
false );
222
281
223
282
if (sd_ctx == NULL ) {
224
- fprintf (stderr, " Null context! \n " );
283
+ fprintf (stderr, " failed loading model (generic error) \n " );
225
284
return 1 ;
226
285
}
286
+ fprintf (stderr, " Created context: OK\n " );
227
287
228
288
sd_c = sd_ctx;
229
289
230
290
return 0 ;
231
291
}
232
292
233
- int gen_image (char *text, char *negativeText, int width, int height, int steps, int seed , char * sample_method_selected, char *dst ) {
293
+ int gen_image (char *text, char *negativeText, int width, int height, int steps, int seed , char *dst, float cfg_scale ) {
234
294
235
295
sd_image_t * results;
236
296
237
-
238
- int sample_method_found = -1 ;
239
- for (int m = 0 ; m < N_SAMPLE_METHODS; m++) {
240
- if (!strcmp (sample_method_selected, sample_method_str[m])) {
241
- sample_method_found = m;
242
- }
243
- }
244
- if (sample_method_found == -1 ) {
245
- fprintf (stderr, " Invalid sample method, default to EULER_A!\n " );
246
- sample_method_found = EULER_A;
247
- return 1 ;
248
- }
249
- sample_method_t sample_method = (sample_method_t )sample_method_found;
250
297
std::vector<int > skip_layers = {7 , 8 , 9 };
251
298
results = txt2img (sd_c,
252
299
text,
253
300
negativeText,
254
301
-1 , // clip_skip
255
- 7 . 0f , // sfg_scale
302
+ cfg_scale , // sfg_scale
256
303
3 .5f ,
257
304
width,
258
305
height,
0 commit comments