Skip to content

MONAI Pipeline Generator #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

MONAI Pipeline Generator #550

wants to merge 19 commits into from

Conversation

mocsharp
Copy link
Collaborator

@mocsharp mocsharp commented Aug 13, 2025

A new tool for creating a MONAI Deploy Application pipeline using a chosen MONAI model.

Tested MONAI models

❯ uv run pg list
warning: `VIRTUAL_ENV=/home/vicchang/sc/github/monai/monai-deploy-app-sdk/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
Fetching models from HuggingFace...
INFO     Fetching models from organization: MONAI                                                                                                                                                                  
INFO     Fetching model: LGAI-EXAONE/EXAONEPath                                                                                                                                                                    
INFO     Fetching model: LGAI-EXAONE/EXAONEPath-CRC-MSI-Predictor                                                                                                                                                  
                                                                Available Models                                                                 
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓
┃ Model ID                                 ┃ Name                                               ┃ Type         ┃ Status     ┃ Downloads ┃ Likes ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━┩
│ LGAI-EXAONE/EXAONEPath                   │ LGAI-EXAONE/EXAONEPath                             │ Model        │            │       468 │    19 │
│ LGAI-EXAONE/EXAONEPath-CRC-MSI-Predictor │ LGAI-EXAONE/EXAONEPath-CRC-MSI-Predictor           │ MONAI Bundle │            │       N/A │     5 │
│ MONAI/Llama3-VILA-M3-13B                 │ MONAI/Llama3-VILA-M3-13B                           │ Model        │ ✓ Verified │        37 │     8 │
│ MONAI/Llama3-VILA-M3-3B                  │ MONAI/Llama3-VILA-M3-3B                            │ Model        │ ✓ Verified │      1922 │     6 │
│ MONAI/Llama3-VILA-M3-8B                  │ MONAI/Llama3-VILA-M3-8B                            │ Model        │ ✓ Verified │       145 │     9 │
│ MONAI/VISTA3D-HF                         │ MONAI/VISTA3D-HF                                   │ MONAI Bundle │            │       N/A │     3 │
│ MONAI/brain_image_synthesis_latent_diff… │ MONAI/brain_image_synthesis_latent_diffusion_model │ Model        │            │       N/A │     1 │
│ MONAI/brats_mri_axial_slices_generative… │ MONAI/brats_mri_axial_slices_generative_diffusion  │ Model        │            │       N/A │     1 │
│ MONAI/brats_mri_generative_diffusion     │ MONAI/brats_mri_generative_diffusion               │ Model        │            │       N/A │   N/A │
│ MONAI/brats_mri_segmentation             │ MONAI/brats_mri_segmentation                       │ Model        │            │       N/A │     3 │
│ MONAI/breast_density_classification      │ MONAI/breast_density_classification                │ Model        │ ✓ Verified │       N/A │     1 │
│ MONAI/classification_template            │ MONAI/classification_template                      │ Model        │            │       N/A │   N/A │
│ MONAI/cxr_image_synthesis_latent_diffus… │ MONAI/cxr_image_synthesis_latent_diffusion_model   │ Model        │            │       N/A │     2 │
│ MONAI/endoscopic_inbody_classification   │ MONAI/endoscopic_inbody_classification             │ Model        │            │       N/A │   N/A │
│ MONAI/endoscopic_tool_segmentation       │ MONAI/endoscopic_tool_segmentation                 │ Model        │ ✓ Verified │       N/A │     2 │
│ MONAI/example_spleen_segmentation        │ MONAI/example_spleen_segmentation                  │ MONAI Bundle │ ✓ Verified │       N/A │     6 │
│ MONAI/lung_nodule_ct_detection           │ MONAI/lung_nodule_ct_detection                     │ Model        │            │       N/A │     1 │
│ MONAI/maisi_ct_generative                │ MONAI/maisi_ct_generative                          │ Model        │            │       N/A │     1 │
│ MONAI/mediastinal-anatomy-v2.0.0         │ MONAI/mediastinal-anatomy-v2.0.0                   │ Model        │            │       N/A │   N/A │
│ MONAI/mednist_ddpm                       │ MONAI/mednist_ddpm                                 │ Model        │            │       N/A │   N/A │
│ MONAI/mednist_gan                        │ MONAI/mednist_gan                                  │ Model        │            │       N/A │   N/A │
│ MONAI/mednist_reg                        │ MONAI/mednist_reg                                  │ Model        │            │       N/A │   N/A │
│ MONAI/multi_organ_segmentation           │ MONAI/multi_organ_segmentation                     │ Model        │ ✓ Verified │       N/A │   N/A │
│ MONAI/pancreas_ct_dints_segmentation     │ MONAI/pancreas_ct_dints_segmentation               │ Model        │ ✓ Verified │       N/A │   N/A │
│ MONAI/pathology_nuclei_classification    │ MONAI/pathology_nuclei_classification              │ Model        │            │       N/A │   N/A │
│ MONAI/pathology_nuclei_segmentation_cla… │ MONAI/pathology_nuclei_segmentation_classification │ Model        │            │       N/A │     1 │
│ MONAI/pathology_nuclick_annotation       │ MONAI/pathology_nuclick_annotation                 │ Model        │            │       N/A │     1 │
│ MONAI/pathology_tumor_detection          │ MONAI/pathology_tumor_detection                    │ Model        │            │       N/A │   N/A │
│ MONAI/pediatric_abdominal_ct_segmentati… │ MONAI/pediatric_abdominal_ct_segmentation          │ Model        │ ✓ Verified │       N/A │     1 │
│ MONAI/prostate_mri_anatomy               │ MONAI/prostate_mri_anatomy                         │ Model        │            │       N/A │   N/A │
│ MONAI/renalStructures_CECT_segmentation  │ MONAI/renalStructures_CECT_segmentation            │ Model        │            │       N/A │   N/A │
│ MONAI/renalStructures_UNEST_segmentation │ MONAI/renalStructures_UNEST_segmentation           │ Model        │            │       N/A │   N/A │
│ MONAI/retinalOCT_RPD_segmentation        │ MONAI/retinalOCT_RPD_segmentation                  │ Model        │            │       N/A │   N/A │
│ MONAI/segmentation_template              │ MONAI/segmentation_template                        │ Model        │            │       N/A │   N/A │
│ MONAI/spleen_ct_segmentation             │ MONAI/spleen_ct_segmentation                       │ Model        │ ✓ Verified │       N/A │   N/A │
│ MONAI/spleen_deepedit_annotation         │ MONAI/spleen_deepedit_annotation                   │ Model        │            │       N/A │   N/A │
│ MONAI/swin_unetr_btcv_segmentation       │ MONAI/swin_unetr_btcv_segmentation                 │ Model        │ ✓ Verified │       N/A │     2 │
│ MONAI/us_model_test                      │ MONAI/us_model_test                                │ Model        │            │        13 │   N/A │
│ MONAI/valve_landmarks                    │ MONAI/valve_landmarks                              │ Model        │            │       N/A │     1 │
│ MONAI/ventricular_short_axis_3label      │ MONAI/ventricular_short_axis_3label                │ Model        │            │       N/A │     1 │
│ MONAI/vista2d                            │ MONAI/vista2d                                      │ Model        │            │       N/A │     1 │
│ MONAI/vista3d                            │ MONAI/vista3d                                      │ Model        │            │       N/A │   N/A │
│ MONAI/wholeBody_ct_segmentation          │ MONAI/wholeBody_ct_segmentation                    │ Model        │ ✓ Verified │       N/A │     1 │
│ MONAI/wholeBrainSeg_Large_UNEST_segment… │ MONAI/wholeBrainSeg_Large_UNEST_segmentation       │ Model        │ ✓ Verified │       N/A │     3 │
└──────────────────────────────────────────┴────────────────────────────────────────────────────┴──────────────┴────────────┴───────────┴───────┘

Total models: 44 (MONAI Bundles: 3, Verified: 13)

Unit Test/Coverage

❯ uv run pytest --cov=pipeline_generator --cov-report=term
warning: `VIRTUAL_ENV=/home/vicchang/sc/github/monai/monai-deploy-app-sdk/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.18, pytest-8.4.1, pluggy-1.6.0
rootdir: /home/vicchang/sc/github/monai/monai-deploy-app-sdk
configfile: setup.cfg
plugins: cov-6.2.1
collected 134 items                                                                                                                                                                                               

