
    i                     P   d dl mZ ddlmZmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZ dd	lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& dd
l'm(Z(m)Z)m*Z*  ejV                  e,      Z- ed e       fd e       fg      Z. G d de      Z/ ed e%       fd e*       fd e       fd e       fd e       fd e       fd e/       fg      Z0 ede#fd e&       fg      Z1 G d de      Z2 ed e*       fd e)dgdg      fg      Z3 G d de      Z4 ed  e       fd! e	       fg      Z5 G d" d#e      Z6 ed e       fd e       fg      Z7 G d$ d%e      Z8 ed e%       fd& e2       fd e4       fd e       fd e       fd' e6       fd e       fd e       fd e8       fg	      Z9 ed e$       fd e&       fg      Z: G d( d)e      Z; ed e*       fd e)dg*      fg      Z< G d+ d,e      Z= ed e%       fd& e;       fd e=       fd e       fd e       fd- e       fd e       fd e       fd e/       fg	      Z> ed. e       fd/ e(       fd0 e       fd1 e       fg      Z? G d2 d3e      Z@ G d4 d5e      ZA G d6 d7e      ZB G d8 d9e      ZC ed e       fd e       fd e       fg      ZD G d: d;e      ZE ed e       fd e       fd' e6       fd e       fg      ZF G d< d=e      ZG ed e       fd e       fd- e       fd e       fg      ZH G d> d?e      ZI G d@ dAe      ZJ G dB dCe      ZK G dD dEe      ZL G dF dGe      ZM G dH dIe      ZN G dJ dKe      ZO ed e%       fd& e@       fd. eA       fd eO       fd eN       fg      ZP G dL dMe      ZQ edN e!       fd e"       fg      ZR G dO dPe      ZS edN e!       fd e$       fd e&       fg      ZT G dQ dRe      ZU ed e*       fd e)dg*      fg      ZV G dS dTe      ZW ed eS       fd& eU       fd eW       fd e       fd e       fd e
       fd e       fd e/       fg      ZX edN e!       fde#fd e&dUdV      fg      ZY G dW dXe      ZZ ed eS       fd& eZ       fd e4       fd e       fd e       fd' e6       fd e
       fd e       fd e8       fg	      Z[ G dY dZe      Z\ G d[ d\e      Z] ed e       fd e       fd e
       fg      Z^ G d] d^e      Z_ ed e       fd e       fd' e6       fd e
       fg      Z` G d_ d`e      Za G da dbe      Zb G dc dde      Zc G de dfe      Zd ed eS       fd& e\       fd ed       fd eN       fg      Ze G dg dhe      Zf edN e       fd e        fg      Zg G di dje      Zh edN e       fd e       fd e&       fg      Zi G dk dle      Zj ed eh       fd& ej       fd eW       fd e       fd e       fd e
       fd e       fd e/       fg      Zk G dm dne      Zl G do dpe      Zm G dq dre      Zn ed eh       fd& em       fd en       fd eN       fg      Zo G ds dte      Zpe0e>eXe[eke9e?ePeeeodu
Zqyv)w   )logging   )AutoPipelineBlocksSequentialPipelineBlocks)InsertableDict   )%QwenImageControlNetBeforeDenoiserStepQwenImageCreateMaskLatentsStepQwenImageEditRoPEInputsStepQwenImagePrepareLatentsStep'QwenImagePrepareLatentsWithStrengthStepQwenImageRoPEInputsStepQwenImageSetTimestepsStep%QwenImageSetTimestepsWithStrengthStep)QwenImageDecoderStep'QwenImageInpaintProcessImagesOutputStep QwenImageProcessImagesOutputStep)QwenImageControlNetDenoiseStepQwenImageDenoiseStepQwenImageEditDenoiseStepQwenImageEditInpaintDenoiseStep%QwenImageInpaintControlNetDenoiseStepQwenImageInpaintDenoiseStep%QwenImageLoopBeforeDenoiserControlNet)
!QwenImageControlNetVaeEncoderStep'QwenImageEditPlusProcessImagesInputStep"QwenImageEditPlusResizeDynamicStep QwenImageEditPlusTextEncoderStepQwenImageEditResizeDynamicStepQwenImageEditTextEncoderStep&QwenImageInpaintProcessImagesInputStepQwenImageProcessImagesInputStepQwenImageTextEncoderStepQwenImageVaeEncoderDynamicStep)QwenImageControlNetInputsStepQwenImageInputsDynamicStepQwenImageTextInputsStepdecodepostprocessc                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageDecodeStep	qwenimagec                      y)NzSDecode step that decodes the latents to images and postprocess the generated image. selfs    ~/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/diffusers/modular_pipelines/qwenimage/modular_blocks.pydescriptionzQwenImageDecodeStep.descriptionJ       d    N)__name__
__module____qualname__
model_nameQwenImageDecodeBlocksvaluesblock_classeskeysblock_namespropertyr2   r.   r4   r1   r+   r+   E   s7    J)002M',,.Ke er4   r+   text_encoderinputprepare_latentsset_timestepsprepare_rope_inputsdenoise
preprocessencodec                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)QwenImageInpaintVaeEncoderStepr,   returnc                      	 y)NzThis step is used for processing image and mask inputs for inpainting tasks. It:
 - Resizes the image to the target size, based on `height` and `width`.
 - Processes and updates `image` and `mask_image`.
 - Creates `image_latents`.r.   r/   s    r1   r2   z*QwenImageInpaintVaeEncoderStep.descriptionp   s    *	
