o
    ۷id                     @   s2  d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
mZmZ d dlmZmZmZmZ ddlmZ dd	lmZmZ eeZd
edefddZi dddddgddddddgddddddgddddddgddddddgddddddgdddddd d!ddddd"d#gd$gd%dd$gd&d'd(d'dd d)d*d)dd)gdd+d,d-d.d/d+gd0d1d2d-d.d/d1gd0d3d4d5d6d7d8d9d:d;d$d<d5d=d>d8d?d$gd@d"dAdBdCdDdEd"gdFd#dGdBdCdDdEd#gdFdHdIdBd d dJdKdLgdMi dNdOdBdPddQd6dNgdMdRdSdBdTddUd6dRgdMdVdWdBdXddYd6dVgdMdZd[d\d]g d^d_d`dad5d=d>d8d?d`gd@dbdcd5d>d>d8d?dbgd@ddded5d8d>d8d?ddgd@dfdgdhddfgddidjdkddigddldmdkddlgddndodkdd dpdqdkdd drdsdkddrgddtdudvddwgddxdydzdd{dd|d}d~dd ddddd3gg ddddd-dd iZG dd deZeddG dd dedZdddefddZ dddefddZ!dej"dde# e$ e% e& e' e( e) e* e+ e, ej-ddge. e/ e0 gej1dde2 e3 gd'gdndpgdde4 ge5 gej+dde3 gdgdigdde6 e7 ge8 gej"dde3 gd+gdtgdwdej1ddge5 ge9 e: e3 gdgdigdddZ;ddededefddZ<de=eef dede=eef fddZ>G dd dZ?dS )    N)asdict	dataclass)Any)create_repohf_hub_downloadupload_file)EntryNotFoundErrorHfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError   )HUGGINGFACE_CO_RESOLVE_ENDPOINT   )
InputParamOutputParamnamereturnc                 C   s   |  dd S )z,Convert snake_case name to Title Case label._ )replacetitler    r   c/home/ubuntu/vllm_env/lib/python3.10/site-packages/diffusers/modular_pipelines/mellon_node_utils.py_name_to_label   s   r   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?   r@   rA   r!   Heightinti   @      )r   r   r:   r?   rA   r!   WidthseedSeed    random	generator)r   r   r:   r?   r@   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    r2   docDocc                   @   s   e Zd ZdZdefddZdS )MellonParamMetazEMetaclass that enables MellonParam.template_name(**overrides) syntax.r   c                    s,   t v rd fdd	}|S td d)Nc                    s>   t  }d|di||}| d ur| |d<  di |S )Nr   r:   r   )MELLON_PARAM_TEMPLATESget)r:   	overridestemplateparamsclsr   r   r   factory   s
   z,MellonParamMeta.__getattr__.<locals>.factoryz,type object 'MellonParam' has no attribute ''N)r|   AttributeError)r   r   r   r   r   r   __getattr__   s   zMellonParamMeta.__getattr__N)__name__
__module____qualname____doc__strr   r   r   r   r   r{      s    r{   T)frozenc                   @   s  e Zd ZU dZeed< eed< eed< dZedB ed< dZeed< dZ	e
dB ed< dZe
dB ed	< dZe
dB ed
< dZeed< dZeed< dZeeef dB ed< dZeed< dZeed< dZeee B dB ed< deeef fddZG dd dZG dd dZdS )MellonParamat  
        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?   r@   rA   r^   valuefieldOptionsr2   onSignalr!   r   c                 C   s   t | }dd | D S )zMConvert to dict for Mellon schema, excluding None values and internal fields.c                 S   s&   i | ]\}}|d ur|dvr||qS )N)r   r!   r   ).0kvr   r   r   
<dictcomp>(  s   & z'MellonParam.to_dict.<locals>.<dictcomp>)r   items)selfdatar   r   r   to_dict%  s   zMellonParam.to_dictc                   @   s"  e Zd ZdZededdfddZed"dededdfd	d
Zed#dedee deddfddZ	e	d$dede
de
de
de
ddfddZe	d$dede
de
de
de
ddfddZed%dededdfddZed&dededdfddZedededdfddZededdfd d!ZdS )'zMellonParam.Inputz$input UI elements for custom blocks.r   r   r   c                 C      t |t|dddS )zimage input.r   r   r   r   r   r    r   r   r   r   r   r   r   0     zMellonParam.Input.imager9   r:   c                 C   s   t |t|dd|dS )ztext input as textarea.r7   r8   )r   r   r   r    r:   r   r   r   r:   r   r   r   textbox5  s   zMellonParam.Input.textboxNr^   c                 C   s8   |r|s|d }|sd}|s|g}t |t|d||dS )zdropdown selection.r   r9   r7   )r   r   r   r^   r   r   )r   r   r^   r:   r   r   r   rZ   <  s   zMellonParam.Input.dropdownr   r?   r@   rA   c              
   C   sp   t |tp|duot |t}|rdnd}|du r|}|du r |}|du r*|r(dnd}t|t||d||||dS )zslider input.Nr=   rE   rC   r   r>   )r   r   r   r    r:   r?   r@   rA   