tests/test_bundle_downloader.py ..........................                                                                                                                                                  [ 19%]
tests/test_cli.py ..........                                                                                                                                                                                [ 26%]
tests/test_gen_command.py ..........                                                                                                                                                                        [ 34%]
tests/test_generator.py ..............................                                                                                                                                                      [ 56%]
tests/test_hub_client.py .................                                                                                                                                                                  [ 69%]
tests/test_models.py .....                                                                                                                                                                                  [ 73%]
tests/test_run_command.py ....................                                                                                                                                                              [ 88%]
tests/test_security.py ....                                                                                                                                                                                 [ 91%]
tests/test_settings.py .......                                                                                                                                                                              [ 96%]
tests/test_vlm_generation.py .....                                                                                                                                                                          [100%]

================================================================================================= tests coverage ==================================================================================================
________________________________________________________________________________ coverage: platform linux, python 3.10.18-final-0 _________________________________________________________________________________

Name                                                Stmts   Miss  Cover
-----------------------------------------------------------------------
pipeline_generator/__init__.py                          1      0   100%
pipeline_generator/cli/__init__.py                      2      0   100%
pipeline_generator/cli/main.py                        126      1    99%
pipeline_generator/cli/run.py                         153     11    93%
pipeline_generator/config/__init__.py                   2      0   100%
pipeline_generator/config/settings.py                  40      0   100%
pipeline_generator/core/__init__.py                     3      0   100%
pipeline_generator/core/hub_client.py                  62      1    98%
pipeline_generator/core/models.py                      23      0   100%
pipeline_generator/generator/__init__.py                3      0   100%
pipeline_generator/generator/app_generator.py         229      2    99%
pipeline_generator/generator/bundle_downloader.py     124      4    97%
-----------------------------------------------------------------------
TOTAL                                                 768     19    98%
=============================================================================================== 134 passed in 1.59s ===============================================================================================

