
    ;3hu8                         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j6                  e      Z G d de      Zy)aa  Contains command to upload a repo or file with the CLI.

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

    # Upload file (explicit)
    huggingface-cli 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.
    huggingface-cli upload my-cool-model

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

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

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

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

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

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

    # Schedule commits every 30 minutes
    huggingface-cli 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                   F    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
y)
UploadCommandparserc                    | j                  dd      }|j                  dt        d       |j                  ddd	
       |j                  ddd
       |j                  dg ddd       |j                  dt        d       |j                  ddd       |j                  ddt        d       |j                  ddt        d       |j                  ddt        d       |j                  d t        d!       |j                  d"t        d#       |j                  d$dd%       |j                  d&t        d'       |j                  d(t        d)       |j                  d*dd+       |j	                  t
        ,       y )-Nuploadz.Upload a file or a folder to a repo on the Hub)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     _/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/huggingface_hub/commands/upload.pyregister_subcommandz!UploadCommand.register_subcommandE   s   ))(9i)j""C&d 	# 	
 	""~ 	# 	

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

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

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

 	"""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                   j!                  d      d   }|  |  j"                  qt%        fdd	D              r]j                  t        d
      j&                  j&                  dk7  rt        d      d| _        j"                  | _        d| _        y j"                  .t(        j*                  j-                  |      r|| _        || _        y j"                  .t(        j*                  j/                  |      r|| _        d| _        y j"                  t        d| d      j&                  it(        j*                  j-                  j"                        r@j"                  | _        t(        j*                  j1                  j"                        | _        y j&                  j"                  | _        d| _        y j"                  | _        j&                  | _        y )Nzhuggingface-cli)tokenlibrary_namer   z'`every` must be a positive value (got 'z')/c              3   :   K   | ]  }|j                   v   y w)N)r   ).0cr.   s     r+   	<genexpr>z)UploadCommand.__init__.<locals>.<genexpr>   s     .]qDOO/C.]s   )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    LL(,'+}}!\\,0LL,0LL+/;;-1-@-@151H1H#~~djj?PQ::
 ::!djjAoFtzzlRTUVV&*jj
 ++C04	??&3.]_.]+]||' !lmm  ,1B1Bc1I !opp!DO??DL #D__$	)B'DO )D__$y)A'DO #D__$ q+opqq&277>>$//+J"ooDO " 0 0 AD&"ooDO #D #ooDO $ 1 1Dr-   c                    | j                   r`t                t        j                         5  t        j                  d       t        | j                                d d d        t                y t        j                          t        | j                                t        j                          y # 1 sw Y   t                y xY w)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/dlln%& !"&&($,,.!))+& !"s   /B//Cc                 
   t         j                  j                  | j                        r| j                  -t        | j                        dkD  rt        j                  d       | j                  -t        | j                        dkD  rt        j                  d       | j                  -t        | j                        dkD  rt        j                  d       t               st        st        j                  d       | j                  t         j                  j                  | j                        rt         j                  j                  | j                        }| j                   j#                  | j                        r#| j                   d t        | j                          n| j                   }| j                  g}g }nq| j                  }| j                   }| j                  xs g }| j                  xs g }| j                  -t        | j                        dkD  rt        j                  d       t%        || j&                  | j(                  | j*                  |||| j,                  | j                  | j.                  
      }t1        d| j                   d	|j&                   d
       	 	 t3        j4                  d       t         j                  j                  | j                        sBt         j                  j;                  | j                        st=        d| j                   d      | j.                  j?                  | j&                  | j(                  d| j,                  | j(                  dk(  rdnd       j&                  }| j*                  ?| j@                  s3	 | j.                  jC                  || j(                  | j*                         t         j                  j                  | j                        ri| j.                  jI                  | j                  | j                   || j(                  | j*                  | jJ                  | jL                  | j@                        S | j.                  jO                  | j                  | j                   || j(                  | j*                  | jJ                  | jL                  | j@                  | j                  | j                  | j                        S # t6        $ r |j9                          Y yw xY w# tD        $ rZ t        j                  d| j*                   d       | j.                  jG                  || j(                  | j*                  d       Y w xY w)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   s!   77>>$//*||'C,=,AUV||'C,=,AUV{{&3t{{+;a+?TU!*CKK] ::!ww~~doo. ggoodoo> ((11$//B %%&=T__)=(=>** 
 #'//!2"$"oo#00!%!3"&,,"4";;*s4;;/?!/CMM"^_''..- /)jjxxI -djj\iFWFWEXXYZ[4JJsO  ww~~doo.rww}}T__7U#&B4??BSSU$VWW((&&LLnnLL"&..G";h ' 
 ' 	 ==$T^^w""7dnnW[WdWd"e 77>>$//*88'' $!....#22#'#:#:.. ( 	 	 88)) OO!....#22#'#:#:..#|| $ $ *  S % 4 34* ) wht}}o5PQR&&w$..Y]YfYfqu&vws%   &S( 2T (TTAU*)U*)r/   N)__name__
__module____qualname__staticmethodr   r,   r   rR   r\   r'   rY    r-   r+   r   r   D   sG    C7$5 C7 C7J92Y 924 92v
,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      sW    D 
   1 ! # = > ? 8 ( M ; 
		H	%v- vr-   