isinstancer=   r   r   r   r   r:   r?   r@   rA   is_float
param_typer   r   r   r>   G  s$   zMellonParam.Input.sliderc              	   C   sB   t |tp|duot |t}|rdnd}t|t||||||dS )znumber input (no slider).Nr=   rE   )r   r   r   r:   r?   r@   rA   r   r   r   r   r   number_  s
   zMellonParam.Input.numberrI   c              	   C   s   t |t|dd|dddS )z!seed input with randomize button.rE   rL   r   rK   )r   r   r   r    r:   r?   r@   r   r   r   r   r   rI   j  s   zMellonParam.Input.seedFc                 C   s   t |t|d|dS )zboolean checkbox.boolean)r   r   r   r   r   r   r   r   r   checkboxw  r   zMellonParam.Input.checkboxr   c                 C      t |t||ddS )z'custom type input for node connections.r   r   r   r   r   r   r   r   r   custom_type|  r   zMellonParam.Input.custom_typec                 C   r   )z%model input for diffusers components.rg   r   r   r   r   r   r   r   model  r   zMellonParam.Input.model)r9   )NN)r   NNN)rI   r   F)r   r   r   r   classmethodr   r   r   listrZ   r=   r>   r   rE   rI   boolr   r   r   r   r   r   r   Input-  s\    "

r   c                   @   s   e Zd ZdZededdfddZededdfddZededdfd	d
ZedededdfddZ	ededdfddZ
dS )zMellonParam.Outputz%output UI elements for custom blocks.r   r   r   c                 C   r   )zimage output.r   r$   r   r   r   r   r   r   r     r   zMellonParam.Output.imagec                 C   r   )zvideo output.rd   r$   r   r   r   r   r   r   rd     r   zMellonParam.Output.videoc                 C   r   )ztext output.r7   r$   r   r   r   r   r   r   text  r   zMellonParam.Output.textr   c                 C   r   )z(custom type output for node connections.r$   r   r   r   r   r   r   r     r   zMellonParam.Output.custom_typec                 C   r   )z&model output for diffusers components.rg   r$   r   r   r   r   r   r   r     r   zMellonParam.Output.modelN)r   r   r   r   r   r   r   rd   r   r   r   r   r   r   r   Output  s    r   )r   r   r   r   r   __annotations__r    r:   r   r?   r=   r@   rA   r^   r   r   dictr2   r   r!   r   r   r   r   r   r   r   r   r      s&   
 \r   )	metaclassinput_paramr   c                 C   s  | j }| j}|r|dnd}| j}t|tr|S |}|dkr%tj|S |dkr3tjj||p0ddS |dkrAtjj	||p>ddS |dkrOtjj
||pLd	dS |d
kr]tjj||pZd	dS |dkrktjj||phd	dS |dkrytjj||pvddS |dkrtj|S tjj|ddS )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   r9   )r:   rZ   r>   r   r   rI   r   Fr   customr   )r   metadatar}   r:   r   r   r   r   r   rZ   r>   r   rI   r   r   r   )r   r   r   mellon_valuer:   mellon_typer   r   r   input_param_to_mellon_param  s0   
r   output_paramr   c                 C   s~   | j }| j}|r|dnd}|dkrtj|S |dkr#tj|S |dkr-tj|S |dkr7tj|S tjj	|ddS )	a7  
    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   rd   r   r   r   r   )
r   r   r}   r   r   r   rd   r   r   r   )r   r   r   r   r   r   r   output_param_to_mellon_param  s   r   )r    denoiseinputsmodel_inputsoutputsrequired_inputsrequired_model_inputs
block_namevae_encoderdecode)rl   r   r   ro   decoder *r   markerc                 C   s   |  |r| S |  | S )z4Add required marker to label if not already present.)endswith)r   r   r   r   r   mark_required?  s   
r   	node_spec	node_typec                 C   s  i }g }g }g }|  dg }|  dg }|  dg D ]}| }	|j|v r-t|	d |	d< |	||j< ||j q|  dg D ]}| }	|j|v rRt|	d |	d< |	||j< ||j q?|  dg D ]}|j|v rrd|j }
n|j}
| ||
< ||
 qd|||||  d|d	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_namer   r   r   node_spec_to_mellon_dictF  s>   B




