
    
3jd                     B   S SK r S SKrS SKrS SKrS SKJrJr  S SKJr  S SK	J
r
JrJr  S SKJrJrJrJr  SSKJr  SS	KJrJr  \R.                  " \5      rS
\S\4S jr0 SSSSS/S._SSSSS/S._SSSSS/S._SSSSS/S._SSSSS/S._SSSSS/S._SSSSS._S SSSSS!S"/S#/S$.SS#/S%._S&S'S&SS._S(S)S(SS(/S._S*S+S,S-S.S*/S/._S0S1S,S-S.S0/S/._S2S3S4S5S6S7S8S9S:._S#S;S4S<S=S7S>S#/S?._S!S@SASBSCSDS!/SE._S"SFSASBSCSDS"/SE._SGSHSAS S SISJSK/SL._0 SMSNSASOSSPS5SM/SL._SQSRSASSSSTS5SQ/SL._SUSVSASWSSXS5SU/SL._SYSZS[S\/ S]QS^._S_S`S4S<S=S7S>S_/S?._SaSbS4S=S=S7S>Sa/S?._ScSdS4S7S=S7S>Sc/S?._SeSfSgSSe/S._ShSiSjSSh/S._SkSlSjSSk/S._SmSnSjSS._SoSpSjSS._SqSrSjSSq/S._SsStSuSSv/S._SwSxSySSzS._S{S|S}SS._S~SSSS2// S.S._ESSS,SS.0Er " S S\5      r\" SS9 " S S\S95       rSSS\4S jr SSS\4S jr!S\RE                  SS9\RG                  5       \RI                  5       \RK                  5       \RM                  5       \RO                  5       \RQ                  5       \RS                  5       \RU                  5       \RW                  5       \RY                  5       \R[                  SS9/\R]                  5       \R_                  5       \Ra                  5       /\Rc                  SS9\Re                  5       \Rg                  5       /S&/SmSo/SS.\Ri                  5       /\Rk                  5       /\RW                  SS9\Rg                  5       /S/Sh/SS.\Rm                  5       \Ro                  5       /\Rq                  5       /\RE                  SS9\Rg                  5       /S*/Ss/SvS.\Rc                  SS9/\Rk                  5       /\Rs                  5       \Ru                  5       \Rg                  5       /S/Sh/SS.S.r;SS\S\S\4S jjr<S\=\\4   S\S\=\\4   4S jr> " S S5      r?g)    N)asdict	dataclass)Any)create_repohf_hub_downloadupload_file)EntryNotFoundErrorHfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError   )HUGGINGFACE_CO_RESOLVE_ENDPOINT   )
InputParamOutputParamnamereturnc                 B    U R                  SS5      R                  5       $ )z,Convert snake_case name to Title Case label._ )replacetitle)r   s    g/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/modular_pipelines/mellon_node_utils.py_name_to_labelr      s    <<S!''))    imageImageinput)labeltypedisplayrequired_block_paramsimagesImagesoutputcontrol_imagezControl ImagelatentsLatentsimage_latentszImage Latentsfirst_frame_latentszFirst Frame Latentslatents_previewzLatents Previewlatent)r   r    r!   image_latents_with_strengthheightwidthstrength)falsetrue)r   r   r    r!   onChanger"   
embeddingszText Embeddingsimage_embedszImage EmbeddingspromptPromptstringtextarea )r   r    r!   defaultr"   negative_promptzNegative Promptguidance_scalezGuidance Scalefloatsliderg      @g      ?g      >@g?)r   r    r!   r;   minmaxstepStrengthg      ?g        {Gz?)r   r    r;   r@   rA   rB   r"   Heightinti   @      )r   r    r;   r@   rB   r"   WidthseedSeed    random	generator)r   r    r;   r@   rA   r!   r"   num_inference_stepsSteps   d   
num_framesFramesQ   i  layersLayers   
   output_typezOutput Typedropdownnp)r\   pilpt)r   r    r;   optionscontrolnet_conditioning_scalezControlnet Conditioning Scalecontrol_guidance_startzControl Guidance Startcontrol_guidance_endzControl Guidance EndvideosVideosvideovaeVAEdiffusers_auto_modelimage_encoderzImage EncoderunetzDenoise Model	scheduler	Scheduler