r4   N)r5   r6   r7   r8    QwenImageInpaintVaeEncoderBlocksr:   r;   r<   r=   r>   strr2   r.   r4   r1   rH   rH   k   s<    J4;;=M2779K
S 
 
r4   rH   text_inputsadditional_inputsimage_latentsprocessed_mask_image)image_latent_inputsadditional_batch_inputsc                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageInpaintInputStepr,   c                      y)NzKInput step that prepares the inputs for the inpainting denoising step. It:
r.   r/   s    r1   r2   z%QwenImageInpaintInputStep.description   s    ]r4   N)r5   r6   r7   r8   QwenImageInpaintInputBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   rT   rT      7    J/668M-224KR Rr4   rT   add_noise_to_latentscreate_mask_latentsc                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)"QwenImageInpaintPrepareLatentsStepr,   rI   c                      	 y)NzThis step prepares the latents/image_latents and mask inputs for the inpainting denoising step. It:
 - Add noise to the image latents to create the latents input for the denoiser.
 - Create the pachified latents `mask` based on the processedmask image.
r.   r/   s    r1   r2   z.QwenImageInpaintPrepareLatentsStep.description   s    Y	
r4   N)r5   r6   r7   r8   $QwenImageInpaintPrepareLatentsBlocksr:   r;   r<   r=   r>   rL   r2   r.   r4   r1   r[   r[      s<    J8??AM6;;=K
S 
 
r4   r[   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageInpaintDecodeStepr,   c                      y)NzDecode step that decodes the latents to images and postprocess the generated image, optional apply the mask overally to the original image.r.   r/   s    r1   r2   z&QwenImageInpaintDecodeStep.description   s     ]r4   N)r5   r6   r7   r8   QwenImageInpaintDecodeBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   r_   r_      s7    J0779M.335K] ]r4   r_   vae_encoderprepare_inpaint_latentsc                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)QwenImageImg2ImgVaeEncoderStepr,   rI   c                      y)Nz^Vae encoder step that preprocess andencode the image inputs into their latent representations.r.   r/   s    r1   r2   z*QwenImageImg2ImgVaeEncoderStep.description   s    or4   N)r5   r6   r7   r8    QwenImageImg2ImgVaeEncoderBlocksr:   r;   r<   r=   r>   rL   r2   r.   r4   r1   re   re      s?    J4;;=M2779KpS p pr4   re   )rQ   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageImg2ImgInputStepr,   c                      y)NzHInput step that prepares the inputs for the img2img denoising step. It:
r.   r/   s    r1   r2   z%QwenImageImg2ImgInputStep.description   s    Zr4   N)r5   r6   r7   r8   QwenImageImg2ImgInputBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   ri   ri      rW   r4   ri   prepare_img2img_latentscontrolnet_vae_encodercontrolnet_inputscontrolnet_before_denoisecontrolnet_denoise_loop_beforec                   4    e Zd ZeegZddgZddgZed        Z	y)QwenImageAutoVaeEncoderStepinpaintimg2img
mask_imageimagec                      	 y)NaZ  Vae encoder step that encode the image inputs into their latent representations.
This is an auto pipeline block.
 - `QwenImageInpaintVaeEncoderStep` (inpaint) is used when `mask_image` is provided.
 - `QwenImageImg2ImgVaeEncoderStep` (img2img) is used when `image` is provided.
 - if `mask_image` or `image` is not provided, step will be skipped.r.   r/   s    r1   r2   z'QwenImageAutoVaeEncoderStep.description%      U	