r   c                   @   s  e Zd ZdZdZ			d-deeeeef dB f dededefd	d
Ze	deeef fddZ
defddZdeeef fddZedeeef dd fddZdefddZdeejB fddZedeejB dd fddZd.deejB defdd Zed!eejB dd fd"d#Ze				$d/d%eeeeef f dB dedededd f
d&d'Ze			d0d(ed)eeef dB d*eeef dB dd fd+d,ZdS )1MellonPipelineConfiga  
    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.jsonr9   
node_specsNr   default_repodefault_dtypec                 C   s   || _ || _|| _|| _dS )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   r   r   r   __init__  s   
zMellonPipelineConfig.__init__r   c                 C   sL   | j du r| jS i }| j  D ]\}}|du rd||< qt||||< q|S )z+Lazily compute node_params from node_specs.N)r   _node_paramsr   r   )r   r   r   specr   r   r   node_params  s   

z MellonPipelineConfig.node_paramsc                 C   s   d| j d| jd| jdg}| j D ]T\}}|d u r'|d| d qdd |d	g D }d
d |dg D }dd |dg D }|d| d |d|  |d|  |d|  qd|S )NzMellonPipelineConfig(label=z, default_repo=z, default_dtype=)z  z: Nonec                 S      g | ]}|j qS r   r   r   r   r   r   r   
<listcomp>      z1MellonPipelineConfig.__repr__.<locals>.<listcomp>r   c                 S   r   r   r   r   r   r   r   r     r   r   c                 S   r   r   r   r   r   r   r   r     r   r   :z    inputs: z    model_inputs: z    outputs: 
)r   r   r   r   r   r   r}   join)r   linesr   r   r   r   r   r   r   r   __repr__  s   
zMellonPipelineConfig.__repr__c                 C   s   | j | j| j| jdS )z*Convert to a JSON-serializable dictionary.r   r   r   r   r   r   r   r   r   r     s
   zMellonPipelineConfig.to_dictr   c                 C   sL   |  | }d|_|di |_|dd|_|dd|_|dd|_|S )z
        Create from a dictionary (loaded from JSON).

        Note: The mellon_params are already in Mellon format when loading from JSON.
        Nr   r   r9   r   r   )__new__r   r}   r   r   r   r   )r   r   instancer   r   r   	from_dict   s   
zMellonPipelineConfig.from_dictc                 C   s   t j|  dddd S )zSerialize to JSON string.r   F)indent	sort_keysr   )jsondumpsr   r   r   r   r   to_json_string/  s   z#MellonPipelineConfig.to_json_stringjson_file_pathc                 C   sB   t |ddd}||   W d   dS 1 sw   Y  dS )zSave to a JSON file.wutf-8encodingN)openwriter   )r   r   writerr   r   r   to_json_file3  s   "z!MellonPipelineConfig.to_json_filec                 C   sB   t |ddd}t|}W d   n1 sw   Y  | |S )zLoad from a JSON file.rr   r   N)r   r   loadr   )r   r   readerr   r   r   r   from_json_file8  s   
z#MellonPipelineConfig.from_json_fileFsave_directorypush_to_hubc           
      K   s   t j|rtd| dt j|dd t j|| j}| | t	d|  |rq|
dd}|
dd}|
d	d
}|
dd}|
d|t jjd }	t|	d||dj}	t|| j|	||pcd|d t	d|	  dS dS )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)r  r  r
  zUpload MellonPipelineConfig)path_or_fileobjpath_in_repor  r
  r  r	  zPipeline config pushed to hub: )ospathisfileAssertionErrormakedirsr   config_namer   loggerinfopopsplitsepr   r  r   )
r   r  r  kwargsoutput_pathr  r  r	  r
  r  r   r   r   save?  s.   
zMellonPipelineConfig.savepretrained_model_name_or_pathc                 K   s  | dd}| dd}| dd}| dd}| dd}| d	d}| d
d}	| dd}
| dd}t|}tj|rC|}ntj|rctj|| j}tj|sbtd| j d| nzt	|| j||||	||
|||d}W nn t
y   t| d ty   t|
 d| d ty   t| d| j d ty } z
td| d| d}~w ty   tdt d| d| j d ty   td| d| d| j dw z| |W S  tjtfy   td| d w )!z=Load a pipeline config from a local path or Hugging Face Hub.	cache_dirN	local_dirlocal_dir_use_symlinksautoforce_downloadFproxiesr
  local_files_onlyrevision	subfolderzNo file named z
 found in )
filenamer  r"  r#  r$  r
  r%  r&  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.)r  r   r  r  r  isdirr   r  EnvironmentErrorr   r
   r   r   r	   
