o
    ia                     @   s   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 de	j
ZG dd de	j
ZG d	d
 d
e	j
ZG dd de	j
ZG dd deZdefd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                   @   s&   e Zd Zedd ZedddZdS )StableCascade_EmptyLatentImagec                 C   s~   t jddt jjdddtjddt jjdddtjddt jjd	d
dddddt jjdddddgt jjddt jjddgdS )Nr   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cls r)   ?/mnt/c/Users/fbmor/ComfyUI/comfy_extras/nodes_stable_cascade.pydefine_schema   s   z,StableCascade_EmptyLatentImage.define_schemar   c                 C   sH   t |d|| || g}t |d|d |d g}td|id|iS )N   r   samples)torchzerosr   
NodeOutput)r(   r   r   r   r   c_latentb_latentr)   r)   r*   execute-   s   z&StableCascade_EmptyLatentImage.executeN)r   __name__
__module____qualname__classmethodr+   r3   r)   r)   r)   r*   r      s
    
r   c                   @   $   e Zd Zedd Zedd ZdS )StableCascade_StageC_VAEEncodec                 C   sT   t jddt jdt jdt jjddddd	d
dgt jjddt jjddgdS )Nr:   r   imagevaer   r   r   r   r   Tr   r   r   r   r   )r   r    Imager"   Vaer!   r%   r&   r'   r)   r)   r*   r+   9   s   

z,StableCascade_StageC_VAEEncode.define_schemac                 C   s   |j d }|j d }|| |j }|| |j }tj|dd||dddd}||d d d d d d d df }	t|	j d d	|d
 d |d
 d g}
t	
d|	id|
iS )Nr   bicubiccenter   r   r   r	      r-   )shapedownscale_ratiocomfyutilscommon_upscalemovedimencoder.   r/   r   r0   )r(   r;   r<   r   r   r   	out_width
out_heightsr1   r2   r)   r)   r*   r3   I   s   

$&(z&StableCascade_StageC_VAEEncode.executeNr4   r)   r)   r)   r*   r:   8   s
    
r:   c                   @   r9   )!StableCascade_StageB_Conditioningc                 C   s.   t jddt jdt jdgt j gdS )NrP   zconditioning/stable_cascadeconditioningr   r   )r   r    Conditioningr"   r%   r&   r'   r)   r)   r*   r+   \   s   

z/StableCascade_StageB_Conditioning.define_schemac                 C   sF   g }|D ]}|d   }|d |d< |d |g}|| qt|S )Nr   r-   stable_cascade_priorr   )copyappendr   r0   )r(   rQ   r   ctdnr)   r)   r*   r3   j   s   
z)StableCascade_StageB_Conditioning.executeNr4   r)   r)   r)   r*   rP   [   s
    
rP   c                   @   r9   )'StableCascade_SuperResolutionControlnetc              
   C   sL   t jdddt jdt jdgt jjddt jjddt jjd	dgd
S )NrZ   z_for_testing/stable_cascadeTr;   r<   controlnet_inputr   r   r   )r   r   is_experimentalr   r   )r   r    r=   r"   r>   r&   r%   r'   r)   r)   r*   r+   v   s   

z5StableCascade_SuperResolutionControlnet.define_schemac           	      C   s   |j d }|j d }|j d }||d d d d d d d df dd}t|d|d |d g}t|d|d	 |d	 g}t|d
|id
|iS )Nr?   r@   r   rD   r   rA   r,   r   rE   r-   )rF   rL   rK   r.   r/   r   r0   )	r(   r;   r<   r   r   r   r[   r1   r2   r)   r)   r*   r3      s   


.z/StableCascade_SuperResolutionControlnet.executeNr4   r)   r)   r)   r*   rZ   u   s
    
rZ   c                   @   s(   e Zd Zedeeej  fddZdS )StableCascadeExtensionreturnc                    s   t tttgS N)r   rP   r:   rZ   )selfr)   r)   r*   get_node_list   s   z$StableCascadeExtension.get_node_listN)	r5   r6   r7   r   listtyper   	ComfyNodera   r)   r)   r)   r*   r]      s    r]   r^   c                      s   t  S r_   )r]   r)   r)   r)   r*   comfy_entrypoint   s   re   )__doc__r.   typing_extensionsr   comfy.utilsrH   r#   comfy_api.latestr   r   rd   r   r:   rP   rZ   r]   re   r)   r)   r)   r*   <module>   s    #"
