@@ -3,9 +3,6 @@ const { base64ToBase64Url } = require('./utility/general')
3
3
4
4
const py_re = require ( './utility/sdapi/python_replacement' )
5
5
const Enum = require ( './enum' )
6
- const { control_net } = require ( './typescripts/dist/bundle' )
7
- const { mapPluginSettingsToControlNet, getEnableControlNet, getModuleDetail } =
8
- control_net
9
6
10
7
const api = require ( './utility/api' )
11
8
//javascript plugin can't read images from local directory so we send a request to local server to read the image file and send it back to plugin as image string base64
@@ -359,186 +356,6 @@ async function requestExtraSingleImage(payload) {
359
356
}
360
357
}
361
358
362
- //REFACTOR: reuse the same code for (requestControlNetTxt2Img,requestControlNetImg2Img)
363
- async function requestControlNetTxt2Img ( plugin_settings ) {
364
- console . log ( 'requestControlNetTxt2Img: ' )
365
-
366
- // const full_url = `${g_sd_url}/controlnet/txt2img`
367
- const full_url = `${ g_sd_url } /sdapi/v1/txt2img`
368
-
369
- const control_net_settings = mapPluginSettingsToControlNet ( plugin_settings )
370
- let control_networks = [ ]
371
- // let active_control_networks = 0
372
- for ( let index = 0 ; index < g_controlnet_max_models ; index ++ ) {
373
- if ( ! getEnableControlNet ( index ) ) {
374
- control_networks [ index ] = false
375
- continue
376
- }
377
- control_networks [ index ] = true
378
-
379
- if ( ! control_net_settings [ 'controlnet_units' ] [ index ] [ 'input_image' ] ) {
380
- app . showAlert ( 'you need to add a valid ControlNet input image' )
381
- throw 'you need to add a valid ControlNet input image'
382
- }
383
-
384
- if ( ! control_net_settings [ 'controlnet_units' ] [ index ] [ 'module' ] ) {
385
- app . showAlert ( 'you need to select a valid ControlNet Module' )
386
- throw 'you need to select a valid ControlNet Module'
387
- }
388
-
389
- if (
390
- ( ! control_net_settings [ 'controlnet_units' ] [ index ] [ 'model' ] &&
391
- ! getModuleDetail ( ) [
392
- control_net_settings [ 'controlnet_units' ] [ index ] [ 'module' ]
393
- ] . model_free ) ||
394
- control_net_settings [ 'controlnet_units' ] [ index ] [ 'model' ] === 'none'
395
- ) {
396
- app . showAlert ( 'you need to select a valid ControlNet Model' )
397
- throw 'you need to select a valid ControlNet Model'
398
- }
399
- // active_control_networks++
400
- }
401
-
402
- let request = await fetch ( full_url , {
403
- method : 'POST' ,
404
- headers : {
405
- Accept : 'application/json' ,
406
- 'Content-Type' : 'application/json' ,
407
- } ,
408
- body : JSON . stringify ( control_net_settings ) ,
409
- } )
410
-
411
- let json = await request . json ( )
412
- console . log ( 'json:' , json )
413
-
414
- //update the mask in controlNet tab
415
- const numOfImages = json [ 'images' ] . length
416
- let numberOfAnnotations =
417
- numOfImages - g_generation_session . last_settings . batch_size
418
- if ( numberOfAnnotations < 0 ) numberOfAnnotations = 0
419
-
420
- const base64_mask = json [ 'images' ] . slice ( numOfImages - numberOfAnnotations )
421
-
422
- let mask_index = 0
423
-
424
- for ( let index = 0 ; index < control_networks . length ; index ++ ) {
425
- if (
426
- control_networks [ index ] == false ||
427
- mask_index >= numberOfAnnotations
428
- )
429
- continue
430
- control_net . setControlDetectMapSrc ( base64_mask [ mask_index ] , index )
431
- g_generation_session . controlNetMask [ index ] = base64_mask [ mask_index ]
432
- mask_index ++
433
- }
434
- // g_generation_session.controlNetMask = base64_mask
435
-
436
- const standard_response = await py_re . convertToStandardResponse (
437
- control_net_settings ,
438
- json [ 'images' ] . slice ( 0 , numOfImages - numberOfAnnotations ) ,
439
- plugin_settings [ 'uniqueDocumentId' ]
440
- )
441
- console . log ( 'standard_response:' , standard_response )
442
-
443
- return standard_response
444
- }
445
-
446
- //REFACTOR: reuse the same code for (requestControlNetTxt2Img,requestControlNetImg2Img)
447
- async function requestControlNetImg2Img ( plugin_settings ) {
448
- console . log ( 'requestControlNetImg2Img: ' )
449
-
450
- const full_url = `${ g_sd_url } /sdapi/v1/img2img`
451
- const control_net_settings = mapPluginSettingsToControlNet ( plugin_settings )
452
-
453
- // let control_networks = 0
454
- let control_networks = [ ]
455
- for ( let index = 0 ; index < g_controlnet_max_models ; index ++ ) {
456
- if ( ! getEnableControlNet ( index ) ) {
457
- control_networks [ index ] = false
458
- continue
459
- }
460
- control_networks [ index ] = true
461
- if ( ! control_net_settings [ 'controlnet_units' ] [ index ] [ 'input_image' ] ) {
462
- app . showAlert ( 'you need to add a valid ControlNet input image' )
463
- throw 'you need to add a valid ControlNet input image'
464
- }
465
-
466
- if ( ! control_net_settings [ 'controlnet_units' ] [ index ] [ 'module' ] ) {
467
- app . showAlert ( 'you need to select a valid ControlNet Module' )
468
- throw 'you need to select a valid ControlNet Module'
469
- }
470
- if (
471
- ( ! control_net_settings [ 'controlnet_units' ] [ index ] [ 'model' ] &&
472
- ! getModuleDetail ( ) [
473
- control_net_settings [ 'controlnet_units' ] [ index ] [ 'module' ]
474
- ] . model_free ) ||
475
- control_net_settings [ 'controlnet_units' ] [ index ] [ 'model' ] === 'none'
476
- ) {
477
- app . showAlert ( 'you need to select a valid ControlNet Model' )
478
- throw 'you need to select a valid ControlNet Model'
479
- }
480
- }
481
-
482
- let request = await fetch ( full_url , {
483
- method : 'POST' ,
484
- headers : {
485
- Accept : 'application/json' ,
486
- 'Content-Type' : 'application/json' ,
487
- } ,
488
- body : JSON . stringify ( control_net_settings ) ,
489
- // body: JSON.stringify(payload),
490
- } )
491
-
492
- let json = await request . json ( )
493
- console . log ( 'json:' , json )
494
-
495
- //update the mask in controlNet tab
496
- const numOfImages = json [ 'images' ] . length
497
- let numberOfAnnotations =
498
- numOfImages - g_generation_session . last_settings . batch_size
499
- if ( numberOfAnnotations < 0 ) numberOfAnnotations = 0
500
-
501
- // To fix a bug: when Ultimate SD Upscale is active and running, the detection maps won’t be retrieved.
502
- // So set its value to 0 to avoid the result images being loaded in the annotation map interface.
503
- if (
504
- scripts . script_store . isInstalled ( ) &&
505
- scripts . script_store . is_active &&
506
- scripts . script_store . selected_script_name !== 'None' &&
507
- scripts . script_store . is_selected_script_available
508
- ) {
509
- numberOfAnnotations = 0
510
- }
511
- const base64_mask = json [ 'images' ] . slice ( numOfImages - numberOfAnnotations )
512
-
513
- let mask_index = 0
514
- for ( let index = 0 ; index < control_networks . length ; index ++ ) {
515
- if (
516
- control_networks [ index ] == false ||
517
- mask_index >= numberOfAnnotations
518
- )
519
- continue
520
- control_net . setControlDetectMapSrc ( base64_mask [ mask_index ] , index )
521
- g_generation_session . controlNetMask [ index ] = base64_mask [ mask_index ]
522
- mask_index ++
523
- }
524
-
525
- // g_generation_session.controlNetMask = base64_mask
526
-
527
- const standard_response = await py_re . convertToStandardResponse (
528
- control_net_settings ,
529
- json [ 'images' ] . slice ( 0 , numOfImages - numberOfAnnotations ) ,
530
- plugin_settings [ 'uniqueDocumentId' ]
531
- )
532
- console . log ( 'standard_response:' , standard_response )
533
-
534
- // //get all images except last because it's the mask
535
- // for (const image of json['images'].slice(0, -1)) {
536
- // await io.IO.base64ToLayer(image)
537
- // }
538
-
539
- return standard_response
540
- }
541
-
542
359
async function isWebuiRunning ( ) {
543
360
console . log ( 'isWebuiRunning: ' )
544
361
let json = [ ]
@@ -577,7 +394,5 @@ module.exports = {
577
394
// requestHordeStatus,
578
395
requestExtraSingleImage,
579
396
580
- requestControlNetTxt2Img,
581
- requestControlNetImg2Img,
582
397
isWebuiRunning,
583
398
}
0 commit comments