r4   N)
r5   r6   r7   rH   re   r;   r=   block_trigger_inputsr>   r2   r.   r4   r1   rr   rr      s4    35STMi(K('2
 
r4   rr   c                   .    e Zd ZegZdgZdgZed        Zy))QwenImageOptionalControlNetVaeEncoderStep
controlnetcontrol_imagec                      	 y)Na  Vae encoder step that encode the image inputs into their latent representations.
This is an auto pipeline block.
 - `QwenImageControlNetVaeEncoderStep` (controlnet) is used when `control_image` is provided.
 - if `control_image` is not provided, step will be skipped.r.   r/   s    r1   r2   z5QwenImageOptionalControlNetVaeEncoderStep.description6      M	
r4   N)	r5   r6   r7   r   r;   r=   ry   r>   r2   r.   r4   r1   r{   r{   1  s,    67M.K+,
 
r4   r{   c                   6    e Zd ZeeegZg dZg dZe	d        Z
y)QwenImageAutoInputSteprs   rt   
text2imagerP   rO   Nc                      	 y)Na  Input step that standardize the inputs for the denoising step, e.g. make sure inputs have consistent batch size, and patchified. 
 This is an auto pipeline block that works for text2image/inpaint/img2img tasks.
 - `QwenImageInpaintInputStep` (inpaint) is used when `processed_mask_image` is provided.
 - `QwenImageImg2ImgInputStep` (img2img) is used when `image_latents` is provided.
 - `QwenImageTextInputsStep` (text2image) is used when both `processed_mask_image` and `image_latents` are not provided.
r.   r/   s    r1   r2   z"QwenImageAutoInputStep.descriptionI  s    K	
r4   N)r5   r6   r7   rT   ri   r'   r;   r=   ry   r>   r2   r.   r4   r1   r   r   D  s-    .0IKbcM6KJ
 
r4   r   c                   .    e Zd ZegZdgZdgZed        Zy)$QwenImageOptionalControlNetInputStepr|   control_image_latentsc                      	 y)Na
  Controlnet input step that prepare the control_image_latents input.
This is an auto pipeline block.
 - `QwenImageControlNetInputsStep` (controlnet) is used when `control_image_latents` is provided.
 - if `control_image_latents` is not provided, step will be skipped.r.   r/   s    r1   r2   z0QwenImageOptionalControlNetInputStep.descriptionZ      U	
r4   N)	r5   r6   r7   r%   r;   r=   ry   r>   r2   r.   r4   r1   r   r   U  s,    23M.K34
 
