
    j*                     l   d Z ddlZddlZddlZddlm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mZmZmZmZmZmZ dd	lmZ  ej        e          Zg d
Zddej        ddddddddddfdedeedz   ej        d          f         deedz   ej        d          f         dedededeee         dz   ej        d          f         deee         dz   ej        d          f         deee         dz   ej        d          f         deedz   ej        d          f         deedz   ej        d          f         dee  ej        d           f         d!ee!dz   ej        d"          f         d#ed$dfd%Z"dededz  dedz  dee         dz  d$e#eeee         dz  f         f
d&Z$dS )'a  Contains command to upload a repo or file with the CLI.

Usage:
    # Upload file (implicit)
    hf upload my-cool-model ./my-cool-model.safetensors

    # Upload file (explicit)
    hf upload my-cool-model ./my-cool-model.safetensors  model.safetensors

    # Upload directory (implicit). If `my-cool-model/` is a directory it will be uploaded, otherwise an exception is raised.
    hf upload my-cool-model

    # Upload directory (explicit)
    hf upload my-cool-model ./models/my-cool-model .

    # Upload filtered directory (example: tensorboard logs except for the last run)
    hf upload my-cool-model ./model/training /logs --include "*.tfevents.*" --exclude "*20230905*"

    # Upload with wildcard
    hf upload my-cool-model "./model/training/*.safetensors"

    # Upload private dataset
    hf upload Wauplin/my-cool-dataset ./data . --repo-type=dataset --private

    # Upload with token
    hf upload Wauplin/my-cool-model --token=hf_****

    # Sync local Space with Hub (upload new files, delete removed files)
    hf upload Wauplin/space-example --repo-type=space --exclude="/logs/*" --delete="*" --commit-message="Sync local Space with Hub"

    # Schedule commits every 30 minutes
    hf upload Wauplin/my-cool-model --every=30
    N)	Annotated)logging)CommitScheduler)RevisionNotFoundError   )
PrivateOpt	RepoIdArgRepoTypeRepoTypeOptRevisionOptTokenOpt
get_hf_api)out)zhf upload my-cool-model . .z:hf upload Wauplin/my-cool-model ./models/model.safetensorszChf upload Wauplin/my-cool-dataset ./data /train --repo-type=datasetzrhf upload Wauplin/my-cool-model ./models . --commit-message="Epoch 34/50" --commit-description="Val accuracy: 68%"z?hf upload bigcode/the-stack . . --repo-type dataset --create-prFrepo_id
local_pathzkLocal path to the file or folder to upload. Wildcard patterns are supported. Defaults to current directory.)helppath_in_repoz\Path of the file or folder in the repo. Defaults to the relative path of the file or folder.	repo_typerevisionprivateincludez'Glob patterns to match files to upload.excludez.Glob patterns to exclude from files to upload.deletezDGlob patterns for file to be deleted from the repo while committing.commit_messagez9The summary / title / first line of the generated commit.commit_descriptionz(The description of the generated commit.	create_prz0Whether to upload content as a new Pull Request.everyzNIf set, a background job is scheduled to create commits every `every` minutes.tokenreturnc                 .   	
 dk    rt          j        dd          |j        t          |          t	           |||          \  dt
          f
	 fd	} |            }t          j        d
|           dS )zLUpload a file or a folder to the Hub. Recommended for single-commit uploads.Nr   z --every must be a positive valuer   )
param_hint)r   )r   r   r   r   r   c                     t           j                                      r<t                    dk    r)t	          t
                    rt          j        d           't                    dk    rt          j        d           
't          
          dk    rt          j        d           t           j                                      rTt           j                                      } 	                              rd t                              n}g}g }n1} }}}
't          
          dk    rt          j        d           t          | |||
  
        }t          j        d d|j         d	           	 	 t          j        d           # t           $ r |                                 Y dS w xY wt           j                                      s2t           j                                      st'          d d                              d
dk    rdnd           j        }c	sa	                     |           nG# t,          $ r: t.                              d d                               |d
           Y nw xY wt           j                                      r                    |	          S                     |	
          S )Nr   z3Ignoring --include since a single file is uploaded.z3Ignoring --exclude since a single file is uploaded.z2Ignoring --delete since a single file is uploaded.z8Ignoring --delete when uploading with scheduled commits.)
