original_docstring: Driver method that parses arguements and intializes providers
      
docstring: Driver method that parses arguements and intializes providers
docstring_tokens: Driver method that parses arguements and intializes providers
code: def main():
      """Driver method that parses arguements and intializes providers
      """
      parser = argparse.ArgumentParser()
      parser.add_argument('--map-urn', type=str, required=True,
                          help="MAP Container <image>:<tag> to de deployed for inference")
      parser.add_argument('--map-entrypoint', type=str, required=True,
                          help="Entry point command for MAP Container")
      parser.add_argument('--map-cpu', type=int, required=True, help="Maximum CPU cores needed by MAP Container")
      parser.add_argument('--map-memory', type=int, required=True,
                          help="Maximum memory in Megabytes needed by MAP Container")
      parser.add_argument('--map-gpu', type=int, required=True, help="Maximum GPUs needed by MAP Container")
      parser.add_argument('--map-input-path', type=str, required=True,
                          help="Input directory path of MAP Container")
      parser.add_argument('--map-output-path', type=str, required=True,
                          help="Output directory path of MAP Container")
      parser.add_argument('--map-model-path', type=str, required=False,
                          help="Model directory path of MAP Container")
      parser.add_argument('--payload-host-path', type=str, required=True,
                          help="Host path of payload directory")
      parser.add_argument('--port', type=int, required=False, default=8000,
                          help="Host port of MONAI Inference Service")
  
      args = parser.parse_args()
  
      if (args.map_cpu < 1):
          raise Exception(f'MAP cpu value can not be less than 1, provided value is \"{args.map_cpu}\"')
      if (args.map_gpu < 0):
          raise Exception(f'MAP gpu value can not be less than 0, provided value is \"{args.map_gpu}\"')
      if (args.map_memory < 256):
          raise Exception(f'MAP memory value can not be less than 256, provided value is \"{args.map_memory}\"')
  
      config.load_incluster_config()
  
      service_config = ServerConfig(args.map_urn, args.map_entrypoint.split(' '), args.map_cpu,
                                    args.map_memory, args.map_gpu, args.map_input_path,
                                    args.map_output_path, args.map_model_path, args.payload_host_path)
      kubernetes_handler = KubernetesHandler(service_config)
      payload_provider = PayloadProvider(args.payload_host_path,
                                         args.map_input_path,
                                         args.map_output_path)
  
      @app.post("/upload/")
      def upload_file(file: UploadFile = File(...)) -> FileResponse:
          """Defines REST POST Endpoint for Uploading input payloads.
          Will trigger inference job sequentially after uploading payload
  
          Args:
              file (UploadFile, optional): .zip file provided by user to be moved
              and extracted in shared volume directory for input payloads. Defaults to File(...).
  
          Returns:
              FileResponse: Asynchronous object for FastAPI to stream compressed .zip folder with
              the output payload from running the MONAI Application Package
          """
          logger.info("/upload/ Request Received")
          if not request_mutex.acquire(False):
              logger.info("Request rejected as MIS is currently servicing another request")
              raise HTTPException(
                  status_code=500,
                  detail="Request timed out since MAP container's pod was in pending state after timeout")
          else:
              logger.info("Acquired resource lock")
  
          try:
              payload_provider.upload_input_payload(file)
              kubernetes_handler.create_kubernetes_pod()
  
              try:
                  pod_status = kubernetes_handler.watch_kubernetes_pod()
              finally:
                  kubernetes_handler.delete_kubernetes_pod()
  
              if (pod_status is PodStatus.Pending):
                  logger.error("Request timed out since MAP container's pod was in pending state after timeout")
                  raise HTTPException(
                      status_code=500,
                      detail="Request timed out since MAP container's pod was in pending state after timeout")
              elif (pod_status is PodStatus.Running):
                  logger.error("Request timed out since MAP container's pod was in running state after timeout")
                  raise HTTPException(
                      status_code=500,
                      detail="Request timed out since MAP container's pod was in running state after timeout")
              elif (pod_status is PodStatus.Failed):
                  logger.info("Request failed since MAP container's pod failed")
                  raise HTTPException(status_code=500, detail="Request failed since MAP container's pod failed")
              elif (pod_status is PodStatus.Succeeded):
                  logger.info("MAP container's pod completed")
                  return payload_provider.stream_output_payload()
          except Exception as e:
              logging.error(e, exc_info=True)
          finally:
              logger.info("Releasing resource lock")
              request_mutex.release()
  
      print(f'MAP URN: \"{args.map_urn}\"')
      print(f'MAP entrypoint: \"{args.map_entrypoint}\"')
      print(f'MAP cpu: \"{args.map_cpu}\"')
      print(f'MAP memory: \"{args.map_memory}\"')
      print(f'MAP gpu: \"{args.map_gpu}\"')
      print(f'MAP input path: \"{args.map_input_path}\"')
      print(f'MAP output path: \"{args.map_output_path}\"')
      print(f'MAP model path: \"{args.map_model_path}\"')
      print(f'payload host path: \"{args.payload_host_path}\"')
      print(f'MIS host: \"{MIS_HOST}\"')
      print(f'MIS port: \"{args.port}\"')
  
      uvicorn.run(app, host=MIS_HOST, port=args.port, log_config=logging_config)
