def _Run(args):
  """This is what gets called when the user runs this command.

  Args:
    args: an argparse namespace. All the arguments that were provided to this
      command invocation.

  Returns:
    A json object that contains predictions.
  """
  instances = predict_utilities.ReadInstancesFromArgs(
      args.json_request,
      args.json_instances,
      args.text_instances,
      limit=INPUT_INSTANCES_LIMIT)

  with endpoint_util.MlEndpointOverrides(region=args.region):
    model_or_version_ref = predict_utilities.ParseModelOrVersionRef(
        args.model, args.version)
    if (args.signature_name is None and
        predict_utilities.CheckRuntimeVersion(args.model, args.version)):
      log.status.Print(
          'You are running on a runtime version >= 1.8. '
          'If the signature defined in the model is '
          'not serving_default then you must specify it via '
          '--signature-name flag, otherwise the command may fail.')
    results = predict.Predict(
        model_or_version_ref, instances, signature_name=args.signature_name)

  if not args.IsSpecified('format'):
    # default format is based on the response.
    args.format = predict_utilities.GetDefaultFormat(
        results.get('predictions'))

  return results
Example #2
0
def _Run(args):
  with endpoint_util.MlEndpointOverrides(region=args.region):
    versions_client = versions_api.VersionsClient()
    operations_client = operations.OperationsClient()
    version_ref = args.CONCEPTS.version.Parse()
    versions_util.Update(versions_client, operations_client, version_ref, args)
    log.UpdatedResource(args.version, kind='AI Platform version')
Example #3
0
def _Run(args):
    region = region_util.GetRegion(args)
    with endpoint_util.MlEndpointOverrides(region=region):
        models_client = models.ModelsClient()
        operations_client = operations.OperationsClient()
        models_util.Update(models_client, operations_client, args)
        log.UpdatedResource(args.model, kind='ai platform model')
Example #4
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         client = versions_api.VersionsClient()
         return versions_util.Delete(client,
                                     operations.OperationsClient(),
                                     args.version,
                                     model=args.model)
Example #5
0
 def testConnectToRegion(self):
     existing_override = properties.VALUES.api_endpoint_overrides.ml.Get()
     with util.MlEndpointOverrides('us-central1'):
         self.assertEqual(properties.VALUES.api_endpoint_overrides.ml.Get(),
                          'https://us-central1-ml.googleapis.com/')
     self.assertEqual(properties.VALUES.api_endpoint_overrides.ml.Get(),
                      existing_override)
Example #6
0
 def Run(self, args):
     region = region_util.GetRegion(args)
     with endpoint_util.MlEndpointOverrides(region=region):
         client = versions_api.VersionsClient()
         labels = versions_util.ParseCreateLabels(client, args)
         framework = flags.FRAMEWORK_MAPPER.GetEnumForChoice(args.framework)
         accelerator = flags.ParseAcceleratorFlag(args.accelerator)
         return versions_util.Create(client,
                                     operations.OperationsClient(),
                                     args.version,
                                     model=args.model,
                                     origin=args.origin,
                                     staging_bucket=args.staging_bucket,
                                     runtime_version=args.runtime_version,
                                     config_file=args.config,
                                     asyncronous=args.async_,
                                     description=args.description,
                                     labels=labels,
                                     machine_type=args.machine_type,
                                     framework=framework,
                                     python_version=args.python_version,
                                     accelerator_config=accelerator,
                                     min_nodes=args.min_nodes,
                                     max_nodes=args.max_nodes,
                                     metrics=args.metric_targets,
                                     autoscaling_hidden=False)
Example #7
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        instances = predict_utilities.ReadInstancesFromArgs(
            args.json_request,
            args.json_instances,
            args.text_instances,
            limit=INPUT_INSTANCES_LIMIT)

        with endpoint_util.MlEndpointOverrides(region=args.region):
            model_or_version_ref = predict_utilities.ParseModelOrVersionRef(
                args.model, args.version)
            results = predict.Explain(model_or_version_ref, instances)

        if not args.IsSpecified('format'):
            # default format is based on the response.
            args.format = predict_utilities.GetDefaultFormat(
                results.get('predictions'))

        return results