r4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)$QwenImageText2ImageBeforeDenoiseStepr,   c                      y)Nz|Before denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step for text2image task.r.   r/   s    r1   r2   z0QwenImageText2ImageBeforeDenoiseStep.descriptionv  s     Nr4   N)r5   r6   r7   r8   &QwenImageText2ImageBeforeDenoiseBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r   q  s7    J:AACM8==?KN Nr4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)!QwenImageInpaintBeforeDenoiseStepr,   c                      y)NzyBefore denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step for inpaint task.r.   r/   s    r1   r2   z-QwenImageInpaintBeforeDenoiseStep.description       Kr4   N)r5   r6   r7   r8   #QwenImageInpaintBeforeDenoiseBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r     7    J7>>@M5::<KK Kr4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)!QwenImageImg2ImgBeforeDenoiseStepr,   c                      y)NzyBefore denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step for img2img task.r.   r/   s    r1   r2   z-QwenImageImg2ImgBeforeDenoiseStep.description  r   r4   N)r5   r6   r7   r8   #QwenImageImg2ImgBeforeDenoiseBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r     r   r4   r   c                   6    e Zd ZeeegZg dZg dZe	d        Z
y)QwenImageAutoBeforeDenoiseStepr   r   c                      	 y)Na  Before denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step.
This is an auto pipeline block that works for text2img, inpainting, img2img tasks.
 - `QwenImageInpaintBeforeDenoiseStep` (inpaint) is used when `processed_mask_image` is provided.
 - `QwenImageImg2ImgBeforeDenoiseStep` (img2img) is used when `image_latents` is provided.
 - `QwenImageText2ImageBeforeDenoiseStep` (text2image) is used when both `processed_mask_image` and `image_latents` are not provided.
r.   r/   s    r1   r2   z*QwenImageAutoBeforeDenoiseStep.description  s    X	
r4   N)r5   r6   r7   r   r   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s1    )),M
 7KJ
 
r4   r   c                   .    e Zd ZegZdgZdgZed        Zy),QwenImageOptionalControlNetBeforeDenoiseStepr|   r   c                      	 y)Na  Controlnet before denoise step that prepare the controlnet input.
This is an auto pipeline block.
 - `QwenImageControlNetBeforeDenoiserStep` (controlnet) is used when `control_image_latents` is provided.
 - if `control_image_latents` is not provided, step will be skipped.r.   r/   s    r1   r2   z8QwenImageOptionalControlNetBeforeDenoiseStep.description  r   r4   N)	r5   r6   r7   r	   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s,    :;M.K34
 
r4   r   c                   4    e Zd ZeegZddgZddgZed        Z	y)"QwenImageControlNetAutoDenoiseStepinpaint_denoiserD   maskNc                      	 y)NaH  Controlnet step during the denoising process. 
 This is an auto pipeline block that works for inpaint and text2image/img2img tasks with controlnet.
 - `QwenImageInpaintControlNetDenoiseStep` (inpaint) is used when `mask` is provided.
 - `QwenImageControlNetDenoiseStep` (text2image/img2img) is used when `mask` is not provided.
r.   r/   s    r1   r2   z.QwenImageControlNetAutoDenoiseStep.description  s    p	
r4   )
r5   r6   r7   r   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s3    :<Z[M$i0K"D>
 
r4   r   c                   6    e Zd ZeeegZg dZg dZe	d        Z
y)QwenImageAutoDenoiseStep)controlnet_denoiser   rD   )r   r   Nc                      	 y)Na  Denoise step that iteratively denoise the latents. 
 This is an auto pipeline block that works for inpaint/text2image/img2img tasks. It also works with controlnet
 - `QwenImageControlNetAutoDenoiseStep` (controlnet) is used when `control_image_latents` is provided.
 - `QwenImageInpaintDenoiseStep` (inpaint) is used when `mask` is provided and `control_image_latents` is not provided.
 - `QwenImageDenoiseStep` (text2image/img2img) is used when `mask` is not provided and `control_image_latents` is not provided.
r.   r/   s    r1   r2   z$QwenImageAutoDenoiseStep.description  s    R	
r4   N)r5   r6   r7   r   r   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s2    *#M
 GKB
 
r4   r   c                   4    e Zd ZeegZddgZddgZed        Z	y)QwenImageAutoDecodeStepinpaint_decoder(   r   Nc                      	 y)NaH  Decode step that decode the latents into images. 
 This is an auto pipeline block that works for inpaint/text2image/img2img tasks, for both QwenImage and QwenImage-Edit.
 - `QwenImageInpaintDecodeStep` (inpaint) is used when `mask` is provided.
 - `QwenImageDecodeStep` (text2image/img2img) is used when `mask` is not provided.
r.   r/   s    r1   r2   z#QwenImageAutoDecodeStep.description  s    e	
r4   )
r5   r6   r7   r_   r+   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s3    /1DEM#X.K"D>
 