code_tokens: def main ( ) : parser = argparse . ArgumentParser ( ) parser . add_argument ( '--map-urn' , type = str , required = True , help = "MAP Container <image>:<tag> to de deployed for inference" ) parser . add_argument ( '--map-entrypoint' , type = str , required = True , help = "Entry point command for MAP Container" ) parser . add_argument ( '--map-cpu' , type = int , required = True , help = "Maximum CPU cores needed by MAP Container" ) parser . add_argument ( '--map-memory' , type = int , required = True , help = "Maximum memory in Megabytes needed by MAP Container" ) parser . add_argument ( '--map-gpu' , type = int , required = True , help = "Maximum GPUs needed by MAP Container" ) parser . add_argument ( '--map-input-path' , type = str , required = True , help = "Input directory path of MAP Container" ) parser . add_argument ( '--map-output-path' , type = str , required = True , help = "Output directory path of MAP Container" ) parser . add_argument ( '--map-model-path' , type = str , required = False , help = "Model directory path of MAP Container" ) parser . add_argument ( '--payload-host-path' , type = str , required = True , help = "Host path of payload directory" ) parser . add_argument ( '--port' , type = int , required = False , default = 8000 , help = "Host port of MONAI Inference Service" ) args = parser . parse_args ( ) if ( args . map_cpu < 1 ) : raise Exception ( f'MAP cpu value can not be less than 1, provided value is \"{args.map_cpu}\"' ) if ( args . map_gpu < 0 ) : raise Exception ( f'MAP gpu value can not be less than 0, provided value is \"{args.map_gpu}\"' ) if ( args . map_memory < 256 ) : raise Exception ( f'MAP memory value can not be less than 256, provided value is \"{args.map_memory}\"' ) config . load_incluster_config ( ) service_config = ServerConfig ( args . map_urn , args . map_entrypoint . split ( ' ' ) , args . map_cpu , args . map_memory , args . map_gpu , args . map_input_path , args . map_output_path , args . map_model_path , args . payload_host_path ) kubernetes_handler = KubernetesHandler ( service_config ) payload_provider = PayloadProvider ( args . payload_host_path , args . map_input_path , args . map_output_path ) @ app . post ( "/upload/" ) def upload_file ( file : UploadFile = File ( ... ) ) -> FileResponse : """Defines REST POST Endpoint for Uploading input payloads.
          Will trigger inference job sequentially after uploading payload
  
          Args:
              file (UploadFile, optional): .zip file provided by user to be moved
              and extracted in shared volume directory for input payloads. Defaults to File(...).
  
          Returns:
              FileResponse: Asynchronous object for FastAPI to stream compressed .zip folder with
              the output payload from running the MONAI Application Package
          """ logger . info ( "/upload/ Request Received" ) if not request_mutex . acquire ( False ) : logger . info ( "Request rejected as MIS is currently servicing another request" ) raise HTTPException ( status_code = 500 , detail = "Request timed out since MAP container's pod was in pending state after timeout" ) else : logger . info ( "Acquired resource lock" ) try : payload_provider . upload_input_payload ( file ) kubernetes_handler . create_kubernetes_pod ( ) try : pod_status = kubernetes_handler . watch_kubernetes_pod ( ) finally : kubernetes_handler . delete_kubernetes_pod ( ) if ( pod_status is PodStatus . Pending ) : logger . error ( "Request timed out since MAP container's pod was in pending state after timeout" ) raise HTTPException ( status_code = 500 , detail = "Request timed out since MAP container's pod was in pending state after timeout" ) elif ( pod_status is PodStatus . Running ) : logger . error ( "Request timed out since MAP container's pod was in running state after timeout" ) raise HTTPException ( status_code = 500 , detail = "Request timed out since MAP container's pod was in running state after timeout" ) elif ( pod_status is PodStatus . Failed ) : logger . info ( "Request failed since MAP container's pod failed" ) raise HTTPException ( status_code = 500 , detail = "Request failed since MAP container's pod failed" ) elif ( pod_status is PodStatus . Succeeded ) : logger . info ( "MAP container's pod completed" ) return payload_provider . stream_output_payload ( ) except Exception as e : logging . error ( e , exc_info = True ) finally : logger . info ( "Releasing resource lock" ) request_mutex . release ( ) print ( f'MAP URN: \"{args.map_urn}\"' ) print ( f'MAP entrypoint: \"{args.map_entrypoint}\"' ) print ( f'MAP cpu: \"{args.map_cpu}\"' ) print ( f'MAP memory: \"{args.map_memory}\"' ) print ( f'MAP gpu: \"{args.map_gpu}\"' ) print ( f'MAP input path: \"{args.map_input_path}\"' ) print ( f'MAP output path: \"{args.map_output_path}\"' ) print ( f'MAP model path: \"{args.map_model_path}\"' ) print ( f'payload host path: \"{args.payload_host_path}\"' ) print ( f'MIS host: \"{MIS_HOST}\"' ) print ( f'MIS port: \"{args.port}\"' ) uvicorn . run ( app , host = MIS_HOST , port = args . port , log_config = logging_config )
short_docstring: Driver method that parses arguements and intializes providers
short_docstring_tokens: Driver method that parses arguements and intializes providers
comment: """Driver method that parses arguements and intializes providers
      """$SEP$"""Defines REST POST Endpoint for Uploading input payloads.
          Will trigger inference job sequentially after uploading payload
  
          Args:
              file (UploadFile, optional): .zip file provided by user to be moved
              and extracted in shared volume directory for input payloads. Defaults to File(...).
  
          Returns:
              FileResponse: Asynchronous object for FastAPI to stream compressed .zip folder with
              the output payload from running the MONAI Application Package
          """