
                         :    d Z ddlmZ ddlmZ ddZd Z	 	 d	dZy)
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                 P   t        j                  |d      }|r|S |xs t        j                  }|t        j                  k(  rddlm} |j                  }nK|t        j                  k(  rddlm} |j                  }n%|t        j                  k(  rddlm} |j                  } |       S )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                    | xs t         j                  } | t         j                  k(  rddlm} |j                  }nK| t         j
                  k(  rddlm} |j                  }n%| t         j                  k(  rddlm} |j                  } |fi |S )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                     |xs t         j                  }t        || fi |}t        || |      }t        j                  |||      rt        j
                  |      }|j                  ||      }dt        |      iS )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,   ^   sx     E+EE)I88&
vy)
4%**9e^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   