
                         >    S r SSKJr  SSKJr  SS jrS r  S	S jrg)
zUtilities for running predictions.

Includes (from the Cloud ML SDK):
- _predict_lib

Important changes:
- Remove interfaces for TensorFlowModel (they don't change behavior).
- Set from_client(skip_preprocessing=True) and remove the pre-processing code.
   )custom_code_utils)prediction_utilsNc                 l   [         R                  " US5      nU(       a  U$ U=(       d    [        R                  nU[        R                  :X  a  SSKJn  UR                  nOMU[        R                  :X  a  SSKJn  UR                  nO&U[        R                  :X  a  SSKJn  UR                  nW" U 5      $ )a  Creates and returns the appropriate model.

Creates and returns a Model if no user specified model is
provided. Otherwise, the user specified model is imported, created, and
returned.

Args:
  client: An instance of PredictionClient for performing prediction.
  model_path: The path to the exported model (e.g. session_bundle or
    SavedModel)
  framework: The framework used to train the model.

Returns:
  An instance of the appropriate model class.
Nr   tf_prediction_libsk_xg_prediction_lib)r   create_user_modelr   TENSORFLOW_FRAMEWORK_NAME
frameworksr   TensorFlowModelSCIKIT_LEARN_FRAMEWORK_NAMEr	   SklearnModelXGBOOST_FRAMEWORK_NAMEXGBoostModel)client
model_path	frameworkunused_kwargscustom_modelr   	model_clsr	   s           <lib/third_party/ml_sdk/cloud/ml/prediction/prediction_lib.pycreate_modelr      s      #44ZF,E+EE)"<<<-!11I$@@@0$11I$;;;0$11I	6	    c                 .   U =(       d    [         R                  n U [         R                  :X  a  SSKJn  UR                  nOMU [         R
                  :X  a  SSKJn  UR                  nO&U [         R                  :X  a  SSKJn  UR                  nW" U40 UD6$ )a  Creates and returns the appropriate prediction client.

Creates and returns a PredictionClient based on the provided framework.

Args:
  framework: The framework used to train the model.
  model_path: The path to the exported model (e.g. session_bundle or
    SavedModel)
  **kwargs: Optional additional params to pass to the client constructor (such
    as TF tags).

Returns:
  An instance of the appropriate PredictionClient.
r   r   r   )
r   r   r   r   create_tf_session_clientr   r	   create_sklearn_clientr   create_xgboost_client)r   r   kwargsr   create_client_fnr	   s         r   create_clientr!   A   s     E+EE)"<<<-(AA$@@@0+AA$;;;0+AA	*	/	//r   c                     U=(       d    [         R                  n[        X040 UD6n[        XPU5      n[         R                  " X6U5      (       a  [         R
                  " U5      nUR                  X!S9nS[        U5      0$ )zRun a prediction locally.)signature_namepredictions)r   r   r!   r   should_base64_decodedecode_base64predictlist)	model_dirr#   	instancesr   r   r   modelr$   s           r   local_predictr,   ^   ss     E+EE)88&
v)
4%**9^LL ..y9IiG+
k*	++r   )N)NNNN)__doc__ r   r   r   r!   r,    r   r   <module>r0      s,       F0: BF 	,r   