r4   r   c                   6    e Zd ZdZeeeeegZ	g dZ
ed        Zy)QwenImageCoreDenoiseStepr,   )r@   controlnet_inputbefore_denoisero   rD   c                      	 y)Na  Core step that performs the denoising process. 
 - `QwenImageAutoInputStep` (input) standardizes the inputs for the denoising step.
 - `QwenImageOptionalControlNetInputStep` (controlnet_input) prepares the controlnet input.
 - `QwenImageAutoBeforeDenoiseStep` (before_denoise) prepares the inputs for the denoising step.
 - `QwenImageOptionalControlNetBeforeDenoiseStep` (controlnet_before_denoise) prepares the controlnet input for the denoising step.
 - `QwenImageAutoDenoiseStep` (denoise) iteratively denoises the latents.
This step support text-to-image, image-to-image, inpainting, and controlnet tasks for QwenImage:
 - for image-to-image generation, you need to provide `image_latents`
 - for inpainting, you need to provide `processed_mask_image` and `image_latents`
 - to run the controlnet workflow, you need to provide `control_image_latents`
 - for text-to-image generation, all you need to provide is prompt embeddingsr.   r/   s    r1   r2   z$QwenImageCoreDenoiseStep.description  s    
^	
r4   N)r5   r6   r7   r8   r   r   r   r   r   r;   r=   r>   r2   r.   r4   r1   r   r     s7    J,&4 M jK
 
