
    9i                         S SK JrJr  S SKJr  S SKJr  S SKJrJ	r	J
r
Jr  S SKJr  S SKJrJr  S SKJr  \" 5       rS r " S	 S
\5      rg)    )ArgumentParser_SubParsersAction)
CLICommand)HubApi)LicensesModelVisibility
VisibilityVisibilityMap)	AigcModel)REPO_TYPE_MODELREPO_TYPE_SUPPORT)
get_loggerc                     [        U 5      $ )z=Function which will be called for a specific sub parser.
    )	CreateCMDargss    U/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/cli/create.pysubparser_funcr      s     T?    c                   T    \ rS rSrSrSrS\4S jr\S\4S j5       r	S r
S	 rS
 rSrg)r      zK
Command for creating a new repository, supporting both model and dataset.
creater   c                     Xl         g )Nr   )selfr   s     r   __init__CreateCMD.__init__   s    	r   parsersc                 J   U R                  [        R                  5      nUR                  S[        SS9  UR                  S[        S SS9  UR                  S[
        [        SS	9  UR                  S
[        R                  [        R                  [        R                  /[        R                  SS	9  UR                  S[        S SS9  UR                  S[        [        R                  " 5       [        R                  SS9  UR                  S[        S SS9  UR                  SS5      nUR                  SSSS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        S S9  UR                  S![        S"S#S9  UR                  S$[        S%S&S9  UR                  S'[        S(S)S9  UR                  S*[        S%S+S9  UR                  S,[        S-S.S9  UR                  S/[        S%S0S9  UR                  [         S19  g )2Nrepo_idz8The ID of the repo to create (e.g. `username/repo-name`))typehelpz--tokenzA User Access Token generated from https://modelscope.cn/my/myaccesstoken to authenticate the user. If not provided, the CLI will use the local credentials if available.)r    defaultr!   z--repo_typezIType of the repo to create (e.g. `dataset`, `model`). Default to `model`.)choicesr"   r!   z--visibilityz6Visibility of the repo to create. Default to `public`.z--chinese_namez6Optional, Chinese name of the repo. Default to `None`.z	--licensez?Optional, License of the repo. Default to `Apache License 2.0`.)r    r#   r"   r!   z
--endpointz9Optional, The modelscope server address. Default to None.zAIGC Model Creationz;Arguments for creating an AIGC model. Use --aigc to enable.z--aigc
store_truezEnable AIGC model creation.)actionr!   z--from_jsonztPath to a JSON file containing AIGC model configuration. If used, all other parameters except --repo_id are ignored.z--model_pathz!Path to the model file or folder.z--aigc_typez4AIGC type. Recommended: 'Checkpoint', 'LoRA', 'VAE'.z--base_model_typezBase model type, e.g., SD_XL.z
--revisionzv1.0z#Model revision. Defaults to 'v1.0'.z--base_model_id zBase model ID from ModelScope.z--descriptionzThis is an AIGC model.zModel description.z--path_in_repoz$Path in the repository to upload to.z--model_sourceUSER_UPLOADz_Source of the AIGC model. `USER_UPLOAD`, `TRAINED_FROM_MODELSCOPE` or `TRAINED_FROM_ALIYUN_FC`.z--base_model_sub_typez)Base model sub type, e.g., Qwen_Edit_2509)func)
add_parserr   nameadd_argumentstrr   r   r	   PUBLICINTERNALPRIVATEr   to_list	APACHE_V2add_argument_groupset_defaultsr   )r   parser
aigc_groups      r   define_argsCreateCMD.define_args   s    ")!3!3INN!CK 	 	M 	T 	 	
 	%#W 	 	
 	!!:#6#6
8J8J %%I 	 	
 	I	 	 	
 	$$&&&M 	 	
 	L	 	 	
 ..!IK
 	\0M 	  	OJ 	  	K
 	+N 	  	PG 	  	I 	0 	  	2 	6	 	  	8
 	1	 	  	3
 	,%	 	  	'
 	7	 	  	9
 	!m 	  	
 	#<	 	  	> 	0r   c                     U R                   R                  (       a:  U R                   R                  [        :w  a  [	        S5      eU R                  5         g U R                  5         g )Nz:AIGC models can only be created when repo_type is "model".)r   aigc	repo_typer   
ValueError_create_aigc_model_create_regular_repo)r   s    r   executeCreateCMD.execute   sI    99>>yy""o5 P  ##%%%'r   c                    [        U R                  R                  S9nUR                  U R                  R                  U R                  R
                  U R                  R                  U R                  R                  U R                  R                  U R                  R                  SSU R                  R                  S9	  g )NendpointT)	r   token
visibilityr:   chinese_namelicenseexist_okcreate_default_configrB   )
r   r   rB   create_repor   rC   rD   r:   rE   rF   )r   apis     r   r=   CreateCMD._create_regular_repo   s     dii001 	II%%))//yy++ii))//II%%"&YY'' 	 
	
r   c                    [        U R                  R                  S9nU R                  R                  nU R                  R                  (       aX  [
        R                  SU R                  R                   35        [        R                  " U R                  R                  5      nGO4[
        R                  S5        [        U R                  R                  U R                  R                  U R                  R                  /5      (       d  [        S5      e[        U R                  R                  U R                  R                  U R                  R                  U R                  R                  U R                  R                  U R                  R                   U R                  R"                  U R                  R$                  U R                  R&                  S9	n[(        R*                  " 5        VVs0 s H  u  pEXT_M	     nnnUR-                  U R                  R.                  [0        R2                  5      n UR5                  UU R                  R6                  UU R                  R8                  U R                  R:                  US9n[=        SU 35        g	s  snnf ! [>         a  n	[=        SU	 35         S	n	A	g	S	n	A	ff = f)
zExecute the command.rA   z$Creating AIGC model from JSON file: z2Creating AIGC model from command line arguments...z`Error: --model_path, --aigc_type, and --base_model_type are required when not using --from_json.)	
model_path	aigc_typebase_model_typetagdescriptionbase_model_idpath_in_repomodel_sourcebase_model_sub_type)model_idrC   rD   rF   rE   
aigc_modelz!Successfully created AIGC model: zError creating AIGC model: N) r   r   rB   r   	from_jsonloggerinfor   from_json_fileallrM   rN   rO   r;   revisionrQ   rR   rS   rT   rU   r
   itemsgetrD   r   r-   create_modelrC   rF   rE   print	Exception)
r   rJ   rV   rW   kvreverse_visibility_mapvisibility_idx	model_urles
             r   r<   CreateCMD._create_aigc_model   s   dii00199$$99KK>99../1 2"11$))2E2EFJ KKLMII(($))*=*=II--   !#$ $
 #99//))-- $		 9 9II&& II11"ii55!YY33!YY33$(II$A$A
J 4A3F3F3H!I3H41!$3H!I488II  /"8"8:
	5((!iioo)		))!YY33% ) 'I 5i[AB "J  	5/s344	5s   3J9AJ 
K (J;;K r   N)__name__
__module____qualname____firstlineno____doc__r*   r   r   staticmethodr6   r>   r=   r<   __static_attributes__ r   r   r   r      sJ     D.  j1. j1 j1X(
$15r   r   N)argparser   r   modelscope.cli.baser   modelscope.hub.apir   modelscope.hub.constantsr   r   r	   r
   modelscope.hub.utils.aigcr   modelscope.utils.constantr   r   modelscope.utils.loggerr   rY   r   r   rq   r   r   <module>ry      s;    6 * %5 5 / H .	D5
 D5r   