ValueErrorr   r  r   JSONDecodeErrorUnicodeDecodeError)r   r  r  r  r  r   r"  r#  r
  r$  r%  r&  config_fileerrr   r   r   r  [  s   
zMellonPipelineConfig.loadbfloat16r   c                 C   s   |du rt }t|j}dtttf dtttf dB fdd}i }| D ](\}	}
|
du r1d||	< q$|
d}|du s>||vrCd||	< q$||
|| ||	< q$| ||pVt|dd||d	S )
zb
        Create MellonPipelineConfig by matching template against actual pipeline blocks.
        Ntemplate_specr   c                    s   t |jt |jt |j fdd| dg D } fdd| dg D }fdd| dg D }dd	 |D d
d	 |D fdd| dg D }fdd| dg D }|||||| ddS )zFFilter template spec params based on what the block actually supports.c                    2   g | ]}|j d u st fdd|j D r|qS )Nc                 3       | ]}| v V  qd S r   r   r   r   block_input_namesr   r   	<genexpr>      ]MellonPipelineConfig.from_blocks.<locals>.filter_spec_for_block.<locals>.<listcomp>.<genexpr>r!   allr   r5  r   r   r         
zSMellonPipelineConfig.from_blocks.<locals>.filter_spec_for_block.<locals>.<listcomp>r   c                    r2  )Nc                 3   r3  r   r   r4  block_component_namesr   r   r7    r8  r9  r:  r   r=  r   r   r     r<  r   c                    r2  )Nc                 3   r3  r   r   r4  block_output_namesr   r   r7    r8  r9  r:  r   r?  r   r   r     r<  r   c                 S      h | ]}|j qS r   r   r   r   r   r   	<setcomp>  r   zRMellonPipelineConfig.from_blocks.<locals>.filter_spec_for_block.<locals>.<setcomp>c                 S   rA  r   r   r   r   r   r   rB    r   c                       g | ]}| v r|qS r   r   r   r   )filtered_input_namesr   r   r         r   c                    rC  r   r   rD  )filtered_model_input_namesr   r   r     rF  r   r   r   )setr   intermediate_output_namescomponent_namesr}   )r1  blockfiltered_inputsfiltered_model_inputsfiltered_outputsfiltered_required_inputsfiltered_required_model_inputsr   )r>  r6  r@  rE  rG  r   filter_spec_for_block  s6   












z?MellonPipelineConfig.from_blocks.<locals>.filter_spec_for_blockr   
model_namer9   r   )DEFAULT_NODE_SPECSr   
sub_blocksr   r   r   r}   getattr)r   blocksr   r   r   r   sub_block_maprQ  r   r   r1  r   r   r   r   from_blocks  s(   
&-
z MellonPipelineConfig.from_blocks
node_labelinput_typesoutput_typesc                 C   sJ  |du r|j j}ddd |D  }|du ri }|du r i }g }g }g }|jD ]-}	|	jdu r1q)|	j|v rCt|	}	d||	j i|	_td|	j d|	j  |	t
|	 q)|jD ]!}
|
jdu rbqZ|
j|v rtt|
}
d||
j i|
_|	t|
 qZ|j}|D ]}|	tj| q|	t  |||g g dd	}| d|i|d
S )a  
        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
        Nr9   c                 S   s    g | ]}|  rd | n|qS )r   )isupper)r   cr   r   r   r     s     z:MellonPipelineConfig.from_custom_block.<locals>.<listcomp>r   z processing input: z, metadata: r   r   )r   r   )	__class__r   r   stripr   r   copyr   printr   r   r   r   rJ  r   r   r   ry   )r   rK  rY  rZ  r[  
class_namer   r   r   r   r   rJ  component_namer   r   r   r   from_custom_block  sP   







	z&MellonPipelineConfig.from_custom_block)r9   r9   r9   r   )Nr9   r9   r0  )NNN)r   r   r   r   r  r   r   r   r   propertyr   r   r   r   r   r   r  PathLiker   r  r   r  r  rX  rd  r   r   r   r   r     sz    *
	QQr   )r   )@r`  r   loggingr  dataclassesr   r   typingr   huggingface_hubr   r   r   huggingface_hub.utilsr   r	   r
   r   utilsr   modular_pipeline_utilsr   r   	getLoggerr   r  r   r   r|   r   r{   r   r   r   r3   r.   r-   rI   rN   rR   r<   r/   r,   r(   r)   rp   ri   rv   rj   r&   r*   ry   r   re   r5   r;   rm   r"   rb   rS  r   r   r   r   r   r   r   r   <module>   s   
#$+2:CLT\enw         $  &  '  -  .  /  5  <  B  C
  I  M (,





Q&n