
    gX5                         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  ej2                  e      Z G d de      Zy)a  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 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_barsc                   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?zJLocal path to the file or folder to upload. 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     T/var/www/openai/venv/lib/python3.12/site-packages/huggingface_hub/commands/upload.pyregister_subcommandz!UploadCommand.register_subcommandA   s   ))(9i)j""C&d 	# 	
 	""*v 	# 	
 	""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"                  .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&                  j/                  |j"                        | _        y |j*                  |j"                  | _        d| _        y |j"                  | _        |j*                  | _        y )Nzhuggingface-cli)tokenlibrary_namer   z'`every` must be a positive value (got 'z')/.'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   r0   apiquietevery
ValueErrorsplitr   ospathisfiler   isdirbasename)selfr-   	repo_names      r*   __init__zUploadCommand.__init__   s    LL(,'+}}!\\,0LL,0LL+/;;-1-@-@151H1H#~~djj?PQ::
 ::!djjAoFtzzlRTUVV&*jj
 ++C04	??"rww~~i'@'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)r@   r   warningscatch_warningssimplefilterprint_uploadr   r   set_verbosity_infoset_verbosity_warning)rI   s    r*   runzUploadCommand.run   sx    ::!#((*%%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        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,                  
      }t/        d| j                   d	|j$                   d
       	 	 t1        j2                  d       t         j                  j                  | j                        sBt         j                  j9                  | j                        st;        d| j                   d      | j,                  j=                  | j$                  | j&                  d| j*                  | j&                  dk(  rdnd       j$                  }| j(                  ?| j>                  s3	 | j,                  jA                  || j&                  | j(                         t         j                  j                  | j                        ri| j,                  jG                  | j                  | j                  || j&                  | j(                  | jH                  | jJ                  | j>                        S | j,                  jM                  | j                  | j                  || j&                  | j(                  | jH                  | jJ                  | j>                  | j                  | j                  | j                        S # t4        $ r |j7                          Y yw xY w# tB        $ rZ t        j                  d| j(                   d       | j,                  jE                  || 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   r6   r7   allow_patternsignore_patternsr   r8   rA   hf_apizScheduling commits every z minutes to r4   Td   zStopped scheduled commits.zNo such file or directory: 'z'.r   gradio)r   r6   exist_okr8   	space_sdk)r   r6   r7   zBranch 'z' not found. Creating it...)r   r6   branchr]   )path_or_fileobjr   r   r6   r7   r<   r=   r>   )rW   r   r   r6   r7   r<   r=   r>   rX   rY   delete_patterns)'rD   rE   rF   r   r9   lenrN   warnr:   r;   r
   loggerinforA   dirnamer   endswithr   r   r6   r7   r8   r?   rQ   timesleepKeyboardInterruptstoprG   FileNotFoundErrorcreate_repor>   	repo_infor   create_branchupload_filer<   r=   upload_folder)rI   rW   r   rX   rY   	schedulerr   s          r*   rR   zUploadCommand._upload   s   77>>$//*||'C,=,AUV||'C,=,AUV{{&3t{{+;a+?TU(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 2S= S:9S:=AU U )r.   N)__name__
__module____qualname__staticmethodr   r+   r   rK   rU   r&   rR    r,   r*   r   r   @   sG    A7$5 A7 A7F02Y 024 02d
,h hr,   r   )__doc__rD   rh   rN   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   
get_loggerrs   rd   r   rw   r,   r*   <module>r      sS   > 
   1 ! # = > ? 8 ( M 
		H	%k- kr,   