Example #8
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         client = versions_api.VersionsClient()
         labels = versions_util.ParseCreateLabels(client, args)
         framework = flags.FRAMEWORK_MAPPER.GetEnumForChoice(args.framework)
         accelerator = flags.ParseAcceleratorFlag(args.accelerator)
         return versions_util.Create(
             client,
             operations.OperationsClient(),
             args.version,
             model=args.model,
             origin=args.origin,
             staging_bucket=args.staging_bucket,
             runtime_version=args.runtime_version,
             config_file=args.config,
             asyncronous=args.async_,
             labels=labels,
             description=args.description,
             machine_type=args.machine_type,
             framework=framework,
             python_version=args.python_version,
             prediction_class=args.prediction_class,
             package_uris=args.package_uris,
             service_account=args.service_account,
             accelerator_config=accelerator,
             explanation_method=args.explanation_method,
             num_integral_steps=args.num_integral_steps,
             num_paths=args.num_paths)
Example #9
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         condition = iam_util.ValidateAndExtractCondition(args)
         iam_util.ValidateMutexConditionAndPrimitiveRoles(
             condition, args.role)
         return models_util.AddIamPolicyBindingWithCondition(
             models.ModelsClient(), args.model, args.member, args.role,
             condition)
Example #10
0
def _Run(args):
    region = region_util.GetRegion(args)
    with endpoint_util.MlEndpointOverrides(region=region):
        client = versions_api.VersionsClient()
        return versions_util.Delete(client,
                                    operations.OperationsClient(),
                                    args.version,
                                    model=args.model)
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The specified function with its description and configured filter.
    """
        with endpoint_util.MlEndpointOverrides(region=args.region):
            client = models.ModelsClient()
            return models_util.RemoveIamPolicyBinding(client, args.model,
                                                      args.member, args.role)
Example #12
0
 def _Run(self, args, support_console_logging=False):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         models_client = models.ModelsClient()
         labels = models_util.ParseCreateLabels(models_client, args)
         enable_console_logging = (support_console_logging
                                   and args.enable_console_logging)
         model = models_util.Create(
             models_client,
             args.model,
             args,
             enable_logging=args.enable_logging,
             enable_console_logging=enable_console_logging,
             labels=labels,
             description=args.description)
         log.CreatedResource(model.name, kind='ml engine model')
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The specified function with its description and configured filter.
    """
        with endpoint_util.MlEndpointOverrides(region=args.region):
            condition = iam_util.ValidateAndExtractCondition(args)
            iam_util.ValidateMutexConditionAndPrimitiveRoles(
                condition, args.role)
            return models_util.RemoveIamPolicyBindingWithCondition(
                models.ModelsClient(), args.model, args.member, args.role,
                condition)
Example #14
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         client = versions_api.VersionsClient()
         labels = versions_util.ParseCreateLabels(client, args)
         framework = flags.FRAMEWORK_MAPPER.GetEnumForChoice(args.framework)
         return versions_util.Create(client,
                                     operations.OperationsClient(),
                                     args.version,
                                     model=args.model,
                                     origin=args.origin,
                                     staging_bucket=args.staging_bucket,
                                     runtime_version=args.runtime_version,
                                     config_file=args.config,
                                     asyncronous=args.async_,
                                     description=args.description,
                                     labels=labels,
                                     framework=framework,
                                     python_version=args.python_version)
