
    uj;                     $   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	  e	e j
                  Zej                            ej                            e                    Zej                            ed          Zd Z G d	 d
e          ZdS )    N)ArgumentParser)Template)
CLICommand)
get_logger)	log_leveltemplatec                      t          |           S )z> Function which will be called for a specific sub parser.
    )PipelineCMDargss    g/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/cli/pipeline.pysubparser_funcr      s     t    c                   @    e Zd ZdZd Zedefd            Zd Zd Z	dS )r
   pipelinec                     || _         d S )Nr   )selfr   s     r   __init__zPipelineCMD.__init__   s    			r   parsersc                    |                      t          j                  }|                    ddt          ddgd           |                    ddt          d	d
           |                    ddt          dd           |                    ddt          dd           |                    ddt          dd           |                    ddt          dd           |                    ddt          dd           |                    d d!t          d"d#           |                    d$d%t          dd&           |                    t          '           d(S ))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_argszPipelineCMD.define_args   s    ##K$455J: 	 	< 	< 	< 	"H 	 	J 	J 	J 	F 	 	H 	H 	H 	#K 	 	M 	M 	M 	6 	 	8 	8 	8 	#9 	 	; 	; 	; 	!*@ 	 	B 	B 	B 	&< 	 	> 	> 	> 	"@ 	 	B 	B 	B 	00000r   c           
      ,   | j         j        t          j        t                    vr| j         j        }n/t          j                            t          | j         j                  }t          j                            |          st          d|z            | j         j	        dk    r| j         j	        nt          j
                    }t          j        |d           | j         j                            d          st          d          | j         j        }t          j                            ||          }| j         j                            d          s| j         j        dz   | j         _        g }t          |          5 }t!          |                                          }|                     |j        di t)          | j                              d d d            n# 1 swxY w Y   t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t,                              d	| j         j        dd
           t,                              d| j         j        d|           t,                              d|z             d S )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   r.   r6   save_file_namesave_pkl_pathlinestpl_filetpl	save_files	            r   create_templatezPipelineCMD.create_templateZ   s   9""*]*C*CCC I3MMGLL)-)@B BMw~~m,, 	?-=>>>59Y5MQU5U5U11[][d \
 \

NT2222y!**511 	@>???+^^DDy+44S99 	N+/9+G#+MDI(-   	<H8==??++CLL::$ty//::;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< -%% 	(  '''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	Y1113G3GI 	J 	J 	JY(((--9 	: 	: 	:>NOOOOOs%   ;AGG"G6HHHc                 l    | j         j        dk    r|                                  d S t          d          )Nr   z+The parameter of action must be in [create])r   actionrK   r5   )r   s    r   executezPipelineCMD.execute|   s9    9x''  """""JKKKr   N)
__name__
__module____qualname__r#   r   staticmethodr   r(   rK   rN   r-   r   r   r
   r
      sw        D   ;1^ ;1 ;1 ;1 \;1z P  P  PDL L L L Lr   r
   )loggingr/   argparser   stringr   modelscope.cli.baser   modelscope.utils.loggerr   WARNINGrB   r2   dirnameabspath__file__current_pathr3   r1   r   r
   r-   r   r   <module>r]      s     				 # # # # # #       * * * * * * . . . . . .	go	.	.	.wrwx8899\:66  jL jL jL jL jL* jL jL jL jL jLr   