
                         &   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	l	mZ dd
l	mZ dZddiZ ej                   ej"                  j$                  ej"                  j&                         G d dej(                               Zy)zai-platform explain command.    )absolute_import)division)unicode_literals)predict)base)endpoint_util)flags)predict_utilities)region_utild   EXAMPLESz        To get explanations for an AI Platform version model with the
        version 'version' and with the name 'model-name', run:

          $ {command} explain --model=model-name --version=version           --json-instances=instances.json
        c                   *    e Zd ZdZeZed        Zd Zy)Explaina  Run AI Platform explanation.

     `{command}` sends an explain request to AI Platform for the given
     instances. This command will read up to 100 instances, though the service
     itself will accept instances up to the payload limit size (currently,
     1.5MB).
  c                 2   | j                  ddd       t        j                  d      j                  |        | j                  dd       | j	                  d	      }|j                  d
d       |j                  dd       |j                  dd       y)z Register flags for this command.z--modelTzName of the model.)requiredhelp)include_globalz	--versionzModel version to be used.

If unspecified, the default version of the model will be used. To list model
versions run

  $ {parent_command} versions list
)r   )r   z--json-requesta@          Path to a local file containing the body of JSON request.

        An example of a JSON request:

            {
              "instances": [
                {"x": [1, 2], "y": [3, 4]},
                {"x": [-1, -2], "y": [-3, -4]}
              ]
            }

        This flag accepts "-" for stdin.
        z--json-instancesaL          Path to a local file from which instances are read.
        Instances are in JSON format; newline delimited.

        An example of the JSON instances file:

            {"images": [0.0, ..., 0.1], "key": 3}
            {"images": [0.0, ..., 0.1], "key": 2}
            ...

        This flag accepts "-" for stdin.
        z--text-instancesa6          Path to a local file from which instances are read.
        Instances are in UTF-8 encoded text format; newline delimited.

        An example of the text instances file:

            107,4.9,2.5,4.5,1.7
            100,5.7,2.8,4.1,1.3
            ...

        This flag accepts "-" for stdin.
        N)add_argumentr	   GetRegionArgAddToParseradd_mutually_exclusive_group)parsergroups     "lib/surface/ai_platform/explain.pyArgszExplain.Args5   s     	D7KL	d+77?
  	 ///>E	    
   
      c                    t        j                  |j                  |j                  |j                  t
              }t        j                  |      }t        j                  |      5  t        j                  |j                  |j                        }t        j                  ||      }ddd       |j                  d      s)t        j                   j#                  d            |_        S # 1 sw Y   ExY w)zThis 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.
    )limit)regionNformatpredictions)r
   ReadInstancesFromArgsjson_requestjson_instancestext_instancesINPUT_INSTANCES_LIMITr   	GetRegionr   MlEndpointOverridesParseModelOrVersionRefmodelversionr   r   IsSpecifiedGetDefaultFormatgetr    )selfargs	instancesr   model_or_version_refresultss         r   RunzExplain.Runr   s     "77#	%I ""4(F		*	*&	9.EE
**dll$ 4i@g 
:
 H%%66
++m
$&dk N 
:	9s   'AC,,C5N)	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr   r4    r   r   r   r   )   s&      -: :xr   r   N)r8   
__future__r   r   r    googlecloudsdk.api_lib.ml_enginer   googlecloudsdk.callioper   $googlecloudsdk.command_lib.ml_enginer   r	   r
   r   r&   r9   ReleaseTracksReleaseTrackALPHABETACommandr   r<   r   r   <module>rF      s    # &  ' 4 ( > 6 B < 		 D%%++T->->-C-CDcdll c Ecr   