@mocsharp mocsharp requested a review from MMelQin August 13, 2025 04:07
@mocsharp mocsharp self-assigned this Aug 13, 2025
@MMelQin MMelQin requested a review from Copilot August 13, 2025 06:33
Copilot

This comment was marked as outdated.

- Introduced ImageOverlayWriter for blending segmentation masks onto RGB images and saving as PNG.
- Updated ImageDirectoryLoader to support channel-first output configuration and improved file searching logic.
- Adjusted documentation and examples to reflect the transition from Poetry to uv for command execution.
- Updated various configuration files and templates to accommodate new features and dependencies.

Signed-off-by: Victor Chang <[email protected]>
- Introduced PromptsLoaderOperator to read prompts from a YAML file and emit them sequentially.
- Added Llama3VILAInferenceOperator for running inference with the Llama3-VILA-M3-3B model, supporting multiple output types.
- Created VLMResultsWriterOperator to write results to disk based on the specified output type.
- Updated configuration files and templates to integrate new operators and support custom input/output types.
- Added unit tests for the new operators to ensure functionality and correctness.

Signed-off-by: [Your Name] <[email protected]>
Signed-off-by: Victor Chang <[email protected]>
- Enhanced README with links to MONAI Deploy and MONAI Bundles for better clarity.
- Clarified usage instructions and examples for generating applications from models.
- Updated design documentation to reflect the correct Python version requirement (changed from 3.12 to 3.10).
- Improved descriptions in the generated application structure and additional models section.

Signed-off-by: Victor Chang <[email protected]>
- Updated import statements in various operator files to use parentheses for better readability.
- Cleaned up whitespace and formatting inconsistencies across multiple files, enhancing overall code clarity.
- Ensured consistent handling of newlines and indentation in operator implementations and test files.

Signed-off-by: Victor Chang <[email protected]>
@mocsharp mocsharp force-pushed the vchang/monai-hf branch 2 times, most recently from ef7242b to 14dbba4 Compare August 13, 2025 21:28
- Introduced a new GitHub Actions workflow for testing the pipeline generator, including steps for setting up Python 3.10, installing dependencies, and running tests.
- Updated the version of the pipeline-generator package from 0.1.0 to 1.0.0 in the uv.lock file.
- Refactored import statements and improved code formatting in various files for better readability and consistency.

Signed-off-by: Victor Chang <[email protected]>
@mocsharp mocsharp requested a review from Copilot August 13, 2025 22:15
Copilot

This comment was marked as outdated.

…tion

- Moved the documentation for ImageOverlayWriter into the class docstring for better organization and clarity.
- Improved the model_id validation logic in AppGenerator to prevent code injection and path traversal, ensuring stricter input checks.
- Updated the generated application template to reflect changes in the channel_first logic.
- Added unit tests to verify the correctness of the refactored channel_first logic.

Signed-off-by: Victor Chang <[email protected]>
@mocsharp mocsharp requested a review from Copilot August 13, 2025 23:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new MONAI Pipeline Generator tool that automatically creates MONAI Deploy Application pipelines from MONAI models hosted on HuggingFace. The tool provides a CLI interface to discover, generate, and run medical imaging applications with minimal configuration.

Key changes include:

  • Complete implementation of the pipeline generator with 44 discoverable models from HuggingFace
  • Comprehensive test suite achieving 97% code coverage with 105 tests
  • Full CLI support for listing models, generating applications, and running them

Reviewed Changes

