Ë
    €ÏÌ  ã                   óÀ   — d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 ddlmZ  G d	„ d
ej                  «      Z G d„ dej                  «      Zd„ Zdd„Zd„ Zy)z*Utilities for dealing with ML predict API.é    )Úabsolute_import)Údivision)Úunicode_literalsN)Ú
exceptions)Úrequests)Úhttp_clientc                   ó   — e Zd ZdZy)ÚInstancesEncodeErrorzFIndicates that error occurs while decoding the instances in http body.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú/lib/googlecloudsdk/api_lib/ml_engine/predict.pyr
   r
      s   „ ÙNØr   r
   c                   ó   — e Zd ZdZy)ÚHttpRequestFailErrorz2Indicates that the http request fails in some way.Nr   r   r   r   r   r   "   s   „ Ù:Ør   r   c                 ó€   — t        j                  «       j                  d| ||¬«      }|j                  |j                  fS )z,Make http request to get prediction results.ÚPOST)ÚdataÚheaders)r   Ú
GetSessionÚrequestÚstatus_codeÚtext)ÚurlÚbodyr   Úresponses       r   Ú_GetPredictionr    '   s>   € ä× Ñ Ó"×*Ñ*Øˆc˜ gð +ó /€(à	×	Ñ	˜xŸ}™}Ð	,Ð,r   c                 óˆ  — | j                  «       dz   }ddi}d|i}|r||d<   	 t        j                  |d¬«      }t        |||«      \  }}t        |«      t        j                  k7  rt        d	|z   «      ‚	 t        j                  |«      S # t        t        f$ r t        d«      ‚w xY w# t        $ r t        d
|z   «      ‚w xY w)aç  Performs online prediction on the input data file.

  Args:
      model_or_version_ref: a Resource representing either a model or a version.
      instances: a list of JSON or UTF-8 encoded instances to perform
          prediction on.
      signature_name: name of input/output signature in the TF meta graph.

  Returns:
      A json object that contains predictions.

  Raises:
      HttpRequestFailError: if error happens with http request, or parsing
          the http response.
  z:predictúContent-Typeúapplication/jsonÚ	instancesÚsignature_nameT©Ú	sort_keysúRInstances cannot be JSON encoded, probably because the input is not utf-8 encoded.úHTTP request failed. Response: ú=No JSON object could be decoded from the HTTP response body: ©ÚSelfLinkÚjsonÚdumpsÚUnicodeDecodeErrorÚ	TypeErrorr
   r    ÚintÚhttplibÚOKr   ÚloadsÚ
ValueError)	Úmodel_or_version_refr$   r%   r   r   Úcontentr   Úresponse_statusÚresponse_bodys	            r   ÚPredictr:   .   sÿ   € ð  	×%Ñ%Ó'¨*Ñ4€#àÐ/Ð0€'Ø˜)Ð$€'ÙØ .€GÐÑðJÜ:‰:g¨Ô.€Dô $2°#°t¸WÓ#EÑ €/=ÜˆÓœWŸZ™ZÒ'Ü
Ð@Ø,ñ -ó .ð .ðGÜ:‰:mÓ$Ð$øô œiÐ	(ò Jä
ð  Ió Jð JðJûô 
ò GÜ
ð  6Ø8Eñ Fó Gð GðGús   ¤B Á6B) ÂB&Â)Cc                 óz  — | j                  «       dz   }ddi}d|i}	 t        j                  |d¬«      }t        |||«      \  }}t        |«      t        j                  k7  rt        d|z   «      ‚	 t        j                  |«      S # t        t        f$ r t        d«      ‚w xY w# t        $ r t        d	|z   «      ‚w xY w)
až  Performs online explanation on the input data file.

  Args:
      model_or_version_ref: a Resource representing either a model or a version.
      instances: a list of JSON or UTF-8 encoded instances to perform
          prediction on.

  Returns:
      A json object that contains explanations.

  Raises:
      HttpRequestFailError: if error happens with http request, or parsing
          the http response.
  z:explainr"   r#   r$   Tr&   r(   r)   r*   r+   )r6   r$   r   r   r7   r   r8   r9   s           r   ÚExplainr<   W   sñ   € ð 	×%Ñ%Ó'¨*Ñ4€#àÐ/Ð0€'Ø˜)Ð$€'ðJÜ:‰:g¨Ô.€Dô $2°#°t¸WÓ#EÑ €/=ÜˆÓœWŸZ™ZÒ'Ü
Ð@Ø,ñ -ó .ð .ðGÜ:‰:mÓ$Ð$øô œiÐ	(ò Jä
ð  Ió Jð JðJûô 
ò GÜ
ð  6Ø8Eñ Fó Gð GðGús   B Á/B" ÂBÂ"B:)N)r   Ú
__future__r   r   r   r-   Úgooglecloudsdk.corer   Úcore_exceptionsÚgooglecloudsdk.core.credentialsr   Ú	six.movesr   r2   ÚErrorr
   r   r    r:   r<   r   r   r   Ú<module>rC      sU   ðñ 1å &Ý Ý 'ã å =Ý 4å ,ô˜?×0Ñ0ô ô
˜?×0Ñ0ô ò
-ó&GóR#Gr   