r4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageAutoBlocksr,   c                      	 y)Na  Auto Modular pipeline for text-to-image, image-to-image, inpainting, and controlnet tasks using QwenImage.
- for image-to-image generation, you need to provide `image`
- for inpainting, you need to provide `mask_image` and `image`, optionally you can provide `padding_mask_crop` 
- to run the controlnet workflow, you need to provide `control_image`
- for text-to-image generation, all you need to provide is `prompt`r.   r/   s    r1   r2   zQwenImageAutoBlocks.description3  s    T	
r4   N)r5   r6   r7   r8   AUTO_BLOCKSr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r   -  s5    J&&(M""$K
 
r4   r   resizec                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)QwenImageEditVLEncoderStepr,   rI   c                      y)NzNQwenImage-Edit VL encoder step that encode the image an text prompts together.r.   r/   s    r1   r2   z&QwenImageEditVLEncoderStep.descriptionP  s    _r4   N)r5   r6   r7   r8   QwenImageEditVLEncoderBlocksr:   r;   r<   r=   r>   rL   r2   r.   r4   r1   r   r   K  s?    J0779M.335K`S ` `r4   r   c                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)QwenImageEditVaeEncoderStepr,   rI   c                      yNzPVae encoder step that encode the image inputs into their latent representations.r.   r/   s    r1   r2   z'QwenImageEditVaeEncoderStep.descriptiond      ar4   N)r5   r6   r7   r8   QwenImageEditVaeEncoderBlocksr:   r;   r<   r=   r>   rL   r2   r.   r4   r1   r   r   _  s?    J188:M/446KbS b br4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageEditInputStepr,   c                      y)NzEInput step that prepares the inputs for the edit denoising step. It:
r.   r/   s    r1   r2   z"QwenImageEditInputStep.descriptionw  s    Wr4   N)r5   r6   r7   r8   QwenImageEditInputBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r   r  s7    J,335M*//1KR Rr4   r   processed_image)
input_nameoutput_namec                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)"QwenImageEditInpaintVaeEncoderStepr,   rI   c                      	 y)NzThis step is used for processing image and mask inputs for QwenImage-Edit inpaint tasks. It:
 - resize the image for target area (1024 * 1024) while maintaining the aspect ratio.
 - process the resized image and mask image.
 - create image latents.r.   r/   s    r1   r2   z.QwenImageEditInpaintVaeEncoderStep.description  s    '	
r4   N)r5   r6   r7   r8   $QwenImageEditInpaintVaeEncoderBlocksr:   r;   r<   r=   r>   rL   r2   r.   r4   r1   r   r     s<    J8??AM6;;=K
S 
 
r4   r   c                   4    e Zd ZeegZddgZddgZed        Z	y)QwenImageEditAutoVaeEncoderStepedit_inpainteditru   rv   c                      	 y)Na  Vae encoder step that encode the image inputs into their latent representations. 
 This is an auto pipeline block that works for edit and edit_inpaint tasks.
 - `QwenImageEditInpaintVaeEncoderStep` (edit_inpaint) is used when `mask_image` is provided.
 - `QwenImageEditVaeEncoderStep` (edit) is used when `image` is provided.
 - if `mask_image` or `image` is not provided, step will be skipped.r.   r/   s    r1   r2   z+QwenImageEditAutoVaeEncoderStep.description  rx   r4   N)
r5   r6   r7   r   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s8    *#M "6*K('2
 
r4   r   c                   4    e Zd ZeegZddgZddgZed        Z	y)QwenImageEditAutoInputStepr   r   rP   rO   c                      	 y)Na  Input step that prepares the inputs for the edit denoising step.
 It is an auto pipeline block that works for edit and edit_inpaint tasks.
 - `QwenImageInpaintInputStep` (edit_inpaint) is used when `processed_mask_image` is provided.
 - `QwenImageEditInputStep` (edit) is used when `image_latents` is provided.
 - if `processed_mask_image` or `image_latents` is not provided, step will be skipped.r.   r/   s    r1   r2   z&QwenImageEditAutoInputStep.description      g	
r4   N)
r5   r6   r7   rT   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s4    .0FGM!6*K2OD
 
r4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageEditBeforeDenoiseStepr,   c                      y)NzvBefore denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step for edit task.r.   r/   s    r1   r2   z*QwenImageEditBeforeDenoiseStep.description  s     Hr4   N)r5   r6   r7   r8    QwenImageEditBeforeDenoiseBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r     s7    J4;;=M2779KH Hr4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)%QwenImageEditInpaintBeforeDenoiseStepr,   c                      y)Nz~Before denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step for edit inpaint task.r.   r/   s    r1   r2   z1QwenImageEditInpaintBeforeDenoiseStep.description  s     Pr4   N)r5   r6   r7   r8   'QwenImageEditInpaintBeforeDenoiseBlocksr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r     s7    J;BBDM9>>@KP Pr4   r   c                   8    e Zd ZdZeegZddgZddgZe	d        Z
y)"QwenImageEditAutoBeforeDenoiseStepqwenimage-editr   r   rP   rO   c                      	 y)Na  Before denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step.
This is an auto pipeline block that works for edit (img2img) and edit inpaint tasks.
 - `QwenImageEditInpaintBeforeDenoiseStep` (edit_inpaint) is used when `processed_mask_image` is provided.
 - `QwenImageEditBeforeDenoiseStep` (edit) is used when `image_latents` is provided and `processed_mask_image` is not provided.
 - if `image_latents` or `processed_mask_image` is not provided, step will be skipped.r.   r/   s    r1   r2   z.QwenImageEditAutoBeforeDenoiseStep.description  r   r4   N)r5   r6   r7   r8   r   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s=    !J-&M "6*K2OD
 
r4   r   c                   8    e Zd ZdZeegZddgZddgZe	d        Z
y)QwenImageEditAutoDenoiseStepr   r   rD   rP   rO   c                      	 y)Na  Denoise step that iteratively denoise the latents. 
This block supports edit (img2img) and edit inpaint tasks for QwenImage Edit. 
 - `QwenImageEditInpaintDenoiseStep` (inpaint) is used when `processed_mask_image` is provided.
 - `QwenImageEditDenoiseStep` (img2img) is used when `image_latents` is provided.
 - if `processed_mask_image` or `image_latents` is not provided, step will be skipped.r.   r/   s    r1   r2   z(QwenImageEditAutoDenoiseStep.description1  r   r4   N)r5   r6   r7   r8   r   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r   *  s9    !J46NOM$i0K2OD
 
r4   r   c                   2    e Zd ZdZeeegZg dZe	d        Z
y)QwenImageEditCoreDenoiseStepr   r@   r   rD   c                      	 y)Na2  Core step that performs the denoising process. 
 - `QwenImageEditAutoInputStep` (input) standardizes the inputs for the denoising step.
 - `QwenImageEditAutoBeforeDenoiseStep` (before_denoise) prepares the inputs for the denoising step.
 - `QwenImageEditAutoDenoiseStep` (denoise) iteratively denoises the latents.

This step support edit (img2img) and edit inpainting workflow for QwenImage Edit:
 - When `processed_mask_image` is provided, it will be used for edit inpainting task.
 - When `image_latents` is provided, it will be used for edit (img2img) task.
r.   r/   s    r1   r2   z(QwenImageEditCoreDenoiseStep.descriptionH  s    `	
r4   N)r5   r6   r7   r8   r   r   r   r;   r=   r>   r2   r.   r4   r1   r   r   ?  s0    !J"*$M
 9K	
 	
