
    9iH                     T   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(                  R3                  \S
5      rS r " S S\	5      rg)    N)ArgumentParser)Template)
CLICommand)HubApi)snapshot_download)get_endpoint)
get_logger)	log_leveltemplatec                     [        U 5      $ )z=Function which will be called for a specific sub parser.
    )ModelCardCMD)argss    X/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/cli/modelcard.pysubparser_funcr      s         c                   X    \ rS rSrSrS r\S\4S j5       rS r	S r
SS jrS	 rS
 rSrg)r      	modelcardc                    Xl         [        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/)r   r   apiaccess_tokenloginmodel_idospathjoingroup_idr   url)selfr   s     r   __init__ModelCardCMD.__init__   s    	8HHNN4,,- 		*** II		 2 2
04		0B0B 	 77<<>r   parsersc           	      :   U R                  [        R                  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().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_argsModelCardCMD.define_args(   s    ##L$5$5y#I8 	 	: 	4? 	 	A 	9 	 	; 	/ 	 	1 	L 	 	N 	(E 	 	F 	11 	 	3 	6 	 	8 	, 	 	. 	- 	 	/ 	0r   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   r@   
ValueErrorrA   r   	get_modelr   	Exceptionloggerinfor'   create_modelrB   pprint)r    r=   r>   attrvisibilitieslicenseses          r   rL   ModelCardCMD.create_modeln   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   rT   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_dirr@   rA   rB   )modelscope.hub.repositoryrX   r   version_tagversion_infotempfileTemporaryDirectoryr4   r   tag_and_pushshutilrmtreer   r   r   r[   existsopentemplate_pathr   readwrite
substitutecloser   
push_modelr@   rA   rB   rM   )	r    tpl_dirrX   	clone_dirrepocfg_filetpl_file_pathtplfs	            r   rk   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.)rJ   rK   rT   r   r   rU   s    r   rM   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   actionrL   rk   r   r   r[   r]   rG   rU   s    r   executeModelCardCMD.execute   s    99x'YY)OOYY+))--..0
 EG Gr   )r   r   r   r   N)z
readme.tpl)__name__
__module____qualname____firstlineno__r4   r!   staticmethodr   r:   rL   rT   rk   rM   rz   __static_attributes__ r   r   r   r      sE    D? C1^ C1 C1J450%Gr   r   )loggingr   rb   r_   argparser   stringr   modelscope.cli.baser   modelscope.hub.apir    modelscope.hub.snapshot_downloadr   modelscope.hub.utils.utilsr   modelscope.utils.loggerr	   WARNINGrJ   r   dirnameabspath__file__current_pathr   rf   r   r   r   r   r   <module>r      s|     	   #  * % > 3 .	goo	.wwrwwx89\:6[G: [Gr   