
    9i:Z                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  SS
KJrJrJrJrJrJrJr  SSKJ r J!r!J"r"  SSK#J$r$J%r%  SSK&J'r'  SSK(J)r)  S r*S r+S r,S r-S r.S r/g)    N)Path   )create_pipeline)MODEL_FILE_PREFIX)load_pipeline_config)get_model_paths)get_all_supported_repo_namessetup)logging)get_dep_versionget_genai_dep_specsget_genai_fastdeploy_specget_paddle2onnx_dep_specsget_serving_dep_specsis_dep_availableis_paddle2onnx_plugin_available)get_gpu_compute_capabilityget_paddle_cuda_versionis_cuda_available)install_packagesuninstall_packages)interactive_get_pipeline)PIPELINE_ARGUMENTSc                     S n [         R                  " S5      nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      nUR                  SSS	S
S9  UR                  SSSS9  UR                  S[        SS/SSS9  UR                  SSSSSS9  UR                  SSSSS9  UR                  S[        SS S!S"9  UR                  S#[        S$S%9  UR                  S&[        S S'S(9  UR                  S)[        S S*S(9  UR                  S+[        S S,S(9  UR                  S-SS.S9  UR                  S/[
        R                  S0S%9  UR                  S1[        S S2S(9  UR                  S3SS4S9  UR                  S5[        S6S7S(9  UR                  S8[        S9S:S(9  UR                  S;SS<S9  UR                  S=[        S>S%9  UR                  S?[        S@S%9  UR                  SA[        SBSCS(9  UR                  5       u  pgUR                  n/ n	UR                  Gc0  UR                  (       Gd  UR                  (       Gd  UGb  [        R                  R                  U5      (       a  [!        U5      SD   n
OUn
U
["        ;  aW  SER%                  ["        R&                  " 5       5      n[(        R*                  " SFU
 SGU SH35        [,        R.                  " SI5        ["        U
   n	U	c  / n	UR                  U
R1                  5        SJ35      nU	 H<  nUR                  USK   USL   [2        L a  U OUSL   UR5                  SMSNU
 SO35      S%9  M>     X4$ )Pzparse cli argumentsc                 0    U S;   a  gU S;   a  gU S;   a  gU $ )z]convert str type value
to None type if it is "None",
to bool type if it means True or False.
)NonenoneNONEN)TRUETruetrueTtT)FALSEFalsefalseFfF )ss    S/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/paddlex_cli.py	parse_strargs_cfg.<locals>.parse_str4   s-    
 ((4477    zCommand-line interface for PaddleX. Use the options below to install plugins, run pipeline predictions, or start the serving application.zInstall PaddleX OptionszPipeline Predict OptionszServing OptionszPaddle2ONNX Optionsz	--install*PLUGINz"Install specified PaddleX plugins.)nargsmetavarhelpz	--no_deps
store_truez>Install custom development plugins without their dependencies.)actionr3   z
--platformz
github.comz	gitee.comz7Platform to use for installation (default: github.com).)typechoicesdefaultr3   z-yz--yesupdate_reposz6Automatically confirm prompts and update repositories.)destr5   r3   z--use_local_reposFz%Use local repositories if they exist.)r5   r8   r3   z--deps_to_replace+Nz=Replace dependency version when installing from repositories.)r6   r1   r8   r3   z
--pipelinez/Name of the pipeline to execute for prediction.)r6   r3   z--inputzJInput data or path for the pipeline, supports specific file and directory.)r6   r8   r3   z--save_pathz$Path to save the prediction results.z--devicez5Device to run the pipeline on (e.g., 'cpu', 'gpu:0').z
--use_hpipz&Use high-performance inference plugin.z--hpi_configz)High-performance inference configuration.z--get_pipeline_configz4Retrieve the configuration for a specified pipeline.z--servez1Start the serving application to handle requests.z--hostz0.0.0.0z,Host address to serve on (default: 0.0.0.0).z--porti  z(Port number to serve on (default: 8080).z--paddle2onnxz*Convert PaddlePaddle model to ONNX format.z--paddle_model_dirz,Directory containing the PaddlePaddle model.z--onnx_model_dirz$Output directory for the ONNX model.--opset_version   z!Version of the ONNX opset to use.pipeline_namez, zUnsupported pipeline: z-, CLI predict only supports these pipelines: 
r   z Pipeline Optionsnamer6   r3   zArgument for z
 pipeline.)argparseArgumentParseradd_argument_groupadd_argumentstrastliteral_evalintparse_known_argspipelineinstallservepaddle2onnxospathisfiler   r   joinkeysr   errorsysexit
capitalizeboolget)r,   parserinstall_grouppipeline_groupserving_grouppaddle2onnx_groupargsremaining_argsrJ   pipeline_argsr>   support_pipelinespipeline_specific_groupargs                 r+   args_cfgrd   1   sH    $$ 	TF --.GHM../IJN--.?@M112GH 1	   M  
 {+F   E   4	   L   3%V    Y	    3	    D	    5   
 8   
 C	    @  
 ;	   7	   ""9 # 
 ""; # 
 ""3 # 
 ""Q5X # 
 "224D}}HM \\%t7G7G7G 77>>(##0:?KM$M 22 $		*<*A*A*C DMM(7devdwwyz HHQK*=9 M"(";";'')**;<#
 !C#00F"%f+"5Y3v;WWV}]O:%NO 1  !   r.   c           	      8   S nS nS nS nS[         R                  S'   S[         R                  S'   U R                  S	S	 nS
U;   aL  UR                  S
5        U(       a,  [        R
                  " S5        [        R                  " S5        U" 5         g	SU;   aL  UR                  S5        U(       a,  [        R
                  " S5        [        R                  " S5        U" 5         g	[        [        S U5      5      nU(       a  U H  nUR                  U5        M     U(       a,  [        R
                  " S5        [        R                  " S5        [        U5      S:  d!  [        US   R                  S5      5      S:w  a,  [        R
                  " S5        [        R                  " S5        US   R                  S5      S   nU" US9  g	[        [        S U5      5      n	U	(       as  U	 H  nUR                  U5        M     U(       a,  [        R
                  " S5        [        R                  " S5        U	 Vs/ s H  ow[        S5      S	 PM     n
nU" U
5        g	[        5       n/ nU H  nX{;  d  M
  UR                  U5        M     U(       a-  [        R
                  " SU5        [        R                  " S5        U(       a  UnO[        U5      S:X  a  Un[        WU R                  U R                   U R"                  U R$                  U R&                  S9  g	s  snf )zinstall paddlexc                       [        [        5       5        [        R                  " S5        g ! [         a.    [        R                  " SSS9  [
        R                  " S5         NNf = f)NInstallation failedTexc_infor   z)Successfully installed the serving plugin)r   r   	Exceptionr   rS   rT   rU   infor)   r.   r+   _install_serving_deps&install.<locals>._install_serving_deps   sM    	245 	@A  	MM/$?HHQK	   , 5A$#A$c                       [        [        5       5        [        R                  " S5        g ! [         a.    [        R                  " SSS9  [
        R                  " S5         NNf = f)Nrg   Trh   r   z-Successfully installed the Paddle2ONNX plugin)r   r   rj   r   rS   rT   rU   rk   r)   r.   r+   _install_paddle2onnx_deps*install.<locals>._install_paddle2onnx_deps   sM    	689 	DE  	MM/$?HHQK	rn   c                    / SQnX;  a.  [         R                  " SUU 5        [        R                  " S5        SnU S:X  aR  [	        5       nU(       d  [        R                  " S5        US   S:X  a  S	nOUS   S
:w  a  [        R                  " S5        SSSS.nX@   n[        UR                  5       5      U1-
  nU HC  n[        U5      nUc  M  [         R                  " SU SU SU SU S3	5         [        U/5        ME     [        R                  R                  SU5       n	[        U5      n Uc  [        U/S[        U	5      /S9  OY[!        S[#        U5       S35      n
U
R%                  5       S;   a#  [        U/5        [        U/S[        U	5      /S9  O
 S S S 5        g S S S 5        [         R                  " S5        ['        5       (       d  [         R                  " S 5        g g ! [         a0    [         R                  " SSS9  [        R                  " S5         GMe  f = f! [         a.    [         R                  " SSS9  [        R                  " S5         Nf = f! , (       d  f       N= f)!N)cpugpunpuzgFailed to install the high-performance plugin.
Supported device types: %s. Your input device type: %s.
   zhpip_links.htmlrt   zZNo CUDA version found. Please make sure you have installed PaddlePaddle with CUDA enabled.r      zhpip_links_cu12.html   zcCurrently, only CUDA versions 11.x and 12.x are supported by the high-performance inference plugin.zultra-infer-pythonzultra-infer-gpu-pythonzultra-infer-npu-pythonz'The high-performance inference plugin 'z' is mutually exclusive with 'z' (version z installed). Uninstalling 'z'...zFailed to uninstall packagesTrh   r   paddlexz--find-linkspip_install_optszDThe high-performance inference plugin is already installed (version z&). Do you want to reinstall it? (y/n):)yyesrg   z<Successfully installed the high-performance inference pluginzThe Paddle2ONNX plugin is not available. It is recommended to run `paddlex --install paddle2onnx` to install the Paddle2ONNX plugin to use the full functionality of high-performance inference.)r   rS   rT   rU   r   setvaluesr   rk   r   rj   	importlib	resourcesrO   r   rE   inputreprlowerr   )device_typeSUPPORTED_DEVICE_TYPEShpip_links_filecuda_versionpackage_mappingpackageother_packagesother_packageversionr(   responses              r+   _install_hpi_deps"install.<locals>._install_hpi_deps   s}   !64MML&	 HHQK+%24Lp A"$"8aB&y
 (++

 "._3356'B+M%m4G"=gYFderdss~  @G  H  Hc  dq  cr  rv  w &7 ,   %%iAQ%g.G?$ 	^SV4L  %^_cdk_l^m  nT  U H  ~~'<7*G95($I . #A. + BAA4 	ST.00LL S 1A !  MM"@4PHHQKK 4  3dC- BAsO   2G'"I/H$I	AH$I'5H! H!$5IIII
I-c                    / n/ nU  H-  nSU;   a  UR                  U5        M  UR                  U5        M/     U(       a|  [        S5      (       d  [        R                  " S5        [	        5       nUS;   a  SnO,US;   a  SnO#[        R                  " SUS	    S
US    S35         [        [        S5      /SW/S9  / nU H  n [        U5      nUW-  nM      [        USS9  U  Hf  nSU;   d  SU;   d  M  [        S/SS9  [        5       (       d  M-   [        S/SS9  [	        5       nUc   eUS:  a  [        S/SS9  O[        S/SS9     O   [        R                  " S[        U 5      S:  a  SOS -   5        g ! [         a.    [        R                  " SSS9  [        R                  " S5         Nf = f! [         a1    [        R                  " SU5        [        R                  " S5         GN f = f! [         a/    [        R                  " SSS9  [        R                  " S5         GNHf = f! [         a/    [        R                  " SSS9  [        R                  " S5         GNf = f)!N
fastdeploypaddlepaddlez"Please install PaddlePaddle first.))   r   )	   r   zEhttps://www.paddlepaddle.org.cn/packages/stable/fastdeploy-gpu-80_90/))r      )r   r   zEhttps://www.paddlepaddle.org.cn/packages/stable/fastdeploy-gpu-86_89/z%The compute capability of the GPU is r   .r   zX, which is not supported. The supported compute capabilities are 8.0, 8.6, 8.9, and 9.0.rt   z--extra-index-urlrz   rg   Trh   z%Invalid generative AI plugin type: %srv   required)constraintsvllmsglangxformerswheel)rw   r   zflash-attn == 2.8.3zflash-attn == 2.8.2z/Successfully installed the generative AI pluginr*    )appendr   rT   rU   r   r   r   rj   r   rS   r   
ValueErrorr   rk   len)plugin_typesfd_plugin_typesnot_fd_plugin_typesplugin_typecap	index_urlreqsrs           r+   _install_genai_deps$install.<locals>._install_genai_depsF  sV    'K{*&&{3#**;7	 (
 #N33=>,.C&&c	((c	;CF81SVH  Me  f .u56&99%E .K'4 AID /	Tz:
 (K$K(? *:F$&&$('
K8:".'>,!6 7Z -!6 7Z ' (* 	=,'!+s5	
O  3dC  E{S  	MM/$?HHQK	( % $&;dK$sN   %E9 F4
G2 +H.>H.95F10F147G/.G/25H+*H+.5I'&I'r    PADDLE_PDX_DEBUGr%   PADDLE_PDX_EAGER_INITNservingz5`serving` cannot be used together with other plugins.rv   rM   z9`paddle2onnx` cannot be used together with other plugins.c                 $    U R                  S5      $ )Nzhpi-
startswithr@   s    r+   <lambda>install.<locals>.<lambda>  s    4??6+Br.   z5`hpi-xxx` cannot be used together with other plugins.r   r   -zInvalid HPI plugin installation format detected.
Correct format: paddlex --install hpi-<device_type>
Example: paddlex --install hpi-gpu)r   c                 $    U R                  S5      $ )Ngenai-r   r   s    r+   r   r     s    T__X-Fr.   z7`genai-xxx` cannot be used together with other plugins.r   zUnknown plugins: %s)
repo_namesno_depsplatformr9   use_local_reposdeps_to_replace)rN   environrK   remover   rS   rT   rU   listfilterr   splitr	   r   r
   r   r   r9   r   r   )r^   rl   rp   r   r   pluginshpi_pluginspr   genai_pluginsgenai_plugin_typesall_repo_namesunknown_pluginsr   s                 r+   rK   rK      s{   BFKZD
N &,BJJ!"*1BJJ&'ll1oGGy!MMQRHHQK}%MMUVHHQK!#vBGLMKANN1 MMQRHHQK{a3{1~';';C'@#AQ#FMM5
 HHQK!!n**3/2k2 FPQMANN1 MMSTHHQK:GH-QH0-H./13NO"""1%  +_=
	W	#
	&&,,,, 1 Is   8Lc                     [        XXES9n U R                  " U40 UD6nU H+  nUR                  5         U(       d  M  UR                  US9  M-     g)zpipeline predict)deviceuse_hpip
hpi_config)	save_pathN)r   predictprintsave_all)	rJ   r   r   r   r   r   r`   resultress	            r+   pipeline_predictr     sP     (H e5}5F		9LL9L- r.   c                P    SSK JnJn  [        U 5      n [        UUUUS9n W" X5      n	W" XUS9  g ! [         a.    [        R
                  " SSS9  [        R                  " S5         N_f = f! [         a.    [        R
                  " SSS9  [        R                  " S5         Nf = f)	Nr   )create_pipeline_app
run_serverz!Failed to load the serving moduleTrh   )configr   r   r   zFailed to create the pipeline)hostport)inference.serving.basic_servingr   r   RuntimeErrorr   rS   rT   rU   r   r   rj   )
rJ   r   r   r   r   r   r   r   pipeline_configapps
             r+   rL   rL     s    T
 +84O	""!	
 h
8CsD)!  9DI  5Es    2 A- 5A*)A*-5B%$B%c                b  ^^	^
 [        5       (       d  [        R                  " S5        [         S3m
[         S3m	S/mU	4S jnS nU
4S jnU	4S jnU4S	 jnU (       d  [        R                  " S
5        [	        U 5      n U(       d  U n[	        U5      n[
        R                  " SU  35        [
        R                  " SU 35        U" U 5        U" 5         U" XU5        UR                  5       (       a  UR                  U 5      (       d  U" X5        U" X5        [
        R                  " S5        g )Nz,Please install the Paddle2ONNX plugin first.z.onnxz.ymlz
scaler.pklc                   > U c  [         R                  " S5        U R                  5       (       d  [         R                  " U  S35        U R                  5       (       d  [         R                  " U  S35        [	        U 5      nSU;  a  [         R                  " S5        U T-  nUR                  5       (       d  [         R                  " U S35        g g )Nz!Input directory must be specifiedz does not existz is not a directorypaddlez!PaddlePaddle model does not exist)rT   rU   existsis_dirr   )	input_dirmodel_pathsconfig_pathCONFIG_FILENAMEs      r+   _check_input_dir(paddle_to_onnx.<locals>._check_input_dir
  s    HH89!!HH	{/23!!HH	{"567%i0;&HH89/1!!##HH}O45 $r.   c                  `    [         R                  " S5      c  [        R                  " S5        g g )NrM   z>Paddle2ONNX is not available. Please install the plugin first.)shutilwhichrT   rU   r)   r.   r+   _check_paddle2onnx*paddle_to_onnx.<locals>._check_paddle2onnx  s#    <<&.HHUV /r.   c                   > [        U 5      n[        R                  " S5        SS[        US   S   R                  5      S[        US   S   R
                  5      S[        US   S   R
                  5      S	[        UT-  5      S
[        U5      /n [        R                  " U5        [        R                  " S5        g ! [        R                   a-  n[        R                  " SUR                   35         S nANSS nAff = f)Nz"Paddle2ONNX conversion starting...rM   z--model_dirr   r   z--model_filenamez--params_filenamer   z--save_filer<   z-Paddle2ONNX conversion failed with exit code z Paddle2ONNX conversion succeeded)r   r   rk   rE   parentr@   
subprocess
check_callCalledProcessErrorrT   rU   
returncode)r   
output_diropset_versionr   cmdeONNX_MODEL_FILENAMEs         r+   _run_paddle2onnx(paddle_to_onnx.<locals>._run_paddle2onnx  s    %i09: H%a(//0H%a(--.H%a(--.
001
	U!!#& 	78 ,, 	UHHDQ\\NSTT	Us   B> >C?#C::C?c                 ~   > U T-  nUT-  n[         R                  " X#5        [        R                  " SU SU 35        g NzCopied z to )r   copyr   rk   )r   r   src_pathdst_pathr   s       r+   _copy_config_file)paddle_to_onnx.<locals>._copy_config_file3  s<    ./H'wxjXJ78r.   c                    > T HT  nX-  nUR                  5       (       d  M  X-  n[        R                  " X45        [        R                  " SU SU 35        MV     g r   )r   r   r   r   rk   )r   r   filenamer   r   ADDITIONAL_FILENAMESs        r+   _copy_additional_files.paddle_to_onnx.<locals>._copy_additional_files9  sR    ,H +H??$$!,HKK+LL78*D
;< -r.   z.PaddlePaddle model directory must be specifiedzInput dir: zOutput dir: Done)	r   rT   rU   r   r   r   rk   r   samefile)paddle_model_dironnx_model_dirr   r   r   r   r   r  r  r   r   s           @@@r+   paddle_to_onnxr    s   *,,?@./u5*+40O(>6W9.9= AB,-).)NLL;/012LL</01%&%}E!!##(?(?@P(Q(Q*;/@LLr.   c            	         [        5       u  pU R                  5       n[        [        R                  5      S:X  a<  [
        R                  " S5        U R                  5         [        R                  " S5        UR                  b  [        U5        gUR                  (       aT  [        UR                  UR                  UR                  =(       d    SUR                  UR                  UR                   S9  gUR"                  (       a*  [%        UR&                  UR(                  UR*                  S9  gUR,                  b!  [/        UR,                  UR0                  5        g0 nU HP  nUS   R3                  S5      n[5        X%5      (       a  [7        X%5      X5'   M6  [
        R                  " S	U S
35        MR      [9        UR                  UR:                  UR                  UR0                  4UR                  =(       d    SUR                  S.UD6  g! [<         a.    [
        R>                  " SSS9  [        R                  " S5         gf = f)zAPI for command liner   z3No arguments provided. Displaying help information:rv   N)r   r   r   r   r   )r   r@   r   z	Argument z is missing in args)r   r   zPipeline prediction failedTrh   ) rd   
parse_argsr   rT   argvr   warning
print_helprU   rK   rL   rJ   r   r   r   r   r   rM   r  r	  r
  r   get_pipeline_configr   r   lstriphasattrgetattrr   r   rj   rS   )rY   r`   r^   pipeline_args_dictrc   arg_names         r+   mainr  U  s   $JFD
388}MN||	MM;;]]*d	
 
		!!,,	
 ##/$T%=%=t~~N!#$v;--c24**3:43J&0OOiz9L$MN % MMJJKKNN	
 "]]2d# )  :TJs   6AH 5II)0rA   rF   importlib.resourcesr   rN   r   r   rT   pathlibr   r   r   	constantsr   inference.pipelinesr   inference.utils.model_pathsr   repo_managerr	   r
   utilsr   
utils.depsr   r   r   r   r   r   r   	utils.envr   r   r   utils.installr   r   utils.interactive_get_pipeliner   utils.pipeline_argumentsr   rd   rK   r   rL   r  r  r)   r.   r+   <module>r$     sz     
  	   
   ( 5 8 =    
 @ D 8r!jnb.(*.Of3r.   