Example #15
0
 def Run(self, args):
     region = region_util.GetRegion(args)
     with endpoint_util.MlEndpointOverrides(region=region):
         client = versions_api.VersionsClient()
         labels = versions_util.ParseCreateLabels(client, args)
         framework = flags.FRAMEWORK_MAPPER.GetEnumForChoice(args.framework)
         accelerator = flags.ParseAcceleratorFlag(args.accelerator)
         return versions_util.Create(
             client,
             operations.OperationsClient(),
             args.version,
             model=args.model,
             origin=args.origin,
             staging_bucket=args.staging_bucket,
             runtime_version=args.runtime_version,
             config_file=args.config,
             asyncronous=args.async_,
             labels=labels,
             description=args.description,
             machine_type=args.machine_type,
             framework=framework,
             python_version=args.python_version,
             prediction_class=args.prediction_class,
             package_uris=args.package_uris,
             service_account=args.service_account,
             accelerator_config=accelerator,
             explanation_method=args.explanation_method,
             num_integral_steps=args.num_integral_steps,
             num_paths=args.num_paths,
             image=args.image,
             command=args.command,
             container_args=args.args,
             env_vars=args.env_vars,
             ports=args.ports,
             predict_route=args.predict_route,
             health_route=args.health_route,
             min_nodes=args.min_nodes,
             max_nodes=args.max_nodes,
             metrics=args.metric_targets,
             containers_hidden=False,
             autoscaling_hidden=False)
Example #16
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         models_client = models.ModelsClient()
         operations_client = operations.OperationsClient()
         models_util.Update(models_client, operations_client, args)
         log.UpdatedResource(args.model, kind='ml engine model')
Example #17
0
def _Run(args):
    with endpoint_util.MlEndpointOverrides(region=args.region):
        client = versions_api.VersionsClient()
        return versions_util.SetDefault(client, args.version, model=args.model)
Example #18
0
def _Run(args):
  with endpoint_util.MlEndpointOverrides(region=args.region):
    return models.ModelsClient().Get(args.model)
Example #19
0
def _Run(args):
    region = region_util.GetRegion(args)
    with endpoint_util.MlEndpointOverrides(region=region):
        models_client = models.ModelsClient()
        operations_client = operations.OperationsClient()
        return models_util.Delete(models_client, operations_client, args.model)
Example #20
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         client = versions_api.VersionsClient()
         return versions_util.List(client, model=args.model)
Example #21
0
def _Run(args):
  with endpoint_util.MlEndpointOverrides(region=args.region):
    return locations.LocationsClient().Get(args.location)
Example #22
0
def _Run(args):
    region = region_util.GetRegion(args)
    with endpoint_util.MlEndpointOverrides(region=region):
        return models_util.GetIamPolicy(models.ModelsClient(), args.model)
Example #23
0
def _Run(args):
    with endpoint_util.MlEndpointOverrides(region=args.region):
        return models_util.SetIamPolicy(models.ModelsClient(), args.model,
                                        args.policy_file)
Example #24
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         client = operations.OperationsClient()
         return operations_util.Wait(client, args.operation)
Example #25
0
def _Run(args):
  region = region_util.GetRegion(args)
  with endpoint_util.MlEndpointOverrides(region=region):
    return models_util.List(models.ModelsClient())
Example #26
0
 def Run(self, args):
   with endpoint_util.MlEndpointOverrides(region=args.region):
     models_client = models.ModelsClient()
     operations_client = operations.OperationsClient()
     return models_util.Delete(models_client, operations_client, args.model)
Example #27
0
 def Run(self, args):
     with endpoint_util.MlEndpointOverrides(region=args.region):
         return models_util.GetIamPolicy(models.ModelsClient(), args.model)
Example #28
0
def _Run(args):
    region = region_util.GetRegion(args)
    with endpoint_util.MlEndpointOverrides(region=region):
        client = models.ModelsClient()
        return models_util.RemoveIamPolicyBinding(client, args.model,
                                                  args.member, args.role)
Example #29
0
def _Run(args):
    region = region_util.GetRegion(args)
    with endpoint_util.MlEndpointOverrides(region=region):
        client = versions_api.VersionsClient()
        return versions_util.List(client, model=args.model)
Example #30
0
def _Run(args):
    with endpoint_util.MlEndpointOverrides(region=args.region):
        client = operations.OperationsClient()
        return operations_util.Describe(client, args.operation)