
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrS r	Sr
S	rS
rS rS rS rS rS r\S:X  a  \" 5         gg)zUtilities for running predictions locally.

This module will always be run within a subprocess, and therefore normal
conventions of Cloud SDK do not apply here.
    )absolute_import)division)print_function)unicode_literalsNc                  :    [        U S[        R                  0UD6  g)zPrint to stderr.fileN)printsysstderr)argskwargss     9lib/googlecloudsdk/command_lib/ml_engine/local_predict.pyeprintr      s     )CJJ)&)    zsPlease verify the installed tensorflow version with: "python -c 'import tensorflow; print tensorflow.__version__'".zjPlease verify the installed sklearn version with: "python -c 'import sklearn; print sklearn.__version__'".zjPlease verify the installed xgboost version with: "python -c 'import xgboost; print xgboost.__version__'".c                     SSK Js  Jn   UR
                  U :  a   [	        SR                  U 5      [        5        g g! [         a    [	        S5         gf = f! [        [        4 a  n[	        SUS[        5         SnAgSnAff = f)	z@Check whether TensorFlow is installed at an appropriate version.r   NzNCannot import Tensorflow. Please verify "python -c 'import tensorflow'" works.Fz(Tensorflow version must be at least {} .z6Error while getting the installed TensorFlow version: 
T)
tensorflow.compat.v1compatv1ImportErrorr   __version__formatVERIFY_TENSORFLOW_VERSION	NameErrorAttributeError)versiontfes      r   _verify_tensorflowr   3   s    %%	~~7>>wG&(   
 
 
 6 7 ^	$ 
CQ*,s&   	> /A AAB)B  Bc                 F    SSK n SSKn UR                  U :  a   [        SR                  U 5      [        5        g g	! [         a    [        S5         gf = f! [         a    [        S5         gf = f! [        [        4 a  n[        SUS[        5         SnAgSnAff = f)
zBCheck whether scikit-learn is installed at an appropriate version.r   NzfCannot import scipy, which is needed for scikit-learn. Please verify "python -c 'import scipy'" works.FzHCannot import sklearn. Please verify "python -c 'import sklearn'" works.z*Scikit-learn version must be at least {} .z8Error while getting the installed scikit-learn version: r   T)	scipyr   r   sklearnr   r   VERIFY_SCIKIT_LEARN_VERSIONr   r   )r   r!   r"   r   s       r   _verify_scikit_learnr$   K   s    W$9@@I(* % 
- 
 
 8 9 
 
 3 4 ^	$ 
Eq$&(s7   > A /A4 AAA10A14B BB c                     SSK n UR                  U :  a   [        SR	                  U 5      [
        5        g g! [         a    [        S5         gf = f! [        [        4 a  n[        SUS[
        5         SnAgSnAff = f)	z=Check whether xgboost is installed at an appropriate version.r   NzHCannot import xgboost. Please verify "python -c 'import xgboost'" works.Fz%Xgboost version must be at least {} .z3Error while getting the installed xgboost version: r   T)xgboostr   r   r   r   VERIFY_XGBOOST_VERSIONr   r   )r   r&   r   s      r   _verify_xgboostr(   k   s    W$4;;GD#% % 
 
 
 3 4 ^	$ 
@!T!#s&   9 /A AAB $A;;B c                    U S:X  a'  [        S5      (       d  [        R                  " S5        gU S:X  a'  [        S5      (       d  [        R                  " S5        gU S:X  a(  [	        S5      (       d  [        R                  " S5        ggg)	z=Verifies the appropriate ML libs are installed per framework.
tensorflowz1.0.0scikit_learnz0.18.1r&   z0.6a2N)r   r
   exitr$   r(   )	frameworks    r   _verify_ml_libsr/      sc    ,'9''B'BHHRLN"+?+I+IHHRLIog&>&>HHRL '?r   c                     [         R                  " 5       n U R                  SSSS9  U R                  SSS SS9  U R                  S	SS
S9  U R                  5       u  pUR                  c"  SSKJn  UR                  UR                  5      nOUR                  nU(       a  [        U5        SSKJ
n  / n[        R                   H9  n[        R                  " UR                  S5      5      nUR!                  U5        M;     UR#                  UR                  UUUR$                  S9n	['        [        R(                  " U	5      5        g )Nz--model-dirTzPath of the model.)requiredhelpz--frameworkFzThe ML framework used to train this version of the model. If not specified, the framework will be identified based on the model file name stored in the specified model-dir)r1   defaultr2   z--signature-namez0Tensorflow signature to select input/output map.r   )prediction_utils)prediction_libr   )	model_dir	instancesr.   signature_name)argparseArgumentParseradd_argumentparse_known_argsr.   cloud.ml.predictionr4   detect_frameworkr6   r/   r5   r
   stdinjsonloadsrstripappendlocal_predictr8   r	   dumps)
parserr   _r4   r.   r5   r7   lineinstancepredictionss
             r   mainrK      s+   ""$&md9MNE	  G 	(5M  O##%'$	^^4 11$..AIII
 1 )iidzz$++d+,HX  ,,((	 - *+
 

; r   __main__)__doc__
__future__r   r   r   r   r9   r@   r
   r   r   r#   r'   r   r$   r(   r/   rK   __name__ r   r   <module>rQ      sn    '  % '   
*@  ? : 
0@0'!T z& r   