r4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageEditAutoBlocksr   c                      	 y)Na  Auto Modular pipeline for edit (img2img) and edit inpaint tasks using QwenImage-Edit.
- for edit (img2img) generation, you need to provide `image`
- for edit inpainting, you need to provide `mask_image` and `image`, optionally you can provide `padding_mask_crop` 
r.   r/   s    r1   r2   z#QwenImageEditAutoBlocks.descriptiond  s    G	
r4   N)r5   r6   r7   r8   EDIT_AUTO_BLOCKSr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r   _  s5    !J$++-M"'')K
 
r4   r   c                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)QwenImageEditPlusVLEncoderStepr,   rI   c                      y)NzSQwenImage-Edit Plus VL encoder step that encode the image an text prompts together.r.   r/   s    r1   r2   z*QwenImageEditPlusVLEncoderStep.description  r3   r4   N)r5   r6   r7   r8    QwenImageEditPlusVLEncoderBlocksr:   r;   r<   r=   r>   rL   r2   r.   r4   r1   r   r   |  s?    J4;;=M2779KeS e er4   r   c                   f    e Zd ZdZej                         Zej                         Ze	de
fd       Zy)QwenImageEditPlusVaeEncoderStepr,   rI   c                      yr   r.   r/   s    r1   r2   z+QwenImageEditPlusVaeEncoderStep.description  r   r4   N)r5   r6   r7   r8   !QwenImageEditPlusVaeEncoderBlocksr:   r;   r<   r=   r>   rL   r2   r.   r4   r1   r   r     s?    J5<<>M388:KbS b br4   r   c                   2    e Zd ZdZegZdgZdgZed        Z	y)&QwenImageEditPlusAutoBeforeDenoiseStepqwenimage-edit-plusr   rO   c                      	 y)Nah  Before denoise step that prepare the inputs (timesteps, latents, rope inputs etc.) for the denoise step.
This is an auto pipeline block that works for edit (img2img) task.
 - `QwenImageEditBeforeDenoiseStep` (edit) is used when `image_latents` is provided and `processed_mask_image` is not provided.
 - if `image_latents` is not provided, step will be skipped.r.   r/   s    r1   r2   z2QwenImageEditPlusAutoBeforeDenoiseStep.description  r   r4   N)
r5   r6   r7   r8   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s1    &J34M(K+,
 
r4   r   c                   .    e Zd ZegZdgZdgZed        Zy)#QwenImageEditPlusAutoVaeEncoderStepr   rv   c                      	 y)Na  Vae encoder step that encode the image inputs into their latent representations. 
 This is an auto pipeline block that works for edit task.
 - `QwenImageEditPlusVaeEncoderStep` (edit) is used when `image` is provided.
 - if `image` is not provided, step will be skipped.r.   r/   s    r1   r2   z/QwenImageEditPlusAutoVaeEncoderStep.description  s    E	
r4   N)	r5   r6   r7   r   r;   r=   ry   r>   r2   r.   r4   r1   r   r     s/    'M (K#9
 
r4   r   c                   2    e Zd ZdZeeegZg dZe	d        Z
y) QwenImageEditPlusCoreDenoiseStepr   r   c                      	 y)Na  Core step that performs the denoising process. 
 - `QwenImageEditAutoInputStep` (input) standardizes the inputs for the denoising step.
 - `QwenImageEditPlusAutoBeforeDenoiseStep` (before_denoise) prepares the inputs for the denoising step.
 - `QwenImageEditAutoDenoiseStep` (denoise) iteratively denoises the latents.

