o
    Zh#                     @   s   d Z ddlZddlmZmZ ddlmZmZ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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LiteralOptionalUnion)logging)snapshot_download)BaseHuggingfaceCLICommand)HF_HUB_ENABLE_HF_TRANSFER)hf_hub_download)disable_progress_barsenable_progress_barsc                   @   sH   e Zd ZedefddZdeddfddZdd	d
Zde	f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g d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g dddd |jdd d!d" |jd#d d$d" |jd%td&d |jd'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spacer   z4Type 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-dirzIf set, the downloaded file will be placed under this directory either as a symlink (default) or a regular file. 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Falser   aw  To be used with `local_dir`. If set to 'auto', the cache directory will be used and the file will be either duplicated or symlinked to the local directory depending on its size. It set to `True`, a symlink will be created, no matter the file size. If set to `False`, the file will either be duplicated from cache (if already exists) or downloaded from the Hub and not cached.z--force-download
store_truezFIf True, the files will be downloaded even if they are already cached.)actionr   z--resume-downloadz2If True, resume a previously interrupted download.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.)func)
add_parseradd_argumentstrset_defaultsr   )r   Zdownload_parser r&   X/var/www/html/lang_env/lib/python3.10/site-packages/huggingface_hub/commands/download.pyregister_subcommand7   sn   
z#DownloadCommand.register_subcommandargsreturnNc                 C   s   |j | _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
|j| _|  |j }|dkr@d| _d S |dkrId| _d S |dkrRd| _d S td|j d)NtrueTfalseFr   'za' is not a valid value for `local_dir_use_symlinks`. It must be either 'auto', 'True' or 'False'.)tokenr   r   	repo_typerevisionincludeexclude	cache_dir	local_dirforce_downloadresume_downloadquietlocal_dir_use_symlinkslower
ValueError)selfr)   Zuse_symlinks_lowercaser&   r&   r'   __init__{   s.   



zDownloadCommand.__init__c                 C   st   | j r*t  t  td t|   W d    n1 s w   Y  t  d S t	  t|   t
  d S )Nignore)r7   r   warnings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r)| jd urt | jdkrtd | jd ur)t | jdkr)td ts0td t | jdkrRt	| j
| j| j| jd | j| 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| jddS )	Nr   z?Ignoring `--include` since filenames have being explicitly set.z?Ignoring `--exclude` since filenames have being explicitly set.zConsider using `hf_transfer` for faster downloads. This solution comes with some limitations. See https://huggingface.co/docs/huggingface_hub/hf_transfer for more details.   zhuggingface-cli)r   r/   r0   filenamer3   r6   r5   r.   r4   r8   library_name)r   r/   r0   allow_patternsignore_patternsr6   r5   r3   r.   r4   r8   rF   )lenr   r1   r>   warnr2   r   loggerinfor   r   r/   r0   r3   r6   r5   r.   r4   r8   r	   )r;   rG   rH   r&   r&   r'   rB      sT   

zDownloadCommand._download)r*   N)__name__
__module____qualname__staticmethodr   r(   r   r<   rC   r$   rB   r&   r&   r&   r'   r   6   s    C
r   )__doc__r>   argparser   r   typingr   r   r   r   Zhuggingface_hubr   Z"huggingface_hub._snapshot_downloadr	   Zhuggingface_hub.commandsr
   Zhuggingface_hub.constantsr   Zhuggingface_hub.file_downloadr   Zhuggingface_hub.utilsr   r   Z
get_loggerrM   rK   r   r&   r&   r&   r'   <module>   s   