controlnetzControlNet Modeltext_encoderszText Encodersdiffusers_auto_modelstext_encodercontrolnet_bundle
ControlNetcustom_controlnetcontrolnet_image
ip_adapterz
IP Adaptercustom_ip_adapterguiderGuidercustom_guider)FT)r   r    r!   r3   docDocc                   &    \ rS rSrSrS\4S jrSrg)MellonParamMeta   zEMetaclass that enables MellonParam.template_name(**overrides) syntax.r   c                 N   ^ ^ T[         ;   a  SU U4S jjnU$ [        ST S35      e)Nc                 d   > [         T   nSUR                  ST5      0UEUEnU b  XS'   T" S0 UD6$ )Nr   r;    )MELLON_PARAM_TEMPLATESget)r;   	overridestemplateparamsclsr   s       r   factory,MellonParamMeta.__getattr__.<locals>.factory   sF    1$7 (,,vt"<VVIV&(/9%}V}$r   z,type object 'MellonParam' has no attribute ''N)r   AttributeError)r   r   r   s   `` r   __getattr__MellonParamMeta.__getattr__   s3    ))% % NKD6QRSTTr   r   N)__name__
__module____qualname____firstlineno____doc__strr   __static_attributes__r   r   r   r}   r}      s    OUs Ur   r}   T)frozenc                   L   \ rS rSr% Sr\\S'   \\S'   \\S'   Sr\S-  \S'   Sr\	\S'   Sr
\S-  \S	'   Sr\S-  \S
'   Sr\S-  \S'   Sr\	\S'   Sr\	\S'   Sr\\\	4   S-  \S'   Sr\	\S'   Sr\	\S'   Sr\\\   -  S-  \S'   S\\\	4   4S jr " S S5      r " S S5      rSrg)MellonParam   a4  
    Parameter definition for Mellon nodes.

    Usage:
```python
    # From template (standard diffuser params)
    MellonParam.seed()
    MellonParam.prompt(default="a cat")
    MellonParam.latents(display="output")

    # Generic inputs (for custom blocks)
    MellonParam.Input.slider("my_scale", default=1.0, min=0.0, max=2.0)
    MellonParam.Input.dropdown("mode", options=["fast", "slow"])

    # Generic outputs
    MellonParam.Output.image("result_images")

    # Fully custom
    MellonParam(name="custom", label="Custom", type="float", default=0.5)
```
r   r   r    Nr!   r;   r@   rA   rB   r_   valuefieldOptionsr3   onSignalr"   r   c                     [        U 5      nUR                  5        VVs0 s H  u  p#Uc  M
  US;  d  M  X#_M     snn$ s  snnf )zMConvert to dict for Mellon schema, excluding None values and internal fields.)r   r"   )r   items)selfdatakvs       r   to_dictMellonParam.to_dict%  s;    d|!%n1LmCmnnns   	>>>c                   n   \ rS rSrSr\S\SS4S j5       r\SS\S\SS4S jj5       r\SS\S