This step support edit (img2img) workflow for QwenImage Edit Plus:
 - When `image_latents` is provided, it will be used for edit (img2img) task.
r.   r/   s    r1   r2   z,QwenImageEditPlusCoreDenoiseStep.description  s    `	
r4   N)r5   r6   r7   r8   r   r   r   r;   r=   r>   r2   r.   r4   r1   r   r     s0    &J".$M
 9K
 
r4   r   c                   `    e Zd ZdZej                         Zej                         Ze	d        Z
y)QwenImageEditPlusAutoBlocksr   c                      	 y)NzAuto Modular pipeline for edit (img2img) and edit tasks using QwenImage-Edit Plus.
- for edit (img2img) generation, you need to provide `image`
r.   r/   s    r1   r2   z'QwenImageEditPlusAutoBlocks.description  s    O	
r4   N)r5   r6   r7   r8   EDIT_PLUS_AUTO_BLOCKSr:   r;   r<   r=   r>   r2   r.   r4   r1   r   r     s5    &J)002M',,.K
 
r4   r   )
r   rt   r   r   	edit_plusrs   r|   auto	edit_autoedit_plus_autoN)rutilsr   modular_pipeliner   r   modular_pipeline_utilsr   r   r	   r
   r   r   r   r   r   r   decodersr   r   r   rD   r   r   r   r   r   r   r   encodersr   r   r   r   r   r    r!   r"   r#   r$   inputsr%   r&   r'   
get_loggerr5   loggerr9   r+   TEXT2IMAGE_BLOCKSrK   rH   rV   rT   r]   r[   ra   r_   INPAINT_BLOCKSrg   re   rk   ri   IMAGE2IMAGE_BLOCKSCONTROLNET_BLOCKSrr   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   EDIT_BLOCKSr   r   EDIT_INPAINT_BLOCKSr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   EDIT_PLUS_BLOCKSr   r   r   r   r   
ALL_BLOCKSr.   r4   r1   <module>r     s
    K 3	 	 	 v u     g f 
		H	% '	')*	8:; e2 e #	134	)+,	79:	356	 7 9:	(*+	&()
   $2 2	
 
134$  
%= 
  -	/12&%4$5PfOg	

 	R 8 	R (6	!H!JK	 > @A( $
)A 
  .	')*	?AB  ]!9 ]  	134	689	+-.	79:	?AB	"$F$HI	 7 9:	/12	-/0
$ $2	689	134$  p%= p -	/12	8oM^_` 	R 8 	R $	134	689	+-.	79:	?AB	"$K$MN	 7 9:	(*+	&()
 $ #	!#D#FG	;=>'13	

 -13	
 (
"4 
"
0B 
&
/ 
"
+= 
& *8	79:	356	 7 9:* &N+C N '5	79:	?AB	"$F$HI	 7 9:	' #K(@ K '5	79:	?AB	"$K$MN	 7 9:	' #K(@ K
%7 
*
3E 
&
); 
 
1 
0
0 

7 
: 	134	356	!#L#NO	,./	*,-
2 
,  .	134	/12  `!9 ` !/	134	689	134! b": b *	/12	8oM^_` 
R5 
R 	356	356	(*+	79:	356	 ; =>	,./	&()	" (6	1342	

 *6GUde	

( $
)A 
  %	356	:<=	+-.	79:	?AB	"$F$HI	 ; =>	356	-/0
 $
&8 
(
!3 
( $2	79:	356	 ; =>$  H%= H +9	79:	?AB	"$F$HI	 ; =>	+ 'P,D P
); 
.
#5 
*
#; 
, "	356	79:	023	*,-	 
6 
* $2	578	356$  e%= e %3	578	>@A	134% !b&> b "	79:	79:	(*+	79:	356	 ; =>	,./	&()	 
-? 
&
*< 
(
'? 
* '	79:	;=>	467	*,-	 

": 

" $!'!#!+
r4   