31
31
import piexif
32
32
import piexif .helper
33
33
from contextlib import closing
34
-
34
+ from modules . progress import create_task_id , add_task_to_queue , start_task , finish_task , current_task
35
35
36
36
def script_name_to_index (name , scripts ):
37
37
try :
@@ -336,6 +336,9 @@ def init_script_args(self, request, default_script_args, selectable_scripts, sel
336
336
return script_args
337
337
338
338
def text2imgapi (self , txt2imgreq : models .StableDiffusionTxt2ImgProcessingAPI ):
339
+ task_id = create_task_id ("text2img" )
340
+ if txt2imgreq .force_task_id is None :
341
+ task_id = txt2imgreq .force_task_id
339
342
script_runner = scripts .scripts_txt2img
340
343
if not script_runner .scripts :
341
344
script_runner .initialize_scripts (False )
@@ -362,6 +365,8 @@ def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
362
365
send_images = args .pop ('send_images' , True )
363
366
args .pop ('save_images' , None )
364
367
368
+ add_task_to_queue (task_id )
369
+
365
370
with self .queue_lock :
366
371
with closing (StableDiffusionProcessingTxt2Img (sd_model = shared .sd_model , ** args )) as p :
367
372
p .is_api = True
@@ -371,12 +376,14 @@ def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
371
376
372
377
try :
373
378
shared .state .begin (job = "scripts_txt2img" )
379
+ start_task (task_id )
374
380
if selectable_scripts is not None :
375
381
p .script_args = script_args
376
382
processed = scripts .scripts_txt2img .run (p , * p .script_args ) # Need to pass args as list here
377
383
else :
378
384
p .script_args = tuple (script_args ) # Need to pass args as tuple here
379
385
processed = process_images (p )
386
+ finish_task (task_id )
380
387
finally :
381
388
shared .state .end ()
382
389
shared .total_tqdm .clear ()
@@ -386,6 +393,10 @@ def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
386
393
return models .TextToImageResponse (images = b64images , parameters = vars (txt2imgreq ), info = processed .js ())
387
394
388
395
def img2imgapi (self , img2imgreq : models .StableDiffusionImg2ImgProcessingAPI ):
396
+ task_id = create_task_id ("img2img" )
397
+ if img2imgreq .force_task_id is None :
398
+ task_id = img2imgreq .force_task_id
399
+
389
400
init_images = img2imgreq .init_images
390
401
if init_images is None :
391
402
raise HTTPException (status_code = 404 , detail = "Init image not found" )
@@ -422,6 +433,8 @@ def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):
422
433
send_images = args .pop ('send_images' , True )
423
434
args .pop ('save_images' , None )
424
435
436
+ add_task_to_queue (task_id )
437
+
425
438
with self .queue_lock :
426
439
with closing (StableDiffusionProcessingImg2Img (sd_model = shared .sd_model , ** args )) as p :
427
440
p .init_images = [decode_base64_to_image (x ) for x in init_images ]
@@ -432,12 +445,14 @@ def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):
432
445
433
446
try :
434
447
shared .state .begin (job = "scripts_img2img" )
448
+ start_task (task_id )
435
449
if selectable_scripts is not None :
436
450
p .script_args = script_args
437
451
processed = scripts .scripts_img2img .run (p , * p .script_args ) # Need to pass args as list here
438
452
else :
439
453
p .script_args = tuple (script_args ) # Need to pass args as tuple here
440
454
processed = process_images (p )
455
+ finish_task (task_id )
441
456
finally :
442
457
shared .state .end ()
443
458
shared .total_tqdm .clear ()
@@ -511,7 +526,7 @@ def progressapi(self, req: models.ProgressRequest = Depends()):
511
526
if shared .state .current_image and not req .skip_current_image :
512
527
current_image = encode_pil_to_base64 (shared .state .current_image )
513
528
514
- return models .ProgressResponse (progress = progress , eta_relative = eta_relative , state = shared .state .dict (), current_image = current_image , textinfo = shared .state .textinfo )
529
+ return models .ProgressResponse (progress = progress , eta_relative = eta_relative , state = shared .state .dict (), current_image = current_image , textinfo = shared .state .textinfo , current_task = current_task )
515
530
516
531
def interrogateapi (self , interrogatereq : models .InterrogateRequest ):
517
532
image_b64 = interrogatereq .image
0 commit comments