
    6pj4                     R   S 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  SS	KJr  \" \R&                  S
9r\R*                  R-                  \R*                  R/                  \5      5      r\R*                  R5                  \S5      r " S S\
5      rg)uE   ``modelscope modelcard`` — create / upload / download a model card.    N)ArgumentParser)Template)
CLICommand)HubApi)snapshot_download)get_endpoint)
get_logger)	log_leveltemplatec                   j   ^  \ rS rSrSrU 4S jr\S\SS4S j5       rS r	S	 r
SS
 jrS rS rSrU =r$ )ModelCardCMD   	modelcardc                   > [         TU ]  U5        [        5       U l        UR                  (       a%  U R                  R                  UR                  5        SU R                  R                  ;  aH  [        R                  R                  U R                  R                  U R                  R                  5      OU R                  R                  U l        [        R                  R                  [        5       U R                  5      U l        g )N/)super__init__r   apiaccess_tokenloginargsmodel_idospathjoingroup_idr   url)selfr   	__class__s     T/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope/cli/modelcard.pyr   ModelCardCMD.__init__   s    8HHNN4,,- 		*** II		 2 2
04		0B0B 	 77<<>    
subparsersreturnNc           	      <   U R                  [        R                  S/SS9nUR                  SS[        SSS9  UR                  S	S
[        S/ SQ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 ).Nmodelz(Create / upload / download a model card.)aliaseshelpz-tkz--access_tokenFz%the certification of visit ModelScope)typerequiredr(   z-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_tagzthe tag of uploaded modelz-viz--version_infozthe info of uploaded model)_command)
add_parserr   nameadd_argumentstrintset_defaults)r#   parsers     r    registerModelCardCMD.register%   s   &&I; ' = 	8 	 	: 	4? 	 	A 	9 	 	; 	/ 	 	1 	L 	 	N 	(E 	 	F 	11 	 	3 	6 	 	8 	, 	 	. 	- 	 	/ 	\2r"   c                 X   SSK JnJn  [        U5       Vs/ s H&  nUR	                  S5      (       a  M  [        X#5      PM(     nnU R                  R                  U;  a  [        SU-  5      e[        U5       Vs/ s H&  nUR	                  S5      (       a  M  [        X5      PM(     nnU R                  R                  U;  a  [        SU-  5      e U R                  R                  U R                  5        U R'                  5         g s  snf s  snf ! [         a  n[        R                  S[!        U5      -  5        U R                  R#                  U R                  U R                  R                  U R                  R                  U R                  R$                  S9   S nANS nAff = f)Nr   )LicensesModelVisibility__zThe access_token must in %s!zThe license must in %s!z>>> %s)r   
visibilitylicensechinese_name)modelscope.hub.constantsr>   r?   dir
startswithgetattrr   rA   
ValueErrorrB   r   	get_modelr   	Exceptionloggerinfor)   create_modelrC   pprint)r   r>   r?   attrvisibilitieslicenseses          r    rM   ModelCardCMD.create_modell   sY   F7:?7K
7Kt??4( +GO*7K 	 
 99|3;lJKK03H
0=??4( $GH# 	 
 99H,6ABB		HHt}}- 	-

  	KK47*+HH!!99//		))!YY33	 " 	s/   DD:DD%D 
F)BF$$F)c                 L    U R                   R                  U R                  5      $ )N)r   get_model_urlr   r   s    r    rU   ModelCardCMD.get_model_url   s    xx%%dmm44r"   c                    SSK Jn  U R                  R                  (       a  U R                  R                  (       a  [
        R                  " 5       R                  nU" X0R                  S9nUR                  U R                  R                  U R                  R                  5        [        R                  " U5        GOb[        R                  R                  U R                  R                  S5      n[        R                  R!                  U5      (       d  [#        [        R                  R                  [$        U5      5       n['        UR)                  5       5      n[#        US5      nUR+                  UR-                  U R                  S95        UR/                  5         S S S 5        U R0                  R3                  U R                  U R                  R                  U R                  R4                  U R                  R6                  U R                  R8                  S9  U R;                  5         g ! , (       d  f       N= f)Nr   )
Repository)
clone_fromz	README.mdw)r   )r   	model_dirrA   rB   rC   )modelscope.hub.repositoryrY   r   version_tagversion_infotempfileTemporaryDirectoryr5   r   tag_and_pushshutilrmtreer   r   r   r\   existsopentemplate_pathr   readwrite
substitutecloser   
push_modelrA   rB   rC   rN   )	r   tpl_dirrY   	clone_dirrepocfg_filetpl_file_pathtplfs	            r    rl   ModelCardCMD.push_model   sr   899  TYY%;%; 335::IiMMBDdii33TYY5K5KLMM)$ww||DII$7$7EH77>>(++"'',,}'.0 14A"=#5#5#78CXs+AGGCNNDMMNBCGGI1 HH))--99//		))!YY33   5 	1 1s   AH11
H?c                     [         R                  SU R                  5       -  5        [         R                  SU R                  -  5        [         R                  SU R                  -  5        g )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.)rK   rL   rU   r   r   rV   s    r    rN   ModelCardCMD.pprint   sS    I((*+ 	,ADHHLMImm$ 	%r"   c                 t   U R                   R                  S:X  a  U R                  5         g U R                   R                  S:X  a  U R                  5         g U R                   R                  S:X  a>  [	        U R
                  U R                   R                  U R                   R                  S9  g [        S5      e)Nr+   r,   r-   )	cache_dirrevisionz3The parameter of action must be in [create, upload])	r   actionrM   rl   r   r   r\   r^   rH   rV   s    r    executeModelCardCMD.execute   s    99x'YY)OOYY+))--..0
 EG Gr"   )r   r   r   )z
readme.tpl)__name__
__module____qualname____firstlineno__r5   r   staticmethodr   r;   rM   rU   rl   rN   r{   __static_attributes____classcell__)r   s   @r    r   r      sT    D? D3^ D3 D3 D3L450%G Gr"   r   )__doc__loggingr   rc   r`   argparser   stringr   modelscope_hub.cli.baser   modelscope.hub.apir    modelscope.hub.snapshot_downloadr   modelscope.hub.utils.utilsr   modelscope.utils.loggerr	   WARNINGrK   r   dirnameabspath__file__current_pathr   rg   r    r"   r    <module>r      sz    K  	   #  . % > 3 .	goo	.wwrwwx89\:6\G: \Gr"   