Copilot reviewed 46 out of 47 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/pipeline-generator/pyproject.toml Project configuration with dependencies and build settings
tools/pipeline-generator/pipeline_generator/ Core module structure with generator, config, CLI, and templates
tools/pipeline-generator/tests/ Comprehensive test suite covering all functionality
tools/pipeline-generator/pipeline_generator/templates/ Jinja2 templates for generating application files
tools/pipeline-generator/pipeline_generator/cli/ CLI commands for list, gen, and run operations
Comments suppressed due to low confidence (1)

tools/pipeline-generator/pipeline_generator/generator/app_generator.py:99

  • The regex pattern has an incorrect escape sequence. The backslash before the opening bracket should be properly escaped as \/ instead of \[ to match the forward slash character correctly.
        model_id_pattern = r"^(?!.*\.\.)(?!/)(?!.*//)(?!.*\/$)[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$"

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

…e generator

- Updated the application class documentation to provide clearer descriptions of the vision-language model (VLM) functionality, including details on prompt processing and output generation.
- Refined the version constraints for the pydicom dependency in the requirements template to ensure compatibility with future updates while maintaining support for existing features.

Signed-off-by: Victor Chang <[email protected]>
…ionality

- Replaced ImageDirectoryLoader with a new GenericDirectoryScanner and ImageFileLoader for improved flexibility in file handling.
- Updated operator imports in the application template to reflect the new structure.
- Added unit tests for the GenericDirectoryScanner to ensure correct functionality, including edge cases for file detection and filtering.
- Removed deprecated NiftiDirectoryLoader and ImageDirectoryLoader to streamline the codebase.

Signed-off-by: Victor Chang <[email protected]>
- Removed deprecated operators from the MONAI Deploy SDK and updated the import paths in the application template to reflect the new structure.
- Introduced new operators such as GenericDirectoryScanner and ImageFileLoader for improved file handling.
- Enhanced the NiftiDataLoader to handle various dimensionalities correctly and added logging for unexpected shapes.
- Updated the pipeline generator to include new operators and refined the requirements for dependencies in the configuration files.
- Added comprehensive tests for the new operators and updated existing tests to ensure functionality and correctness.

Signed-off-by: Victor Chang <[email protected]>
- Updated operator imports in the MONAI Deploy SDK to streamline the structure and improve readability.
- Refined the NiftiDataLoader to ensure proper handling of various dimensionalities and added logging for unexpected shapes.
- Enhanced the pipeline generator to include new operators and improved the handling of output types.
- Cleaned up whitespace and formatting inconsistencies across multiple files for better code clarity.
- Removed deprecated test files related to GenericDirectoryScanner and VLM operators to maintain a clean codebase.

Signed-off-by: Victor Chang <[email protected]>
- Adjusted whitespace in print statements for better readability in the DICOM data loader operator.
- Enhanced the error message in the AppGenerator class to improve clarity regarding valid model_id formats.
- Corrected spacing in the file processing output of the generic directory scanner operator.
- Removed unused import from the test_run_command module to clean up the code.

Signed-off-by: Victor Chang <[email protected]>
- Deleted the __init__.py test file from the pipeline-generator tests directory to clean up the codebase and remove unused files.

Signed-off-by: Victor Chang <[email protected]>
- Added type hints for lists and dictionaries in various operator classes to improve code readability and maintainability.
- Updated import statements to include type ignoring for YAML to prevent type checking issues.
- Refined the initialization of file lists in the GenericDirectoryScanner operator for better type safety.

Signed-off-by: Victor Chang <[email protected]>
- Updated the CLI output to reflect "Verified" models instead of "Tested" for better clarity.
- Added new model configurations for pancreas segmentation and spleen segmentation in the config file.
- Implemented a method to organize downloaded bundle structures into the standard MONAI format, improving file management.
- Enhanced dependency handling in the AppGenerator to resolve conflicts between configuration and metadata.
- Added unit tests to verify the new bundle organization functionality and ensure correct behavior under various scenarios.

Signed-off-by: Victor Chang <[email protected]>
…nerator

- Added functionality to ensure the bundle root is included in sys.path for script imports.
- Introduced a new model configuration for pediatric abdominal CT segmentation in the config file.
- Improved the organization of model files by preferring PyTorch models over TensorRT models and handling subdirectory structures.
- Enhanced unit tests to verify the new model organization logic and ensure correct behavior under various scenarios.

Signed-off-by: Victor Chang <[email protected]>
- Removed unnecessary whitespace in the app_generator and bundle_downloader files to enhance readability.
- Streamlined import statements in test files for better organization.
- Ensured consistent formatting across various sections of the codebase.

Signed-off-by: Victor Chang <[email protected]>
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants