
    wi8                         d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ  ej        e          Z G d de          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)	Namespace_SubParsersAction)ListOptional)logging)CommitScheduler)BaseHuggingfaceCLICommand)HF_HUB_ENABLE_HF_TRANSFER)RevisionNotFoundError)HfApi)disable_progress_barsenable_progress_bars)is_xet_availablec                   N    e Zd Zedefd            ZdeddfdZd	dZde	fdZ
dS )
UploadCommandparserc                    |                      dd          }|                    dt          d           |                    ddd	
           |                    ddd
           |                    dg ddd           |                    dt          d           |                    ddd           |                    ddt          d           |                    ddt          d           |                    ddt          d           |                    d t          d!           |                    d"t          d#           |                    d$dd%           |                    d&t          d'           |                    d(t          d)           |                    d*dd+           |                    t
          ,           d S )-NuploadzLUpload a file or a folder to the Hub. Recommended for single-commit uploads.)helprepo_idz<The ID of the repo to upload to (e.g. `username/repo-name`).)typer   
local_path?zkLocal path to the file or folder to upload. Wildcard patterns are supported. Defaults to current directory.)nargsr   path_in_repoz\Path of the file or folder in the repo. Defaults to the relative path of the file or folder.z--repo-type)modeldatasetspacer   z/Type of the repo to upload to (e.g. `dataset`).)choicesdefaultr   z
--revisionzAn optional Git revision to push to. It can be a branch name or a PR reference. If revision does not exist and `--create-pr` is not set, a branch will be automatically created.z	--private
store_truezfWhether to create a private repo if repo doesn't exist on the Hub. Ignored if the repo already exists.)actionr   z	--include*z'Glob patterns to match files to upload.)r   r   r   z	--excludez.Glob patterns to exclude from files to upload.z--deletezDGlob patterns for file to be deleted from the repo while committing.z--commit-messagez9The summary / title / first line of the generated commit.z--commit-descriptionz(The description of the generated commit.z--create-prz0Whether to upload content as a new Pull Request.z--everyzNIf set, a background job is scheduled to create commits every `every` minutes.z--tokenzIA User Access Token generated from https://huggingface.co/settings/tokensz--quietzWIf True, progress bars are disabled and only the path to the uploaded files is printed.)func)
add_parseradd_argumentstrfloatset_defaultsr   )r   upload_parsers     r/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/huggingface_hub/cli/upload.pyregister_subcommandz!UploadCommand.register_subcommandE   s   ))i * 
 
 	""C&d 	# 	
 	
 	
 	""~ 	# 	
 	
 	

 	""o 	# 	
 	
 	

 	""111B	 	# 	
 	
 	
 	""_	 	# 	
 	
 	
 	""	 	# 	
 	
 	
 	"";cJs"ttt""s3c 	# 	
 	
 	
 	""W	 	# 	
 	
 	
 	""S/j 	# 	
 	
 	
 	""#9Jt"uuu"",5g 	# 	
 	
 	
 	""a 	# 	
 	
 	

 	""C&q 	# 	
 	
 	
 	""j 	# 	
 	
 	

 	"""66666    argsreturnNc                    j         | _         j        | _        j        | _        j        | _        j        | _        j        | _        j        | _        j        | _        j        | _        j	        | _	        t          j        d          | _        j        | _        j        #j        dk    rt          dj         d          j        | _        j                             d          d         }|  |  j        nt%          fdd	D                       rSj        t          d
          j        j        dk    rt          d          d| _        j        | _        d| _        d S j        /t(          j                            |          r|| _        || _        d S j        /t(          j                            |          r|| _        d| _        d S j        t          d| d          j        [t(          j                            j                  r7j        | _        t(          j                            j                  | _        d S j        j        | _        d| _        d S j        | _        j        | _        d S )Nzhuggingface-cli)tokenlibrary_namer   z'`every` must be a positive value (got 'z')/c              3   *   K   | ]}|j         v V  d S )N)r   ).0cr.   s     r+   	<genexpr>z)UploadCommand.__init__.<locals>.<genexpr>   s*      .].]qDO/C.].].].].].]r-   )r#   r   [zICannot set `--include` when passing a `local_path` containing a wildcard..zLCannot set `path_in_repo` when passing a `local_path` containing a wildcard.'zD' is not a local file or folder. Please set `local_path` explicitly.)r   	repo_typerevisionprivateincludeexcludedeletecommit_messagecommit_description	create_prr   r1   apiquietevery
ValueErrorsplitr   anyr   ospathisfileisdirbasename)selfr.   	repo_names    ` r+   __init__zUploadCommand.__init__   sm    L(,'+}!\,0L,0L+/;-1-@151H#~dj?PQQQ:
 :!djAooUtzUUUVVV&*j
 ++C004	?&3.].].].]_.].].]+]+]&|' !lmmm ,1Bc1I1I !oppp!DO?DL #D_$	)B)B$'DO )D_$y)A)A$'DO #D_$ ppppqqq&27>>$/+J+J&"oDO " 0 0 A AD&"oDO #D #oDO $ 1Dr-   c                    | j         r~t                       t          j                    5  t          j        d           t          |                                            d d d            n# 1 swxY w Y   t                       d S t          j	                     t          |                                            t          j
                     d S )Nignore)rF   r   warningscatch_warningssimplefilterprint_uploadr   r   set_verbosity_infoset_verbosity_warning)rP   s    r+   runzUploadCommand.run   s    : 		,!###(** & &%h///dllnn%%%& & & & & & & & & & & & & & & !"""""&((($,,..!!!)+++++s   6A++A/2A/c                    t           j                            | j                  r| j        ,t          | j                  dk    rt          j        d           | j        ,t          | j                  dk    rt          j        d           | j	        ,t          | j	                  dk    rt          j        d           t                      s!t          st                              d           | j        t           j                            | j                  rwt           j                            | j                  }| j                            | j                  r"| j        d t          | j                            n| j        }| j        g}g }nS| j        }| j        }| j        pg }| j        pg }| j	        ,t          | j	                  dk    rt          j        d           t%          || j        | j        | j        |||| j        | j        | j        
  
        }t1          d| j         d	|j         d
           	 	 t3          j        d           # t6          $ r |                                 Y dS w xY wt           j                            | j                  s<t           j                            | j                  st=          d| j         d          | j                            | j        | j        d| j        | j        dk    rdnd           j        }| j        | j         s	 | j        !                    || j        | j                   n[# tD          $ rN t                              d| j         d           | j        #                    || j        | j        d           Y nw xY wt           j                            | j                  rE| j        $                    | j        | j        || j        | j        | j%        | j&        | j                   S | j        '                    | j        | j        || j        | j        | j%        | j&        | j         | j        | j        | j	                  S )Nr   z5Ignoring `--include` since a single file is uploaded.z5Ignoring `--exclude` since a single file is uploaded.z4Ignoring `--delete` since a single file is uploaded.zConsider using `hf_transfer` for faster uploads. This solution comes with some limitations. See https://huggingface.co/docs/huggingface_hub/hf_transfer for more details.z:Ignoring `--delete` when uploading with scheduled commits.)
folder_pathr   r<   r=   allow_patternsignore_patternsr   r>   rG   hf_apizScheduling commits every z minutes to r:   Td   zStopped scheduled commits.zNo such file or directory: 'z'.r   gradio)r   r<   exist_okr>   	space_sdk)r   r<   r=   zBranch 'z' not found. Creating it...)r   r<   branchrd   )path_or_fileobjr   r   r<   r=   rB   rC   rD   )r^   r   r   r<   r=   rB   rC   rD   r_   r`   delete_patterns)(rK   rL   rM   r   r?   lenrU   warnr@   rA   r   r
   loggerinforG   dirnamer   endswithr   r   r<   r=   r>   rE   rX   timesleepKeyboardInterruptstoprN   FileNotFoundErrorcreate_reporD   	repo_infor   create_branchupload_filerB   rC   upload_folder)rP   r^   r   r_   r`   	schedulerr   s          r+   rY   zUploadCommand._upload   sm   7>>$/** 	V|'C,=,=,A,AUVVV|'C,=,=,A,AUVVV{&3t{+;+;a+?+?TUUU!! 	*C 	KK]   :!w~~do.. ` goodo>> (11$/BB+D%&=T_)=)=(=&=>>* 
 #'/!2"$"o#0!%!3"&,"4";*s4;/?/?!/C/CM"^___''.- /)jx  I ZdjZZiFWZZZ[[[4$JsOOO$$ 4 4 4   3334
 w~~do.. 	Xrw}}T_7U7U 	X#$V4?$V$V$VWWW(&&LnL"&.G";";hh ' 
 
  	 =$T^$w""7dnW[Wd"eeee( w w wQt}QQQRRR&&w$.Y]Yfqu&vvvvvw 7>>$/** 	8'' $!..#2#'#:. ( 	 	 	 8)) O!..#2#'#:.#| $ $ *   s%   ;I I32I3%'M AN%$N%)r/   N)__name__
__module____qualname__staticmethodr   r,   r   rR   r\   r'   rY    r-   r+   r   r   D   s        E7$5 E7 E7 E7 \E7N92Y 924 92 92 92 92v
, 
, 
, 
,h h h h h h hr-   r   )__doc__rK   ro   rU   argparser   r   typingr   r   huggingface_hubr   !huggingface_hub._commit_schedulerr   huggingface_hub.commandsr	   huggingface_hub.constantsr
   huggingface_hub.errorsr   huggingface_hub.hf_apir   huggingface_hub.utilsr   r   huggingface_hub.utils._runtimer   
get_loggerrz   rk   r   r~   r-   r+   <module>r      sF     D 
			   1 1 1 1 1 1 1 1 ! ! ! ! ! ! ! ! # # # # # # = = = = = = > > > > > > ? ? ? ? ? ? 8 8 8 8 8 8 ( ( ( ( ( ( M M M M M M M M ; ; ; ; ; ; 
	H	%	%x x x x x- x x x x xr-   