
    9i"                        S SK rS SKrS SKrS SKrS SKJrJrJr  S SK	J
r
  S SKJrJrJ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  \" 5       r\R2                  R5                  S	S
9r\" 5       r\" 5       r\" 5       rSq S\SS4S\\!\
4   S\!S\!S\\!\"S4   S\\!   S\\!   S\\!   4S jjr#SSSSS\4S jr$SSSSSSS\4S jr%SSSSSS\4S jr&S r' " S S5      r(\(RR                  4S jr*S r+g)    N)ManagerProcessValue)Path)ListOptionalUnionHubApi)ModelVisibility)DEFAULT_REPOSITORY_REVISION)
get_logger   )max_workerspath_or_fileobjpath_in_reporepo_idtokenrevisioncommit_messagecommit_descriptionc                    [         R                  R                  U 5      (       d  gSSKJn  U" 5       nUR                  U5        U(       d  SnU(       a  US-   U-   n[        R                  " 5        n	SSKJ	n
  U
" XUS9nU(       a   [         R                  R                  X5      nOU	n[         R                  " USS	9  [         R                  R                  U 5      (       aT  [         R                  R                  U[         R                  R                  U 5      5      n[        R                  " X5        O[        R                   " XSS
9  UR#                  U5        SSS5        g! , (       d  f       g= f)zPush files to model hub incrementally

This function if used for patch_hub, user is not recommended to call this.
This function will be merged to push_to_hub in later sprints.
Nr   r
   zUpdating files
)
Repository)r   T)exist_ok)dirs_exist_ok)ospathexists
modelscoper   logintempfileTemporaryDirectorymodelscope.hub.repositoryr   joinmakedirsisfilebasenameshutilcopyfilecopytreepush)r   r   r   r   r   r   r   r   apitemp_cache_dirr   repo
sub_folder	dest_files                 Z/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/hub/push_to_hub.py_push_files_to_hubr3      s     77>>/**!
(CIIe)'$.1CC		$	$	&.8.HEnCJ'J
J.77>>/**Z%'WW%5%5o%FHIOOO7OOOtL		.! 
'	&	&s   1C*E$$
E2T c	                 j    [        5       n	U	R                  U5        U	R                  U UU(       d  [        R                  O[        R
                  U UUUUUS9	  U=(       d    Sn[        R                  SU  SU 35        g! [         a(  n
[        R                  SU  SU SU
 35         S n
A
gS n
A
ff = f)	N)
visibilitychinese_namer   tagoriginal_model_idignore_file_patternr   zNo commit messagez!Successfully upload the model to z with message: Tz#Error happens when uploading model z: F)
r   r!   
push_modelr   PUBLICPRIVATEloggerinfo	Exceptionerror)	repo_name
output_dirr   privater   r8   source_repor:   r   r-   es              r2   _api_push_to_hubrG   D   s    h		% '-- / 7 7")) 3 	 
	 (>+>/	{/.IYZ	
  1)ONK[[]^_]`a	
 	s   A=B   
B2
B--B2   c
                 "   Uc  [         R                  R                  S5      nUc  [         R                  R                  S5      nU c   eUc   S5       e[         R                  R	                  U5      (       d   eS[         R
                  " U5      ;   d6  S[         R
                  " U5      ;   d  S[         R
                  " U5      ;   d   e[        R                  SU SU  S	U 35        [        U5       H  n
[        XX#XVUX5	      (       d  M    g
   g)a  
Args:
    repo_name: The repo name for the modelhub repo
    output_dir: The local output_dir for the checkpoint
    token: The user api token, function will check the `MODELSCOPE_API_TOKEN` variable if this argument is None
    private: If is a private repo, default True
    retry: Retry times if something error in uploading, default 3
    commit_message: The commit message
    tag: The tag of this commit
    source_repo: The source repo (model id) which this model comes from
    ignore_file_pattern: The file pattern to be ignored in uploading.
    revision: The branch to commit to
Returns:
    The boolean value to represent whether the model is uploaded.
MODELSCOPE_API_TOKENUPLOAD_IGNORE_FILE_PATTERNUEither pass in a token or to set `MODELSCOPE_API_TOKEN` in the environment variables.configuration.jsonconfiguration.yamlconfiguration.yml
Uploading  to  with message TF)
r   environgetr   isdirlistdirr>   r?   rangerG   )rB   rC   r   rD   retryr   r8   rE   r:   r   is              r2   push_to_hubrZ   g   s   2 }

56" jjnn-IJ   uuu77==$$$$2::j#99=QUWU_U_`jUk=k!RZZ
%;;< < KK
ZLYK~n=MNP5\I5*/; ; 	 
     c	                    Uc  [         R                  R                  S5      nUc  [         R                  R                  S5      nU c   eUc   S5       e[         R                  R	                  U5      (       d   eS[         R
                  " U5      ;   d6  S[         R
                  " U5      ;   d  S[         R
                  " U5      ;   d   e[        R                  SU SU  S	U 35        [        R                  [        XUX4XVXx5
      $ )
aF  
Args:
    repo_name: The repo name for the modelhub repo
    output_dir: The local output_dir for the checkpoint
    token: The user api token, function will check the `MODELSCOPE_API_TOKEN` variable if this argument is None
    private: If is a private repo, default True
    commit_message: The commit message
    tag: The tag of this commit
    source_repo: The source repo (model id) which this model comes from
    ignore_file_pattern: The file pattern to be ignored in uploading
    revision: The branch to commit to
Returns:
    A handler to check the result and the status
rJ   rK   rL   rM   rN   rO   rP   rQ   rR   )r   rS   rT   r   rU   rV   r>   r?   	_executorsubmitrG   )	rB   rC   r   rD   r   r8   rE   r:   r   s	            r2   push_to_hub_asyncr_      s    . }

56" jjnn-IJ   uuu77==$$$$2::j#99=QUWU_U_`jUk=k!RZZ
%;;< < KK
ZLYK~n=MNP,iU#S/; ;r[   c                     SUl         U R                  5       n[        R                  U5        SUl         UR	                  SS5      (       dq  UR	                  SS5      nUR                  S5      n [        S0 UD6  U(       a:  [        R                  R                  U5      (       a  [        R                  " U5        Og M  ! [         a  n[        R                  U5         S nAN&S nAff = f)NTFdone
delete_dirrC    )valuerT   r>   r?   poprZ   r   r   r   r)   rmtreer@   rA   )qbitemrb   rC   rF   s         r2   submit_taskrj      s    
uuwDxx&&,6J,/J #d#"''.."<"<MM*-     Q s   0AC   
C)
C$$C)c                       \ rS rSrSrSrSrg)UploadStrategy   cancelwaitrc   N)__name__
__module____qualname____firstlineno__rn   ro   __static_attributes__rc   r[   r2   rl   rl      s    FDr[   rl   c                 j   U b  [        U 5      S:  d   S5       e[        c
  [        5       qU [        ;  ae  [        R	                  5       [        U '   [        SS5      [        U '   [        [        [        U    [        U    4S9nUR                  5         U[        U '   [        U    n[        U    nUR                  SS5      (       a  UR                  U5        g UR                  (       a=  U[        R                  :X  a)  [         R#                  SUR                  S5       S	35        g UR                  U5        g )
Nr   z"Please specify a valid queue name!rh   F)targetargsra   z:Another uploading is running, this uploading with message r   z will be canceled.)len_managerr   _queuesQueuer   _flagsr   rj   start_tasksrT   putrd   rl   rn   r>   rA   )
queue_namestrategykwargsprocessqueueflags         r2   push_to_hub_in_queuer      s   !c'' >=>  9 &nn.
"3.zgj&96*;M%NP$zJE$Dzz&%  		&	N$9$99++1::6F+G*HHZ\	

 			&r[   c                     [         R                  U S 5      nUc  g UR                  5         [        R                  U 5        [        R                  U 5        g )N)r~   re   r%   rz   r|   )r   r   s     r2   wait_for_doner      s;    zz*d3GLLNKK

JJzr[   ),concurrent.futures
concurrentr   r)   r"   multiprocessingr   r   r   pathlibr   typingr   r   r	   jsonmodelscope.hub.apir   modelscope.hub.constantsr   modelscope.utils.constantr   modelscope.utils.loggerr   r>   futuresProcessPoolExecutorr]   dictrz   r|   r~   ry   strboolr3   rG   rZ   r_   rj   rl   rn   r   r   rc   r[   r2   <module>r      s\    	   3 3  ( (  % 4 A .	22q2A	
&		 %)9$((,&"39%&"&" &" dD!	&"
 sm&" SM&" !&"X "$&!#)-9 J !$(4*^ !"%'"$*.:%;P& 
 /=.C.C 6r[   