
    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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)
    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                   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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     [/var/www/html/ai-engine/env/lib/python3.11/site-packages/huggingface_hub/commands/upload.pyregister_subcommandz!UploadCommand.register_subcommandA   s   ))(9i)jj""C&d 	# 	
 	
 	
 	""*v 	# 	
 	
 	
 	""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                 0   |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        /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')/.'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    L(,'+}!\,0L,0L+/;-1-@151H#~dj?PQQQ:
 :!djAooUtzUUUVVV&*j
 ++C004	?"rw~~i'@'@"'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)r@   r   warningscatch_warningssimplefilterprint_uploadr   r   set_verbosity_infoset_verbosity_warning)rI   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                              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        
  
        }t/          d| j         d	|j         d
           	 	 t1          j        d           # t4          $ 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[# tB          $ 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   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_   7>>$/** 	V|'C,=,=,A,AUVVV|'C,=,=,A,AUVVV{&3t{+;+;a+?+?TUUU( 	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 I%$I%'L? ?ANN)r.   N)__name__
__module____qualname__staticmethodr   r+   r   rK   rU   r&   rR    r,   r*   r   r   @   s        A7$5 A7 A7 A7 \A7F02Y 024 02 02 02 02d
, 
, 
, 
,h h h h h 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      s3   > 
			   1 1 1 1 1 1 1 1 ! ! ! ! ! ! ! ! # # # # # # = = = = = = > > > > > > ? ? ? ? ? ? 8 8 8 8 8 8 ( ( ( ( ( ( M M M M M M M M 
	H	%	%k k k k k- k k k k kr,   