
    ujH                     X   d dl Z d dlZ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 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)HubApi)snapshot_download)get_endpoint)
get_logger)	log_leveltemplatec                      t          |           S )z> Function which will be called for a specific sub parser.
    )ModelCardCMD)argss    h/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/cli/modelcard.pysubparser_funcr      s         c                   T    e Zd ZdZd Zedefd            Zd Zd Z	ddZ
d	 Zd
 ZdS )r   	modelcardc                    || _         t                      | _        |j        r| j                            |j                   d| j         j        vr4t          j                            | j         j	        | j         j                  n| j         j        | _        t          j                            t                      | j                  | _        d S )N/)r   r   apiaccess_tokenloginmodel_idospathjoingroup_idr   url)selfr   s     r   __init__zModelCardCMD.__init__   s    	88 	.HNN4,--- 	*** I	 2
 
 
04	0B 	 7<<>>r   parsersc                    |                      t          j        dg          }|                    ddt          dd           |                    dd	t          d
g 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)           |                    d*d+t          d(d,           |                    t          -           d(S ).z= define args for create or upload modelcard command.
        model)aliasesz-tkz--access_tokenFz%the certification of visit ModelScope)typerequiredhelpz-actz--actionT)createuploaddownloadz,the action of api ModelScope[create, upload])r%   r&   choicesr'   z-gidz
--group_iddamoz&the group name of ModelScope, eg, damo)r%   defaultr'   z-midz
--model_idzthe model name of ModelScopez-visz--visibility   z>the visibility of ModelScope[PRIVATE: 1, INTERNAL:3, PUBLIC:5]z-licz	--licensezApache License 2.0zithe license of visit ModelScope[Apache License 2.0|GPL-2.0|GPL-3.0|LGPL-2.1|LGPL-3.0|AFL-3.0|ECL-2.0|MIT]z-chz--chinese_nameu   这是我的第一个模型zthe chinese name of ModelScopez-mdz--model_dir.z#the model_dir of configuration.jsonz-vtz--version_tagNzthe tag of uploaded modelz-viz--version_infozthe info of uploaded model)func)
add_parserr   nameadd_argumentstrintset_defaultsr   )r!   parsers     r   define_argszModelCardCMD.define_args(   s    ##L$5y#II8 	 	: 	: 	: 	444? 	 	A 	A 	A 	9 	 	; 	; 	; 	/ 	 	1 	1 	1 	L 	 	N 	N 	N 	(E 	 	F 	F 	F 	11 	 	3 	3 	3 	6 	 	8 	8 	8 	, 	 	. 	. 	. 	- 	 	/ 	/ 	/ 	00000r   c                 t   ddl mm fdt                    D             }| j        j        |vrt          d|z            fdt                    D             }| j        j        |vrt          d|z            	 | j        	                    | j
                   n# t          $ ru}t                              dt          |          z             | j                            | j
        | j        j        | j        j        | j        j                   Y d }~nd }~ww xY w|                                  d S )	Nr   )LicensesModelVisibilityc                 Z    g | ]'}|                     d           t          |          (S __
startswithgetattr).0attrr;   s     r   
<listcomp>z-ModelCardCMD.create_model.<locals>.<listcomp>p   sE     
 
 
/3??4((
OT**
 
 
r   zThe access_token must in %s!c                 Z    g | ]'}|                     d           t          |          (S r=   r?   )rB   rC   r:   s     r   rD   z-ModelCardCMD.create_model.<locals>.<listcomp>v   sE     
 
 
(,??4((
Hd##
 
 
r   zThe license must in %s!z>>> %s)r   
visibilitylicensechinese_name)modelscope.hub.constantsr:   r;   dirr   rF   
ValueErrorrG   r   	get_modelr   	Exceptionloggerinfor%   create_modelrH   pprint)r   visibilitieslicenseser:   r;   s       @@r   rP   zModelCardCMD.create_modeln   s   FFFFFFFF
 
 
 
7:?7K7K
 
 
 9|33;lJKKK
 
 
 
03H
 
 
 9H,,6ABBB		Ht}---- 	 	 	KK477*+++H!!9/	)!Y3	 "        	 	s   B" "
D!,A+DD!c                 @    | j                             | j                  S )N)r   get_model_urlr   r   s    r   rV   zModelCardCMD.get_model_url   s    x%%dm444r   
readme.tplc                    ddl m} | j        j        rv| j        j        rjt          j                    j        } ||| j                  }|	                    | j        j        | j        j                   t          j        |           nRt          j                            | j        j        d          }t          j                            |          st#          t          j                            t$          |                    5 }t'          |                                          }t#          |d          }|                    |                    | j                             |                                 d d d            n# 1 swxY w Y   | j                            | j        | j        j        | j        j        | j        j        | j        j                   |                                  d S )Nr   )
Repository)
clone_fromz	README.mdw)r   )r   	model_dirrF   rG   rH   )modelscope.hub.repositoryrZ   r   version_tagversion_infotempfileTemporaryDirectoryr2   r   tag_and_pushshutilrmtreer   r   r   r]   existsopentemplate_pathr   readwrite
substitutecloser   
push_modelrF   rG   rH   rQ   )	r   tpl_dirrZ   	clone_dirrepocfg_filetpl_file_pathtplfs	            r   rm   zModelCardCMD.push_model   s   8888889  	5TY%; 	5 355:I:iDMBBBDdi3TY5KLLLM)$$$$w||DI$7EEH7>>(++ "',,}'.0 0 1 1 4A"=#5#5#7#788CXs++AGGCNNDMNBBCCCGGIII               H)-9/	)!Y3   5 5 5 	s   A4FFFc                     t                               d|                                 z             t                               d| j        z             t                               d| j        z             d S )Nz3>>> Clone the model_git < %s >, commit and push it.z+>>> Open the url < %s >, check and read it.z3>>> Visit the model_id < %s >, download and run it.)rN   rO   rV   r   r   rW   s    r   rQ   zModelCardCMD.pprint   sv    I((**+ 	, 	, 	,ADHLMMMIm$ 	% 	% 	% 	% 	%r   c                 2   | j         j        dk    r|                                  d S | j         j        dk    r|                                  d S | j         j        dk    r-t	          | j        | j         j        | j         j                   d S t          d          )Nr(   r)   r*   )	cache_dirrevisionz3The parameter of action must be in [create, upload])	r   actionrP   rm   r   r   r]   r_   rK   rW   s    r   executezModelCardCMD.execute   s    9x''Y))OOY++)-.0 0 0 0 0 0
 EG G Gr   N)rX   )__name__
__module____qualname__r2   r    staticmethodr   r8   rP   rV   rm   rQ   rz    r   r   r   r      s        D? ? ? C1^ C1 C1 C1 \C1J  45 5 5   0% % %G G G G Gr   r   )loggingr   rd   ra   argparser   stringr   modelscope.cli.baser   modelscope.hub.apir    modelscope.hub.snapshot_downloadr   modelscope.hub.utils.utilsr   modelscope.utils.loggerr	   WARNINGrN   r   dirnameabspath__file__current_pathr   rh   r   r   r   r   r   <module>r      sH    				   # # # # # #       * * * * * * % % % % % % > > > > > > 3 3 3 3 3 3 . . . . . .	go	.	.	.wrwx8899\:66  [G [G [G [G [G: [G [G [G [G [Gr   