U
    ”Ê¹jå  ã                   @   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 e	 e¡ZG d
d„ deƒZdS )a_  Contains command to download files from the Hub with the CLI.

Usage:
    hf download --help

    # Download file
    hf download gpt2 config.json

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

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

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

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

    # Download to local dir
    hf download gpt2 --local-dir=./models/gpt2
é    N)Ú	NamespaceÚ_SubParsersAction)ÚListÚOptional)Úlogging)Úsnapshot_download)ÚBaseHuggingfaceCLICommand)Úhf_hub_download)Údisable_progress_barsÚenable_progress_barsc                   @   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� |jd td!d� |jd"dd#d� |jd$td%d&d'� |jtd(� d S ))NÚ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--force-downloadÚ
store_truezFIf True, the files will be downloaded even if they are already cached.)Úactionr   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/cli/download.pyÚregister_subcommand6   s†      ÿ   ÿüý   ÿ   ÿ  ÿü	ý  ÿýüz#DownloadCommand.register_subcommandN)ÚargsÚreturnc                 C   sd   |j | _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
|j| _d S )N)Útokenr   r   Ú	repo_typeÚrevisionÚincludeÚexcludeÚ	cache_dirÚ	local_dirÚforce_downloadÚquietÚmax_workers)Úselfr%   r"   r"   r#   Ú__init__q   s    zDownloadCommand.__init__)r&   c              	   C   s^   | j r>tƒ  t ¡ � t d¡ t|  ¡ ƒ W 5 Q R X tƒ  nt 	¡  t|  ¡ ƒ t 
¡  d S )NÚignore)r/   r
   ÚwarningsÚcatch_warningsÚsimplefilterÚprintÚ	_downloadr   r   Zset_verbosity_infoZset_verbosity_warning)r1   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dd�	S t | jƒdkrª| j}| j}n
| j}d }t| 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.é   zhuggingface-cli)	r   r(   r)   Úfilenamer,   r.   r'   r-   Úlibrary_name)r   r(   r)   Úallow_patternsÚignore_patternsr.   r,   r'   r-   r<   r0   )Úlenr   r*   r4   Úwarnr+   r	   r   r(   r)   r,   r.   r'   r-   r   r0   )r1   r=   r>   r"   r"   r#   r8   ‹   sF    

÷õzDownloadCommand._download)Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr   r$   r   r2   r9   r   r8   r"   r"   r"   r#   r   5   s
   :r   )Ú__doc__r4   Ú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
get_loggerrA   Úloggerr   r"   r"   r"   r#   Ú<module>   s   
