U
    ”Ê¹jv   ã                   @   s–   d 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mZ d
dlmZ e	 e¡ZG dd„ deƒZdS )aº  Contains command to download files from the Hub with the CLI.

Usage:
    huggingface-cli download --help

    # Download file
    huggingface-cli download gpt2 config.json

    # Download entire repo
    huggingface-cli download fffiloni/zeroscope --repo-type=space --revision=refs/pr/78

    # Download repo with filters
    huggingface-cli download gpt2 --include="*.safetensors"

    # Download with token
    huggingface-cli download Wauplin/private-model --token=hf_***

    # Download quietly (no progress bar, no warnings, only the returned path)
    huggingface-cli download gpt2 config.json --quiet

    # Download to local dir
    huggingface-cli download gpt2 --local-dir=./models/gpt2
é    N)Ú	NamespaceÚ_SubParsersAction)ÚListÚOptional)Úlogging)Úsnapshot_download)ÚBaseHuggingfaceCLICommand)Úhf_hub_download)Údisable_progress_barsÚenable_progress_barsé   )Úshow_deprecation_warningc                   @   sJ   e Zd Zeedœdd„ƒZeddœdd„Zddœd	d
„Ze	dœdd„Z
dS )ÚDownloadCommand)Úparserc                 C   s  | j ddd�}|jdtdd� |jdtdd	d
� |jddddgddd� |jdtdd� |jddtdd� |jddtdd� |jdtdd� |jdtdd� |jddddgd d!� |jd"d#d$d%� |jd&d#d'd%� |jd(td)d� |jd*d#d+d%� |jd,td-d.d/� |jtd0� d S )1NÚdownloadzDownload files from the Hub)ÚhelpÚrepo_idz<ID of the repo to download from (e.g. `username/repo-name`).)Útyper   Ú	filenamesÚ*z>Files to download (e.g. `config.json`, `data/metadata.jsonl`).)r   Únargsr   z--repo-typeÚmodelZdatasetÚspacez4Type of repo to download from (defaults to 'model').)ÚchoicesÚdefaultr   z
--revisionzPAn optional Git revision id which can be a branch name, a tag, or a commit hash.z	--includez)Glob patterns to match files to download.)r   r   r   z	--excludez0Glob patterns to exclude from files to download.z--cache-dirz9Path to the directory where to save the downloaded files.z--local-dirz·If set, the downloaded file will be placed under this directory. Check out https://huggingface.co/docs/huggingface_hub/guides/download#download-files-to-local-folder for more details.z--local-dir-use-symlinksÚautoÚTrueÚFalsezWDeprecated and ignored. Downloading to a local directory does not use symlinks anymore.)r   r   z--force-downloadÚ
store_truezFIf True, the files will be downloaded even if they are already cached.)Úactionr   z--resume-downloadz“Deprecated and ignored. Downloading a file to local dir always attempts to resume previously interrupted downloads (unless hf-transfer is enabled).z--tokenzIA User Access Token generated from https://huggingface.co/settings/tokensz--quietzWIf True, progress bars are disabled and only the path to the download files is printed.z--max-workersé   zEMaximum number of workers to use for downloading files. Default is 8.)r   r   r   )Úfunc)Ú
add_parserÚadd_argumentÚstrÚintÚset_defaultsr   )r   Zdownload_parser© r'   ú`/var/www/html/bwave/python/venv/lib/python3.8/site-packages/huggingface_hub/commands/download.pyÚregister_subcommand8   sš      ÿ   ÿüý   ÿ   ÿ  ÿü	ýýý  ÿýüz#DownloadCommand.register_subcommandN)ÚargsÚreturnc                 C   s†   |j | _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
pXd | _
|j| _|j| _|jd k	r‚t dt¡ d S )NzbIgnoring --local-dir-use-symlinks. Downloading to a local directory does not use symlinks anymore.)Útokenr   r   Ú	repo_typeÚrevisionÚincludeÚexcludeÚ	cache_dirÚ	local_dirÚforce_downloadÚresume_downloadÚquietÚmax_workersZlocal_dir_use_symlinksÚwarningsÚwarnÚFutureWarning)Úselfr*   r'   r'   r(   Ú__init__}   s$    
þzDownloadCommand.__init__)r+   c              	   C   sh   t ddƒ | jrHtƒ  t ¡ � t d¡ t|  ¡ ƒ W 5 Q R X tƒ  nt	 
¡  t|  ¡ ƒ t	 ¡  d S )Nzhuggingface-cli downloadzhf downloadÚignore)r   r5   r
   r7   Úcatch_warningsÚsimplefilterÚprintÚ	_downloadr   r   Zset_verbosity_infoZset_verbosity_warning)r:   r'   r'   r(   Úrun’   s    


zDownloadCommand.runc                 C   sê   t | jƒdkrR| jd k	r0t | jƒdkr0t d¡ | jd k	rRt | jƒdkrRt d¡ t | jƒdkr’t| j| j| j	| jd | j
| j| j| j| jdd�
S t | jƒdkr®| j}| j}n
| j}d }t| j| j| j	||| j| j| j
| j| jd| jd�S )Nr   z?Ignoring `--include` since filenames have being explicitly set.z?Ignoring `--exclude` since filenames have being explicitly set.r   zhuggingface-cli)
r   r-   r.   Úfilenamer1   r4   r3   r,   r2   Úlibrary_name)r   r-   r.   Úallow_patternsÚignore_patternsr4   r3   r1   r,   r2   rC   r6   )Úlenr   r/   r7   r8   r0   r	   r   r-   r.   r1   r4   r3   r,   r2   r   r6   )r:   rD   rE   r'   r'   r(   r@       sJ    

öôzDownloadCommand._download)Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr   r)   r   r;   rA   r$   r@   r'   r'   r'   r(   r   7   s
   Dr   )Ú__doc__r7   Úargparser   r   Útypingr   r   Zhuggingface_hubr   Z"huggingface_hub._snapshot_downloadr   Zhuggingface_hub.commandsr   Zhuggingface_hub.file_downloadr	   Zhuggingface_hub.utilsr
   r   Z
_cli_utilsr   Z
get_loggerrG   Úloggerr   r'   r'   r'   r(   Ú<module>   s   
