code: def main():
      import argparse
      import shutil
      from pathlib import Path
  
      from monailabel.utils.others.generic import device_list, file_ext
  
      os.putenv("MASTER_ADDR", "127.0.0.1")
      os.putenv("MASTER_PORT", "1234")
  
      logging.basicConfig(
          level=logging.INFO,
          format="[%(asctime)s] [%(process)s] [%(threadName)s] [%(levelname)s] (%(name)s:%(lineno)d) - %(message)s",
          datefmt="%Y-%m-%d %H:%M:%S",
          force=True,
      )
  
      home = str(Path.home())
      studies = f"{home}/Dataset/Radiology"
  
      parser = argparse.ArgumentParser()
      parser.add_argument("-s", "--studies", default=studies)
      parser.add_argument("-m", "--model", default="segmentation")
      parser.add_argument(
          "-t",
          "--test",
          default="batch_infer",
          choices=("train", "infer", "batch_infer"),
      )
      args = parser.parse_args()
  
      app_dir = os.path.dirname(__file__)
      studies = args.studies
      conf = {
          "models": args.model,
          "preload": "false",
      }
  
      app = MyApp(app_dir, studies, conf)
  
      # Infer
      if args.test == "infer":
          sample = app.next_sample(request={"strategy": "first"})
          image_id = sample["id"]
          image_path = sample["path"]
  
          # Run on all devices
          for device in device_list():
              res = app.infer(
                  request={
                      "model": args.model,
                      "image": image_id,
                      "device": device,
                  }
              )
              # res = app.infer(
              #     request={"model": "vertebra_pipeline", "image": image_id, "device": device, "slicer": False}
              # )
              label = res["file"]
              label_json = res["params"]
              test_dir = os.path.join(args.studies, "test_labels")
              os.makedirs(test_dir, exist_ok=True)
  
              label_file = os.path.join(
                  test_dir, image_id + file_ext(image_path)
              )
              shutil.move(label, label_file)
  
              print(label_json)
              print(f"++++ Image File: {image_path}")
              print(f"++++ Label File: {label_file}")
              break
          return
  
      # Batch Infer
      if args.test == "batch_infer":
          app.batch_infer(
              request={
                  "model": args.model,
                  "multi_gpu": False,
                  "save_label": True,
                  "label_tag": "original",
                  "max_workers": 1,
                  "max_batch_size": 0,
              }
          )
  
          # app.batch_infer(
          #     request={
          #         "model": "pipeline",
          #         "multi_gpu": False,
          #         "save_label": True,
          #         "label_tag": "original",
          #         "max_workers": 1,
          #         "max_batch_size": 0,
          #     }
          # )
  
          return
  
      # Train
      app.train(
          request={
              "model": args.model,
              "max_epochs": 10,
              "dataset": "Dataset",  # PersistentDataset, CacheDataset
              "train_batch_size": 1,
              "val_batch_size": 1,
              "multi_gpu": False,
              "val_split": 0.1,
          },
      )
  
imports: import json
  import logging
  import os
  from typing import Dict
  import lib.configs
  from lib.activelearning import Last
  from lib.infers.deepgrow_pipeline import InferDeepgrowPipeline
  from lib.infers.vertebra_pipeline import InferVertebraPipeline
  import monailabel
  from monailabel.interfaces.app import MONAILabelApp
  from monailabel.interfaces.config import TaskConfig
  from monailabel.interfaces.datastore import Datastore
  from monailabel.interfaces.tasks.infer_v2 import InferTask
  from monailabel.interfaces.tasks.scoring import ScoringMethod
  from monailabel.interfaces.tasks.strategy import Strategy
  from monailabel.interfaces.tasks.train import TrainTask
  from monailabel.scribbles.infer import GMMBasedGraphCut, HistogramBasedGraphCut
  from monailabel.tasks.activelearning.first import First
  from monailabel.tasks.activelearning.random import Random
  from monailabel.tasks.infer.bundle import BundleInferTask
  from monailabel.tasks.train.bundle import BundleTrainTask
  from monailabel.utils.others.class_utils import get_class_names
  from monailabel.utils.others.generic import get_bundle_models, strtobool
  from monailabel.utils.others.planner import HeuristicPlanner
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types