Ë
    Q^(hu8  ã                   óÞ   — 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
--revisionz°An 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/skyplay_api_hub/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   øè ø€ Ò.]È¨q°D·O±OÔ/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  ø€ Ø ŸL™LˆŒØ(,¯©ˆŒØ'+§}¡}ˆŒØ!Ÿ\™\ˆŒà,0¯L©LˆŒØ,0¯L©LˆŒØ+/¯;©;ˆŒà-1×-@Ñ-@ˆÔØ15×1HÑ1HˆÔØ#Ÿ~™~ˆŒÜ d§j¡jÐ?PÔQˆŒØŸ:™:ˆŒ
ð �:‰:Ð! d§j¡j°A¢oÜÐFÀtÇzÁzÀlÐRTÐUÓVÐVØ&*§j¡jˆŒ
ð Ÿ™×+Ñ+¨CÓ0°Ñ4ˆ	ÙÙà�?‰?Ð&¬3Ó.]È_Ô.]Ô+]Ø�|‰|Ð'Ü Ð!lÓmÐmØ× Ñ Ð,°×1BÑ1BÀcÒ1IÜ Ð!oÓpÐpØ!ˆDŒOØŸ?™?ˆDŒLØ #ˆDÕØ�_‰_Ð$¬¯©¯©¸	Ô)Bà'ˆDŒOØ )ˆDÕØ�_‰_Ð$¬¯©¯©°yÔ)Aà'ˆDŒOØ #ˆDÕØ�_‰_Ð$ô ˜q  Ð+oÐpÓqÐqØ×ÑÐ&¬2¯7©7¯>©>¸$¿/¹/Ô+Jà"Ÿo™oˆDŒOÜ "§¡× 0Ñ 0°·±Ó AˆDÕØ×ÑÐ&à"Ÿo™oˆDŒOØ #ˆDÕð #Ÿo™oˆDŒOØ $× 1Ñ 1ˆDÕ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Ô/Ü�d—l‘l“nÔ%÷&ô !Õ"ä×&Ñ&Ô(Ü�$—,‘,“.Ô!Ü×)Ñ)Õ+÷&ô !Õ"ú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                  «      r�t         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.z©Consider 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:   Téd   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!  € Ü�7‰7�>‰>˜$Ÿ/™/Ô*Ø�|‰|Ð'¬C°·±Ó,=ÀÒ,AÜ—‘ÐUÔVØ�|‰|Ð'¬C°·±Ó,=ÀÒ,AÜ—‘ÐUÔVØ�{‰{Ð&¬3¨t¯{©{Ó+;¸aÒ+?Ü—‘ÐTÔUäÔ!Õ*CÜ�K‰Kð]ôð �:‰:Ñ!Ü�w‰w�~‰~˜dŸo™oÔ.ä Ÿg™gŸo™o¨d¯o©oÓ>�ð ×(Ñ(×1Ñ1°$·/±/ÔBð ×%Ñ%Ð&=¬¨T¯_©_Ó)=Ð(=Ñ>à×*Ñ*ð ð
 #'§/¡/Ð!2�Ø"$‘à"Ÿo™o�Ø#×0Ñ0�Ø!%§¡Ò!3°�Ø"&§,¡,Ò"4°"�Ø—;‘;Ð*¬s°4·;±;Ó/?À!Ò/CÜ—M‘MÐ"^Ô_ä'Ø'ØŸ™ØŸ.™.ØŸ™Ø-Ø /Ø)ØŸ™Ø—j‘jØ—x‘xôˆIô Ð-¨d¯j©j¨\¸Ài×FWÑFWÐEXÐXYÐZÔ[ð4ØÜ—J‘J˜s”Oð ô �w‰w�~‰~˜dŸo™oÔ.´r·w±w·}±}ÀTÇ_Á_Ô7UÜ#Ð&BÀ4Ç?Á?ÐBSÐSUÐ$VÓWÐWØ—(‘(×&Ñ&Ø—L‘LØ—n‘nØØ—L‘LØ"&§.¡.°GÒ";‘hÀð 'ó 
÷ ‰'ð 	ð �=‰=Ð$¨T¯^ª^ðwØ—‘×"Ñ"¨7¸d¿n¹nÐW[×WdÑWdÐ"Ôeô �7‰7�>‰>˜$Ÿ/™/Ô*Ø—8‘8×'Ñ'Ø $§¡Ø!×.Ñ.ØØŸ.™.ØŸ™Ø#×2Ñ2Ø#'×#:Ñ#:ØŸ.™.ð (ó 	ð 	ð —8‘8×)Ñ)Ø ŸO™OØ!×.Ñ.ØØŸ.™.ØŸ™Ø#×2Ñ2Ø#'×#:Ñ#:ØŸ.™.Ø#Ÿ|™|Ø $§¡Ø $§¡ð *ó ð øôS %ò 4Ø—‘Ô Ù3ð4ûô* )ò wÜ—‘˜h t§}¡} oÐ5PÐQÔRØ—‘×&Ñ&¨wÀ$Ç.Á.ÐY]×YfÑYfÐquÐ&×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7ðJ92˜Yð 92¨4ó 92óv
,ð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-   