Repository: huggingface/diffusers
File: src/diffusers/modular_pipelines/modular_pipeline.py (Python)

Code before:
        elif config_dict is not None:
            from diffusers.pipelines.auto_pipeline import _get_model

            logger.debug(" try to determine the modular pipeline class from model_index.json")
            standard_pipeline_class = _get_pipeline_class(cls, config=config_dict)
            model_name = _get_model(standard_pipeline_class.__name__)
            pipeline_class_name = MODULAR_PIPELINE_MAPPING.get(model_name, ModularPipeline.__name__)
            diffusers_module = importlib.import_module("diffusers")
            pipeline_class = getattr(diffusers_module, pipeline_class_name)
        else:
            # there is no config for modular pipeline, assuming that the pipeline block does not need any from_pretrained components
            pipeline_class = cls
            pretrained_model_name_or_path = None

        pipeline = pipeline_class(
            blocks=blocks,
            pretrained_model_name_or_path=pretrained_model_name_or_path,
            components_manager=components_manager,
            collection=collection,
            modular_config_dict=modular_config_dict,
            config_dict=config_dict,
            **kwargs,
        )
        return pipeline

    def _generate_modular_model_card_content(self) -> Dict[str, Any]:
        from .modular_pipeline_utils import format_components, format_configs

        blocks_class_name = self.blocks.__class__.__name__
        pipeline_name = blocks_class_name.replace("Blocks", " Pipeline")
        description = self.blocks.description or "A modular diffusion pipeline."

        # generate blocks architecture description
        blocks_desc_parts = []
        for i, (name, block) in enumerate(self.blocks.sub_blocks.items()):
            block_class = block.__class__.__name__
            block_desc = block.description.split("\n")[0] if block.description else ""
            blocks_desc_parts.append(f"{i + 1}. **{name}** (`{block_class}`)")
            if block_desc:
                blocks_desc_parts.append(f"   - {block_desc}")

            # add sub-blocks if any
            if hasattr(block, "sub_blocks") and block.sub_blocks:
                for sub_name, sub_block in block.sub_blocks.items():
                    sub_class = sub_block.__class__.__name__
                    sub_desc = sub_block.description.split("\n")[0] if sub_block.description else ""
                    blocks_desc_parts.append(f"   - *{sub_name}*: `{sub_class}`")
                    if sub_desc:
                        blocks_desc_parts.append(f"     - {sub_desc}")

        blocks_description = "\n".join(blocks_desc_parts) if blocks_desc_parts else "No blocks defined."

Review comment (refactor):
I think we can move this as a function in` modular_pipeline_utils` so the pipeline itself is less crowded, like https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/modular_pipeline_utils.py#L865
 
```py
def generate_modular_model_card_conten(blocks):
    ...
````

Code after:
            pipeline_class = _get_pipeline_class(cls, config=modular_config_dict)
        elif config_dict is not None:
            from diffusers.pipelines.auto_pipeline import _get_model

            logger.debug(" try to determine the modular pipeline class from model_index.json")
            standard_pipeline_class = _get_pipeline_class(cls, config=config_dict)
            model_name = _get_model(standard_pipeline_class.__name__)
            pipeline_class_name = MODULAR_PIPELINE_MAPPING.get(model_name, ModularPipeline.__name__)
            diffusers_module = importlib.import_module("diffusers")
            pipeline_class = getattr(diffusers_module, pipeline_class_name)
        else:
            # there is no config for modular pipeline, assuming that the pipeline block does not need any from_pretrained components
            pipeline_class = cls
            pretrained_model_name_or_path = None

        pipeline = pipeline_class(
            blocks=blocks,
            pretrained_model_name_or_path=pretrained_model_name_or_path,
            components_manager=components_manager,
            collection=collection,
            modular_config_dict=modular_config_dict,
            config_dict=config_dict,
            **kwargs,
        )
        return pipeline

    def save_pretrained(self, save_directory: Union[str, os.PathLike], push_to_hub: bool = False, **kwargs):
        """
        Save the pipeline to a directory. It does not save components, you need to save them separately.

        Args:
            save_directory (`str` or `os.PathLike`):
                Path to the directory where the pipeline will be saved.
            push_to_hub (`bool`, optional):
                Whether to push the pipeline to the huggingface hub.
            **kwargs: Additional arguments passed to `save_config()` method
        """
        if push_to_hub:
            commit_message = kwargs.pop("commit_message", None)
            private = kwargs.pop("private", None)
            create_pr = kwargs.pop("create_pr", False)
            token = kwargs.pop("token", None)
            repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1])
            repo_id = create_repo(repo_id, exist_ok=True, private=private, token=token).repo_id

            # Generate modular pipeline card content
            card_content = generate_modular_model_card_content(self.blocks)

            # Create a new empty model card and eventually tag it
            model_card = load_or_create_model_card(
                repo_id,