
    +j                         d Z ddlZddlmZ ddlZddlZddlmZm	Z	  G d de	j
                  Z G d de	j
                  Z G d	 d
e	j
                  Z G d de	j
                  Z G d de          ZdefdZdS )a  
    This file is part of ComfyUI.
    Copyright (C) 2024 Stability AI

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
    N)override)ComfyExtensionioc                   <    e Zd Zed             Zedd            ZdS )StableCascade_EmptyLatentImagec                    t          j        ddt           j                            dddt          j        d          t           j                            dddt          j        d          t           j                            d	d
dddd          t           j                            dddd          gt           j                            d          t           j                            d          g          S )Nr   model/latent/stable_cascadewidthi         )defaultminmaxstepheightcompression*            Tr   r   r   r   advanced
batch_sizei   )r   r   r   stage_cdisplay_namestage_bnode_idcategoryinputsoutputs)r   SchemaIntInputnodesMAX_RESOLUTIONLatentOutputclss    A/home/wildlama/comfy/ComfyUI/comfy_extras/nodes_stable_cascade.pydefine_schemaz,StableCascade_EmptyLatentImage.define_schema   s    y42WdAU\]^^Xt%BV]^__]BA3QY]^^\1!FF	 	  i 88	  i 88
 
 
 	
    r   c                     t          j        |d||z  ||z  g          }t          j        |d|dz  |dz  g          }t          j        d|id|i          S )N   r   samples)torchzerosr   
NodeOutput)r+   r
   r   r   r   c_latentb_latents          r,   executez&StableCascade_EmptyLatentImage.execute-   so    ;
B+0EuP[G[\]];
Av{EQJGHH}x
 x
  	r.   N)r   __name__
__module____qualname__classmethodr-   r7    r.   r,   r   r      sM        
 
 [
     [  r.   r   c                   :    e Zd Zed             Zed             ZdS )StableCascade_StageC_VAEEncodec                 n   t          j        ddt           j                            d          t           j                            d          t           j                            ddddd	d
          gt           j                            d          t           j                            d          g          S )Nr?   r	   imagevaer   r   r   r   r   Tr   r   r   r   r   )r   r#   Imager%   Vaer$   r(   r)   r*   s    r,   r-   z,StableCascade_StageC_VAEEncode.define_schema9   s    y42w''U##]BA3QY]^^ 	  i 88	  i 88
 
 
 	
r.   c                    |j         d         }|j         d         }||z  |j        z  }||z  |j        z  }t          j                            |                    dd          ||dd                              dd          }|                    |d d d d d d d df                   }	t          j        |	j         d         d	|d
z  dz  |d
z  dz  g          }
t          j
        d|	id|
i          S )Nr   bicubiccenter   r   r   r      r1   )shapedownscale_ratiocomfyutilscommon_upscalemovedimencoder2   r3   r   r4   )r+   rA   rB   r   r
   r   	out_width
out_heightsr5   r6   s              r,   r7   z&StableCascade_StageC_VAEEncode.executeI   s   BRk)S-@@	+s/BB
K&&u}}R':':IzS\^fggoopqrtuu::a!!!AAAbqbk**;q 11v{a6G%ST*XYIYZ[[}x
 x
  	r.   Nr8   r=   r.   r,   r?   r?   8   sH        
 
 [
   [  r.   r?   c                   :    e Zd Zed             Zed             ZdS )!StableCascade_StageB_Conditioningc                     t          j        ddt           j                            d          t           j                            d          gt           j                                        g          S )NrX   z!model/conditioning/stable_cascadeconditioningr   r   )r   r#   Conditioningr%   r(   r)   r*   s    r,   r-   z/StableCascade_StageB_Conditioning.define_schema\   sb    y78%%n55		**
 &&((

 

 

 
	
r.   c                     g }|D ]F}|d                                          }|d         |d<   |d         |g}|                    |           Gt          j        |          S )Nr   r1   stable_cascade_priorr   )copyappendr   r4   )r+   rZ   r   ctdns          r,   r7   z)StableCascade_StageB_Conditioning.executej   se     	 	A!		A(/	(:A$%1q	AHHQKKKK}Qr.   Nr8   r=   r.   r,   rX   rX   [   sH        
 
 [
     [     r.   rX   c                   :    e Zd Zed             Zed             ZdS )'StableCascade_SuperResolutionControlnetc                 f   t          j        dddt           j                            d          t           j                            d          gt           j                            d          t           j                            d          t           j                            d	          g
          S )Nre   zexperimental/stable_cascadeTrA   rB   controlnet_inputr   r   r   )r   r    is_experimentalr!   r"   )r   r#   rC   r%   rD   r)   r(   r*   s    r,   r-   z5StableCascade_SuperResolutionControlnet.define_schemav   s    y=2 w''U##
 -?@@	  i 88	  i 88
 
 
 	
r.   c                 r   |j         d         }|j         d         }|j         d         }|                    |d d d d d d d df                                       dd          }t          j        |d|dz  |dz  g          }t          j        |d|d	z  |d	z  g          }t          j        |d
|id
|i          S )NrF   rG   r   rK   r   rH   r0   r   rL   r1   )rM   rS   rR   r2   r3   r   r4   )	r+   rA   rB   r
   r   r   rg   r5   r6   s	            r,   r7   z/StableCascade_SuperResolutionControlnet.execute   s    BR[^
::eAAAaaa"1"Ho66>>q"EE;
B"erkJKK;
Av{EQJGHH}-x0
 x
  	r.   Nr8   r=   r.   r,   re   re   u   sH        
 
 [
    [  r.   re   c                   L    e Zd Zedeeej                          fd            ZdS )StableCascadeExtensionreturnc                 :   K   t           t          t          t          gS N)r   rX   r?   re   )selfs    r,   get_node_listz$StableCascadeExtension.get_node_list   s       +-*3	
 	
r.   N)	r9   r:   r;   r   listtyper   	ComfyNoderp   r=   r.   r,   rk   rk      sE        
T$r|*<%= 
 
 
 X
 
 
r.   rk   rl   c                  "   K   t                      S rn   )rk   r=   r.   r,   comfy_entrypointru      s      !###r.   )__doc__r2   typing_extensionsr   comfy.utilsrO   r&   comfy_api.latestr   r   rs   r   r?   rX   re   rk   ru   r=   r.   r,   <module>rz      s[   $  & & & & & &      / / / / / / / /    R\   :         R\      F               4    bl   D
 
 
 
 
^ 
 
 
$ 6 $ $ $ $ $ $r.   