folder_pathr   r   r   allow_patternsignore_patternsr   r   r   hf_apizScheduling commits every z minutes to .Td   zStopped scheduled commits.zNo such file or directory: 'z'.spacegradio)r   r   exist_okr   	space_sdk)r   r   r   zBranch 'z' not found. Creating it...)r   r   branchr+   )path_or_fileobjr   r   r   r   r   r   r   )r#   r   r   r   r   r   r   r   r$   r%   delete_patterns)ospathisfilelen
isinstancelistwarningswarndirnameendswithr   r   textr   timesleepKeyboardInterruptstopisdirFileNotFoundErrorcreate_repo	repo_infor   loggerinfocreate_branchupload_fileupload_folder)r#   pir$   r%   	schedulercreatedapir   r   r   r   r   r   r   r   repo_type_strresolved_includeresolved_local_pathresolved_path_in_repor   s         ]/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/huggingface_hub/cli/upload.py
run_uploadzupload.<locals>.run_upload   s   7>>-.. 	T+4D0E0E0I0IjYikoNpNp0ISTTT"s7||a'7'7STTT!c&kkAooRSSS  w~~122 ^ goo.ABB -556IJJ/)*ES1D-E-E,E*EFF. 
 #6!6"$1*!1")%#f++//M"\]]]'''!- /  I HXXXIDUXXXYYY4$JsOOO$$ 4 4 4   3334
 w~~122 	\27==I\;];] 	\#$ZCV$Z$Z$Z[[[//#"/7":":hh " 
 
  	 	lgQYZZZZ( l l lLxLLLMMM!!']S[fj!kkkkkl 7>>-.. 
	?? 32'!-#5# # 	 	 	   +.#)1+#" ! 
 
 	
s%   F( (G
	G

I# #AJ'&J'Uploaded)url)typerBadParametervaluer   _resolve_upload_pathsstrr   result)r   r   r   r   r   r   r   r   r   r   r   r   r   r   rQ   rY   rK   rL   rM   rN   rO   s   `   `` ``````   @@@@@rP   uploadrZ   S   s"   ~ UaZZ !CPWXXXXOM
5
!
!
!C DYJ\SZD D D@.0@c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
 c
J Z\\FJzv&&&&&&    c                 4   |                      d          d         }|}It          fddD                       r.|t          d          ||dk    rt          d          ddgfS $t          j                            |          r|||fS $t          j                            |          r|d|fS t          d| d	          |At          j                                      r"t          j                                      |fS |d|fS ||fS )
N/c              3       K   | ]}|v V  	d S )N ).0cr   s     rP   	<genexpr>z(_resolve_upload_paths.<locals>.<genexpr>  s'      %O%O!a:o%O%O%O%O%O%Or[   )*?[z9Cannot set --include when local_path contains a wildcard.r'   z<Cannot set path_in_repo when local_path contains a wildcard.'zB' is not a local file or folder. Please set local_path explicitly.)splitany
ValueErrorr0   r1   r2   r?   basename)r   r   r   r   	repo_namerM   s    `    rP   rW   rW     sS    c""2&I#%O%O%O%O%O%O%O"O"OXYYY#(;(;[\\\J%%bgnnY77)%555bgmmI66#///jYjjjkkkz : :27++J779III3 000|%555r[   )%__doc__r0   r;   r6   typingr   rT   huggingface_hubr   !huggingface_hub._commit_schedulerr   huggingface_hub.errorsr   
_cli_utilsr   r	   r
   r   r   r   r   _outputr   
get_logger__name__rC   UPLOAD_EXAMPLESmodelrX   Argumentr5   OptionboolfloatrZ   tuplerW   r`   r[   rP   <module>r}      s     D 
			          # # # # # # = = = = = = 8 8 8 8 8 8                        
	H	%	%    	 	%^  	 	 	 	 	 	 	wq' q'q'd
~	
 	
 	
	q' d
o	
 	
 	
	q' q' q'  !q'" S	D:	
 	
 	
	#q'. S	DA	
 	
 	
	/q': S	DW	
 	
 	
	;q'F d
L	
 	
 	
	Gq'R "d
;	
 	
 	
	Sq'^ C	
 	
 	
	_q'j a	
 	
 	
	kq'v wq'x 
yq' q' q' q'h66!$t6;>:6PTUXPY\`P`6
3T#Y%%&6 6 6 6 6 6r[   