\	\   S\SS4S jj5       r
\ SS\S\S\S\S\SS4S jj5       r\ SS\S\S\S\S\SS4S jj5       r\SS\S\SS4S jj5       r\SS\S\SS4S jj5       r\S\S\SS4S j5       r\S\SS4S j5       rSrg	)MellonParam.Inputi-  z$input UI elements for custom blocks.r   r   r   c                 ,    [        U[        U5      SSS9$ )zimage input.r   r   r   r   r    r!   r   r   r   r   s     r   r   MellonParam.Input.image0  s     Dt0D7\cddr   r;   c                 .    [        U[        U5      SSUS9$ )ztext input as textarea.r8   r9   )r   r   r    r!   r;   r   r   r   r;   s      r   textboxMellonParam.Input.textbox5  s"     !5Hjbi r   Nr_   c                 x    U(       a  U(       d  US   nU(       d  SnU(       d  U/n[        U[        U5      SX#S9$ )zdropdown selection.r   r:   r8   )r   r   r    r_   r   r   )r   r   r_   r;   s       r   r[   MellonParam.Input.dropdown<  s;     w!!*")Dt0D8]dttr   r@   rA   rB   c                     [        U[        5      =(       d    USL=(       a    [        U[        5      nU(       a  SOSnUc  UnUc  UnUc  U(       a  SOSn[        U[        U5      USUUUUS9$ )zslider input.Nr>   rF   rD   r   r?   )r   r   r    r!   r;   r@   rA   rB   
isinstancer>   r   r   r   r   r;   r@   rA   rB   is_float
param_types           r   r?   MellonParam.Input.sliderG  s}    
 "'51cd$6F6b:VZ\aKbH$,%J{{|'tQ$T* 	 	r   c           
          [        U[        5      =(       d    USL=(       a    [        U[        5      nU(       a  SOSn[        U[        U5      XrX4US9$ )znumber input (no slider).Nr>   rF   )r   r   r    r;   r@   rA   rB   r   r   s           r   numberMellonParam.Input.number_  sP    
 "'51cd$6F6b:VZ\aKbH$,%J!5J]`pt r   c           
      2    [        U[        U5      SSUSSS9$ )z!seed input with randomize button.rF   rM   r   rL   )r   r   r    r!   r;   r@   rA   r   r   s      r   rJ   MellonParam.Input.seedj  s+     $T*  r   c                 ,    [        U[        U5      SUS9$ )zboolean checkbox.boolean)r   r   r    r   r   r   s      r   checkboxMellonParam.Input.checkboxw  s     Dt0D9\cddr   r    c                 ,    [        U[        U5      USS9$ )z'custom type input for node connections.r   r   r   r   r   r    s      r   custom_typeMellonParam.Input.custom_type|  s     Dt0D4Y`aar   c                 ,    [        U[        U5      SSS9$ )z%model input for diffusers components.rh   r   r   r   r   s     r   modelMellonParam.Input.model  s     Dt0DKakrssr   r   )r:   )NN)r   NNN)rJ   r   F)r   r   r   r   r   classmethodr   r   r   listr[   r>   r?   r   rF   rJ   boolr   r   r   r   r   r   r   Inputr   -  s   2		eS 	e] 	e 
	e 
	s 	S 	- 	 
	 
	u 	ud3i 	u 	uXe 	u 
	u 
dh		%*	5:	HM	\a		 
	. 
dh		%*	5:	HM	\a		 
	 

	C 
	3 
	} 
	 

	 
	e 	ed 	e} 	e 
	e 
	b3 	bc 	bm 	b 
	b 
	tS 	t] 	t 
	tr   r   c                       \ rS rSrSr\S\SS4S j5       r\S\SS4S j5       r\S\SS4S j5       r	\S\S	\SS4S
 j5       r
\S\SS4S j5       rSrg)MellonParam.Outputi  z%output UI elements for custom blocks.r   r   r   c                 ,    [        U[        U5      SSS9$ )zimage output.r   r%   r   r   r   s     r   r   MellonParam.Output.image       Dt0D7\deer   c                 ,    [        U[        U5      SSS9$ )zvideo output.re   r%   r   r   r   s     r   re   MellonParam.Output.video  r   r   c                 ,    [        U[        U5      SSS9$ )ztext output.r8   r%   r   r   r   s     r   textMellonParam.Output.text  s     Dt0D8]effr   r    c                 ,    [        U[        U5      USS9$ )z(custom type output for node connections.r%   r   r   r   s      r   r   MellonParam.Output.custom_type  s     Dt0D4Yabbr   c                 ,    [        U[        U5      SSS9$ )z&model output for diffusers components.rh   r%   r   r   r   s     r   r   MellonParam.Output.model  s     Dt0DKaksttr   r   N)r   r   r   r   r   r   r   r   re   r   r   r   r   r   r   r   Outputr     s    3		fS 	f] 	f 
	f 
	fS 	f] 	f 
	f 
	gC 	gM 	g 
	g 
	c3 	cc 	cm 	c 
	c 
	uS 	u] 	u 
	ur   r   r   )r   r   r   r   r   r   __annotations__r!   r;   r   r@   r>   rA   rB   r_   r   r   dictr3   r   r"   r   r   r   r   r   r   r   r   r   r      s    , IJ
IGS4ZGSCCD%$,GSE3*.L$sCx.4'.HcHc483c?T18oc3h oWt Wtxu ur   r   )	metaclassinput_paramr   c                    U R                   nU R                  nU(       a  UR                  S5      OSnU R                  n[	        U[
        5      (       a  U$ UnUS:X  a  [
        R                  R                  U5      $ US:X  a&  [
        R                  R                  X=(       d    SS9$ US:X  a&  [
        R                  R                  X=(       d    SS9$ US:X  a&  [
        R                  R                  X=(       d    S	S9$ US
:X  a&  [
        R                  R                  X=(       d    S	S9$ US:X  a&  [
        R                  R                  X=(       d    S	S9$ US:X  a&  [
        R                  R                  X=(       d    SS9$ US:X  a  [
        R                  R                  U5      $ [
        R                  R                  USS9$ )aH  
Convert an InputParam to a MellonParam using metadata.

Args:
    input_param: An InputParam with optional metadata containing either:
        - {"mellon": "<type>"} for simple types (image, textbox, slider, etc.)
        - {"mellon": MellonParam(...)} for full control over UI configuration

Returns:
    MellonParam instance
mellonNr   r   r:   )r;   r[   r?   r   r   rJ   r   Fr   customr    )r   metadatar   r;   r   r   r   r   r   r[   r?   r   rJ   r   r   r   )r   r   r   mellon_valuer;   mellon_types         r   input_param_to_mellon_paramr     s    D##H-58<<)4L!!G ,,,Kg  &&t,,			!  ((}"(EE	
	"  ))$2)FF		   ''l'CC		   ''l'CC		  %%dLq%AA	
	"  ))$8H5)II		  &&t,,   ,,T,AAr   output_paramr   c                    U R                   nU R                  nU(       a  UR                  S5      OSnUS:X  a  [        R                  R                  U5      $ US:X  a  [        R                  R                  U5      $ US:X  a  [        R                  R                  U5      $ US:X  a  [        R                  R                  U5      $ [        R                  R                  USS9$ )	a  
Convert an OutputParam to a MellonParam using metadata.

Args:
    output_param: An OutputParam with optional metadata={"mellon": "<type>"} where type is one of:
        image, video, text, model. If metadata is None or unknown, maps to "custom".

Returns:
    MellonParam instance
r   Nr   re   r   r   r   r   )
r   r   r   r   r   r   re   r   r   r   )r   r   r   r   s       r   output_param_to_mellon_paramr     s     D$$H,4(,,x($Kg!!''--		!!''--		!!&&t,,		!!''-- !!--d-BBr   )r!   denoiseinputsmodel_inputsoutputsrequired_inputsrequired_model_inputs
block_namevae_encoderdecode)rm   r   r   rp   decoderr   markerc                 >    U R                  U5      (       a  U $ U  U 3$ )z4Add required marker to label if not already present.)endswith)r   r   s     r   mark_requiredr   ?  s%    ~~fWVHr   	node_spec	node_typec                 &   0 n/ n/ n/ nU R                  S/ 5      nU R                  S/ 5      nU R                  S/ 5       H]  nUR                  5       n	UR                  U;   a  [        U	S   5      U	S'   XUR                  '   UR	                  UR                  5        M_     U R                  S/ 5       H]  nUR                  5       n	UR                  U;   a  [        U	S   5      U	S'   XUR                  '   UR	                  UR                  5        M_     U R                  S/ 5       HR  nUR                  U;   a  SUR                   3n
OUR                  n
UR                  5       X*'   UR	                  U
5        MT     UUUUU R                  S5      US	.$ )
a
  
Convert a node spec dict into Mellon format.

A node spec is how we define a Mellon diffusers node in code. This function converts it into the `params` map
format that Mellon UI expects.

The `params` map is a dict where keys are parameter names and values are UI configuration:
    ```python
    {"seed": {"label": "Seed", "type": "int", "default": 0}}
    ```

For Modular Mellon nodes, we need to distinguish:
    - `inputs`: Pipeline inputs (e.g., seed, prompt, image)
    - `model_inputs`: Model components (e.g., unet, vae, scheduler)
    - `outputs`: Node outputs (e.g., latents, images)

The node spec also includes:
    - `required_inputs` / `required_model_inputs`: Which params are required (marked with *)
    - `block_name`: The modular pipeline block this node corresponds to on backend

We provide factory methods for common parameters (e.g., `MellonParam.seed()`, `MellonParam.unet()`) so you don't
have to manually specify all the UI configuration.

Args:
    node_spec: Dict with `inputs`, `model_inputs`, `outputs` (lists of MellonParam),
               plus `required_inputs`, `required_model_inputs`, `block_name`.
    node_type: The node type string (e.g., "denoise", "controlnet")

Returns:
    Dict with:
        - `params`: Flat dict of all params in Mellon UI format
        - `input_names`: List of input parameter names
        - `model_input_names`: List of model input parameter names
        - `output_names`: List of output parameter names
        - `block_name`: The backend block name
        - `node_type`: The node type

Example:
    ```python
    node_spec = {
        "inputs": [MellonParam.seed(), MellonParam.prompt()],
        "model_inputs": [MellonParam.unet()],
        "outputs": [MellonParam.latents(display="output")],
        "required_inputs": ["prompt"],
        "required_model_inputs": ["unet"],
        "block_name": "denoise",
    }

    result = node_spec_to_mellon_dict(node_spec, "denoise")
    # Returns:
    # {
    #     "params": {
    #         "seed": {"label": "Seed", "type": "int", "default": 0},
    #         "prompt": {"label": "Prompt *", "type": "string", "default": ""},  # * marks required
    #         "unet": {"label": "Denoise Model *", "type": "diffusers_auto_model", "display": "input"},
    #         "latents": {"label": "Latents", "type": "latents", "display": "output"},
    #     },
    #     "input_names": ["seed", "prompt"],
    #     "model_input_names": ["unet"],
    #     "output_names": ["latents"],
    #     "block_name": "denoise",
    #     "node_type": "denoise",
    # }
    ```
r   r   r   r   r   r   out_r   )r   input_namesmodel_input_namesoutput_namesr   r   )r   r   r   r   append)r   r   r   r   r   r  r   r   p
param_dictoutput_names              r   node_spec_to_mellon_dictr  F  sz   D FKLmm$5r:O%MM*A2F ]]8R(YY[
66_$"/
70C"DJw#qvv166" ) ]]>2.YY[
66**"/
70C"DJw#qvv  ( / ]]9b)66[  /K&&KiikK( * ".$mmL1 r   c                   6   \ rS rSrSrSr   S S\\\\\4   S-  4   S\S\S\4S	 jjr	\
S
\\\4   4S j5       rS
\4S jrS
\\\4   4S jr\S\\\4   S
S 4S j5       rS
\4S jrS\\R$                  -  4S jr\S\\R$                  -  S
S 4S j5       rS!S\\R$                  -  S\4S jjr\S\\R$                  -  S
S 4S j5       r\    S"S\\\\\4   4   S-  S\S\S\S
S 4
S jj5       r\   S#S\S\\\4   S-  S\\\4   S-  S
S 4S jj5       rSrg)$MellonPipelineConfigi  a.  
Configuration for an entire Mellon pipeline containing multiple nodes.

Accepts node specs as dicts with inputs/model_inputs/outputs lists of MellonParam, converts them to Mellon-ready
format, and handles save/load to Hub.

Example:
    ```python
    config = MellonPipelineConfig(
        node_specs={
            "denoise": {
                "inputs": [MellonParam.seed(), MellonParam.prompt()],
                "model_inputs": [MellonParam.unet()],
                "outputs": [MellonParam.latents(display="output")],
                "required_inputs": ["prompt"],
                "required_model_inputs": ["unet"],
                "block_name": "denoise",
            },
            "decoder": {
                "inputs": [MellonParam.latents(display="input")],
                "outputs": [MellonParam.images()],
                "block_name": "decoder",
            },
        },
        label="My Pipeline",
        default_repo="user/my-pipeline",
        default_dtype="float16",
    )

    # Access Mellon format dict
    denoise = config.node_params["denoise"]
    input_names = denoise["input_names"]
    params = denoise["params"]

    # Save to Hub
    config.save("./my_config", push_to_hub=True, repo_id="user/my-pipeline")

    # Load from Hub
    loaded = MellonPipelineConfig.load("user/my-pipeline")
    ```
zmellon_pipeline_config.json
node_specsNr   default_repodefault_dtypec                 4    Xl         X l        X0l        X@l        g)a  
Args:
    node_specs: Dict mapping node_type to node spec or None.
                Node spec has: inputs, model_inputs, outputs, required_inputs, required_model_inputs,
                block_name (all optional)
    label: Human-readable label for the pipeline
    default_repo: Default HuggingFace repo for this pipeline
    default_dtype: Default dtype (e.g., "float16", "bfloat16")
Nr	  r   r
  r  )r   r	  r   r
  r  s        r   __init__MellonPipelineConfig.__init__  s    " %
(*r   r   c                     U R                   c  U R                  $ 0 nU R                   R                  5        H  u  p#Uc  SX'   M  [        X25      X'   M     U$ )z+Lazily compute node_params from node_specs.N)r	  _node_paramsr   r  )r   r   r   specs       r   node_params MellonPipelineConfig.node_params  sY     ??"$$$#446OI|$(!$<T$M!	  7
 r   c                    SU R                   < SU R                  < SU R                  < S3/nU R                  R	                  5        H  u  p#Uc  UR                  SU S35        M  UR                  S/ 5       Vs/ s H  oDR                  PM     nnUR                  S/ 5       Vs/ s H  oDR                  PM     nnUR                  S	/ 5       Vs/ s H  oDR                  PM     nnUR                  SU S
35        UR                  SU 35        UR                  SU 35        UR                  SU 35        M     SR                  U5      $ s  snf s  snf s  snf )NzMellonPipelineConfig(label=z, default_repo=z, default_dtype=)z  z: Noner   r   r   :z    inputs: z    model_inputs: z    outputs: 
)	r   r
  r  r	  r   r  r   r   join)r   linesr   r  r  r   r   r   s           r   __repr__MellonPipelineConfig.__repr__  sK   )$**tGXGXF[[klpl~l~  lB  BC  D
  $446OI|r)F34*.((8R*@A*@Q&&*@A040LM0L10LM+/88Ir+BC+Ba66+BCr)A./|F8451,@A}WI67  7 yy BMCs   <E'EEc                 `    U R                   U R                  U R                  U R                  S.$ )z*Convert to a JSON-serializable dictionary.r   r
  r  r  r  r   s    r   r   MellonPipelineConfig.to_dict  s0     ZZ --!//++	
 	
r   r   c                     U R                  U 5      nSUl        UR                  S0 5      Ul        UR                  SS5      Ul        UR                  SS5      Ul        UR                  SS5      Ul        U$ )z|
Create from a dictionary (loaded from JSON).

Note: The mellon_params are already in Mellon format when loading from JSON.
Nr  r   r:   r
  r  )__new__r	  r   r  r   r
  r  )r   r   instances      r   	from_dictMellonPipelineConfig.from_dict   sj     ;;s#" $ ;'2. $ <!%/2!>r   c                 P    [         R                  " U R                  5       SSS9S-   $ )zSerialize to JSON string.r   F)indent	sort_keysr  )jsondumpsr   r  s    r   to_json_string#MellonPipelineConfig.to_json_string/  s     zz$,,.eDtKKr   json_file_pathc                     [        USSS9 nUR                  U R                  5       5        SSS5        g! , (       d  f       g= f)zSave to a JSON file.wutf-8encodingN)openwriter+  )r   r-  writers      r   to_json_file!MellonPipelineConfig.to_json_file3  s1    .#8FLL,,./ 988s	    5
Ac                     [        USSS9 n[        R                  " U5      nSSS5        U R                  W5      $ ! , (       d  f       N= f)zLoad from a JSON file.rr0  r1  N)r3  r)  loadr$  )r   r-  readerr   s       r   from_json_file#MellonPipelineConfig.from_json_file8  s=     .#8F99V$D 9}}T"" 98s	   <
A
save_directorypush_to_hubc           	         [         R                  R                  U5      (       a  [        SU S35      e[         R                  " USS9  [         R                  R                  XR                  5      nU R                  U5        [        R                  SU 35        U(       a  UR                  SS5      nUR                  SS5      nUR                  S	S
5      nUR                  SS5      nUR                  SUR                  [         R                  R                  5      S   5      n	[        U	SXhS9R                  n	[        UU R                  U	UU=(       d    SUS9  [        R                  SU	 35        gg)z/Save the mellon pipeline config to a directory.zProvided path (z#) should be a directory, not a fileT)exist_okzPipeline config saved to commit_messageNprivate	create_prFtokenrepo_id)rA  rC  rE  zUpload MellonPipelineConfig)path_or_fileobjpath_in_reporF  rE  rB  rD  zPipeline config pushed to hub: )ospathisfileAssertionErrormakedirsr  config_namer6  loggerinfopopsplitsepr   rF  r   )
r   r>  r?  kwargsoutput_pathrB  rC  rD  rE  rF  s
             r   saveMellonPipelineConfig.save?  s4   77>>.)) ?>2BBe!fgg
NT2ggll>3C3CD+&/}=>#ZZ(8$?NjjD1G

;6IJJw-EjjN,@,@,Mb,QRG!'D'W__G +!---N1N# KK9'CD! r   pretrained_model_name_or_pathc                    UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	S5      nUR                  S
S5      n	UR                  SS5      n
UR                  SS5      n[        U5      n[        R                  R	                  U5      (       a  UnO[        R                  R                  U5      (       ai  [        R                  R                  XR                  5      n[        R                  R	                  U5      (       d  [        SU R                   SU 35      eO [        UU R                  UUUU	UU
UUUS9n U R!                  U5      $ ! [         a    [        U S35      e[         a    [        U
 SU S35      e[         a    [        U SU R                   S35      e[         a  n[        SU SU 35      eSnAf[         a$    [        S[         SU SU R                   S35      e[         a     [        SU SU SU R                   S35      ef = f! ["        R$                  [&        4 a    [        SU S 35      ef = f)!z=Load a pipeline config from a local path or Hugging Face Hub.	cache_dirN	local_dirlocal_dir_use_symlinksautoforce_downloadFproxiesrE  local_files_onlyrevision	subfolderzNo file named z
 found in )
filenamer[  r_  r`  ra  rE  rb  rc  r\  r]  z is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `token` or log in with `hf auth login`.z is not a valid git identifier (branch name, tag name or commit id) that exists for this model name. Check the model page at 'https://huggingface.co/z' for available revisions.z& does not appear to have a file named .z:There was a specific connection error when trying to load z:
zWe couldn't connect to 'zM' to load this model, couldn't find it in the cached files and it looks like z- is not the path to a directory containing a z file.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/diffusers/installation#offline-mode'.zCan't load config for 'z'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'z2' is the correct path to a directory containing a z filezThe config file at 'z' is not a valid JSON file.)rR  r   rJ  rK  rL  isdirr  rO  EnvironmentErrorr   r   r   r	   r
   
ValueErrorr   r<  r)  JSONDecodeErrorUnicodeDecodeError)r   rY  rU  r[  r\  r]  r_  r`  rE  ra  rb  rc  config_fileerrs                 r   r:  MellonPipelineConfig.load[  s    JJ{D1	JJ{D1	!',Df!M$4e<**Y-

7D)!::&8%@::j$/JJ{D1	(+,I(J%77>>7887KWW]]899'',,'DooVK77>>+..&7H
SpRq'rss /1-1 __'#1#%5%''+Ad	d%%k22M + &45 6i i 
 ) &j !00M/NNhj 
 & &455[\_\k\k[llmn  " &56c#@   &./N.O P>>[=\ ]//2.? @ZZ  $ &-.K-L M--J,K L$$'OO#4E;  $$&89 	d"%9+Fa#bcc	ds&   #F I AI1HAI*Jr   c                 t   Uc  [         n[        UR                  5      nS[        [        [        4   S[        [        [        4   S-  4S jn0 nUR                  5        H:  u  pU
c  SX'   M  U
R                  S5      nUb  X;  a  SX'   M-  U" XU   5      X'   M<     U " UU=(       d    [        USS5      UUS9$ )	zR
Create MellonPipelineConfig by matching template against actual pipeline blocks.
Ntemplate_specr   c                 
  ^^^ [        UR                  5      m[        UR                  5      m[        UR                  5      mU R	                  S/ 5       Vs/ s H8  nUR
                  b&  [        U4S jUR
                   5       5      (       d  M6  UPM:     nnU R	                  S/ 5       Vs/ s H8  nUR
                  b&  [        U4S jUR
                   5       5      (       d  M6  UPM:     nnU R	                  S/ 5       Vs/ s H8  nUR
                  b&  [        U4S jUR
                   5       5      (       d  M6  UPM:     nnU Vs1 s H  o"R                  iM     nnU Vs1 s H  o"R                  iM     nnU R	                  S/ 5       Vs/ s H  oU;   d  M
  UPM     n	nU R	                  S/ 5       Vs/ s H  oU;   d  M
  UPM     n
nUUUU	U
U R	                  S	5      S
.$ s  snf s  snf s  snf s  snf s  snf s  snf s  snf )zFFilter template spec params based on what the block actually supports.r   c              3   ,   >#    U  H	  oT;   v   M     g 7fr   r   ).0r   block_input_namess     r   	<genexpr>RMellonPipelineConfig.from_blocks.<locals>.filter_spec_for_block.<locals>.<genexpr>  s     U=TT00=T   r   c              3   ,   >#    U  H	  oT;   v   M     g 7fr   r   )rr  r   block_component_namess     r   rt  ru    s     YAX44AXrv  r   c              3   ,   >#    U  H	  oT;   v   M     g 7fr   r   )rr  r   block_output_namess     r   rt  ru    s     V>Ud11>Urv  r   r   r   r   )setr   intermediate_output_namescomponent_namesr   r"   allr   )ro  blockr  filtered_inputsfiltered_model_inputsfiltered_outputsfiltered_input_namesfiltered_model_input_namesr9  filtered_required_inputsfiltered_required_model_inputsrx  rs  rz  s              @@@r   filter_spec_for_block?MellonPipelineConfig.from_blocks.<locals>.filter_spec_for_block  s    #E$5$5 6!$U%D%D!E$'(=(=$>! '**8R88A**2UQ=T=TUU 8   '**>2>%>A**2YAXAXYY > " % '**9b9 9A**2Va>U>UVV 9    5D#DOqFFO #D:O)P:OQ&&:O&)P ),,->C(CaL`G`C % ( ),,-DbI.IaRlMlI + .
 * 5+#;)G+//= ;%  $E)P(.sH   5G"G",5G'%G'5G,:G,G1!G6	G;G;5	H H r   
model_namer:   r  )DEFAULT_NODE_SPECSr   
sub_blocksr   r   r   r   getattr)r   blocksr   r   r
  r  sub_block_mapr  r	  r   ro  r   s               r   from_blocks MellonPipelineConfig.from_blocks  s     )HV../*	c3h *	4PSUXPX>\`K` *	Z 
(0(8$I$(,
%&**<8J!Z%D(,
%$9-WaIb$cJ! )9 !<76<<%'	
 	
r   
node_labelinput_typesoutput_typesc                    Uc_  UR                   R                  nSR                  U Vs/ s H  ofR                  5       (       a  SU-   OUPM      sn5      R	                  5       nUc  0 nUc  0 n/ n/ n/ n	UR
                   H  n
U
R                  c  M  U
R                  U;   a+  [        R                  " U
5      n
SX:R                     0U
l        [        SU
R                   SU
R                   35        UR                  [        U
5      5        M     UR                   Hg  nUR                  c  M  UR                  U;   a+  [        R                  " U5      nSXKR                     0Ul        U	R                  [        U5      5        Mi     UR                  nU H1  nUR                  [        R                   R#                  U5      5        M3     U	R                  [        R%                  5       5        UUU	/ / SS.nU " SU0US9$ s  snf )	ao  
Create a MellonPipelineConfig from a custom block.

Args:
    block: A block instance with `inputs`, `outputs`, and `expected_components`/`component_names` properties.
        Each InputParam/OutputParam should have metadata={"mellon": "<type>"} where type is one of: image,
        video, text, checkbox, number, slider, dropdown, model. If metadata is None, maps to "custom".
    node_label: The display label for the node. Defaults to block class name with spaces.
    input_types:
        Optional dict mapping input param names to mellon types. Overrides the block's metadata if provided.
        Example: {"prompt": "textbox", "image": "image"}
    output_types:
        Optional dict mapping output param names to mellon types. Overrides the block's metadata if provided.
        Example: {"prompt": "text", "images": "image"}

Returns:
    MellonPipelineConfig instance
r:   r   r   z processing input: z, metadata: r   r   )r	  r   )	__class__r   r  isupperstripr   r   copyr   printr  r   r   r   r}  r   r   r   rz   )r   r  r  r  r  
class_namecr   r   r   r   r   r}  component_namer   s                  r   from_custom_block&MellonPipelineConfig.from_custom_block  s   4 11J!TAYY[[#'a"?!TU[[]JKL !<<K';."ii4(0+>N>N2O'P$'(8(8'9kFZFZE[\]MM5kBC ( "MML  (  L0#yy6)1<@Q@Q3R(S%NN7EF *  //-N 1 1 7 7 GH . 	{() (!%'"
	  ),
 	
_ "Us   %G>)r  r
  r   r	  )r:   r:   r:   r   )Nr:   r:   bfloat16)NNN)r   r   r   r   r   rO  r   r   r   r  propertyr  r  r   r   r$  r+  rJ  PathLiker6  r<  r   rW  r:  r  r  r   r   r   r   r  r    sJ   (T 0K
 +d38nt334+ + 	+
 +. T#s(^   #  "
c3h 
 T#s(^ 0F  L L03+< 0
 #C"++,= #BX # #E3#4 E4 E8 Od'*R[['8Od 
 	Od Odb  6:'O
 sDcN*+d2O
 	O

 O
 O
 
 O
 O
b  -1.2M
 M
 #s(^d*	M

 38nt+M
 
 M
 M
r   r  )z *)@r  r)  loggingrJ  dataclassesr   r   typingr   huggingface_hubr   r   r   huggingface_hub.utilsr	   r
   r   r   utilsr   modular_pipeline_utilsr   r   	getLoggerr   rP  r   r   r   r    r}   r   r   r   r4   r/   r.   rJ   rO   rS   r=   r0   r-   r)   r*   rq   rj   rw   rk   r'   r+   rz   r   rf   r6   r<   rn   r#   rc   r  r   r   r  r  r   r   r   <module>r     s      	 *  E E  4 ; 
		8	$* * *IwG_f^ghI 'hbjaklI  "1!2		I I'endopI  "1!2	I$ &"7!8	%I0 !2HQYZ1I4 " '1J<H"1:!>$5IF -|PXYGIH #"0!1	IIV "*WId ""3!4eIt !uIF ",GIX "*YIh ")iIx "-yIJ "7!8KI\ ".]In "*oI@ &	AIN $0"A!B&OI` )":!;aIr '"8!9sIF 'hbjaklGIJ 
U$:wjoipqKIL  &"1!2	MIX o/ERYZYIZ ;0FSZ[[I\ #&".	]Ih  '"0!1	iIv #!3	wIB L2ERYZCID -.b9	EIP 
UHBQI XUd U& $duO du duN)B\ )Bk )BXC} C C:  ""7"3 ++-""$&&(  "335%%'++-))'):
  !!#
 1'')OO

 )>"(+!67> 
 OO
 %%h%7OO
 $9"'#"  '')

 %%'
 ""8"4OO
 %:"1!2$$ 0
 OO
   OO

 &;"'}N b c S kS#X k3 k4PSUXPX> k\Y
 Y
r   