a
    h                     @   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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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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. 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"   X/var/www/html/assistant/venv/lib/python3.9/site-packages/huggingface_hub/cli/download.pyregister_subcommand6   sh    	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   sr   | j rRt  t & td t|   W d    n1 s@0    Y  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 ur0t | jdkr0td | jd urRt | jdkrRtd t | jdkrt| 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hf)	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   
