
    9i;                         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	  \	" \ R                  S9r\R                  R                  \R                  R                  \5      5      r\R                  R#                  \S5      rS r " S	 S
\5      rg)    N)ArgumentParser)Template)
CLICommand)
get_logger)	log_leveltemplatec                     [        U 5      $ )z=Function which will be called for a specific sub parser.
    )PipelineCMDargss    W/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/cli/pipeline.pysubparser_funcr      s     t    c                   B    \ rS rSrSrS r\S\4S j5       rS r	S r
Srg	)
r
      pipelinec                     Xl         g )Nr   )selfr   s     r   __init__PipelineCMD.__init__   s    	r   parsersc           	      
   U R                  [        R                  5      n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SS9  UR                  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"S#S9  UR                  S$S%[        SS&S9  UR                  [        S'9  g())z:define args for create pipeline template command.
        z-actz--actionTcreatez'the action of command  pipeline[create])typerequiredchoiceshelpz-tplz--tpl_file_pathztemplate.tplz5the template be selected for ModelScope[template.tpl])r   defaultr   z-sz--save_file_path./z3the name of custom template be saved for ModelScopez-fz
--filenamezms_wrapper.pyz8the init name of custom template be saved for ModelScopez-tz--task_namez#the unique task_name for ModelScope)r   r   r   z-mz--model_nameMyCustomModelz&the class of model name for ModelScopez-pz--preprocessor_nameMyCustomPreprocessorz-the class of preprocessor name for ModelScopez-ppz--pipeline_nameMyCustomPipelinez)the class of pipeline name for ModelScopez-configz--configuration_pathz-the path of configuration.json for ModelScope)funcN)
add_parserr
   nameadd_argumentstrset_defaultsr   )r   parsers     r   define_argsPipelineCMD.define_args   sy    ##K$4$45J: 	 	< 	"H 	 	J 	F 	 	H 	#K 	 	M 	6 	 	8 	#9 	 	; 	!*@ 	 	B 	&< 	 	> 	"@ 	 	B 	0r   c           
         U R                   R                  [        R                  " [        5      ;  a  U R                   R                  nO8[        R
                  R                  [        U R                   R                  5      n[        R
                  R                  U5      (       d  [        SU-  5      eU R                   R                  S:w  a  U R                   R                  O[        R                  " 5       n[        R                  " USS9  U R                   R                  R                  S5      (       d  [        S5      eU R                   R                  n[        R
                  R                  X#5      nU R                   R                  R                  S5      (       d(  U R                   R                  S-   U R                   l        / n[        U5       n[!        UR#                  5       5      nUR%                  UR&                  " S0 [)        U R                   5      D65        S S S 5        [        US5       nUR+                  U5        S S S 5        [,        R/                  S	U R                   R                  < SS
< 35        [,        R/                  SU R                   R0                  < SU< 35        [,        R/                  SU-  5        g ! , (       d  f       N= f! , (       d  f       N= f)Nz%s not exists!r   T)exist_okz.pyzthe FILENAME must end with .py /wz>>> Configuration be saved in zconfiguration.jsonz>>> Task_name: z, Created in z(Open the file < %s >, update and run it. )r   tpl_file_pathoslistdirtemplate_pathpathjoinexists
ValueErrorsave_file_pathgetcwdmakedirsfilenameendswithconfiguration_pathopenr   readappend
substitutevars
writelinesloggerinfo	task_name)	r   r1   r9   save_file_namesave_pkl_pathlinestpl_filetpl	save_files	            r   create_templatePipelineCMD.create_templateZ   s   99"""**]*CC II33MGGLL)-)@)@BMww~~m,,-=>>59YY5M5MQU5U11[][d[d \

NT2yy!!**511>??++^Dyy++44S99+/99+G+G#+MDII(- H8==?+CLL:$tyy/:; ! -%  ' & 	YY113GI 	JYY((-9 	:>NO !  &%s   AK9K
K
K-c                 n    U R                   R                  S:X  a  U R                  5         g [        S5      e)Nr   z+The parameter of action must be in [create])r   actionrN   r8   )r   s    r   executePipelineCMD.execute|   s,    99x'  "JKKr   r   N)__name__
__module____qualname____firstlineno__r%   r   staticmethodr   r*   rN   rR   __static_attributes__r0   r   r   r
   r
      s5    D ;1^ ;1 ;1z PDLr   r
   )loggingr2   argparser   stringr   modelscope.cli.baser   modelscope.utils.loggerr   WARNINGrE   r5   dirnameabspath__file__current_pathr6   r4   r   r
   r0   r   r   <module>rd      sm     	 #  * .	goo	.wwrwwx89\:6jL* jLr   