o
    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                   @   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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)model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   download_parser r$   R/var/www/html/ai/venv/lib/python3.10/site-packages/huggingface_hub/cli/download.pyregister_subcommand6   sh   	z#DownloadCommand.register_subcommandargsreturnNc                 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__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)r1   r
   warningscatch_warningssimplefilterprint	_downloadr   r   set_verbosity_infoset_verbosity_warning)r3   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 | jdkrGt| j| j| j	| jd | j
| j| j| jdd	S t | jdkrU| 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.   hf)	r   r*   r+   filenamer.   r0   r)   r/   library_name)r   r*   r+   allow_patternsignore_patternsr0   r.   r)   r/   rA   r2   )lenr   r,   r6   warnr-   r	   r   r*   r+   r.   r0   r)   r/   r   r2   )r3   rB   rC   r$   r$   r%   r:      sF   

zDownloadCommand._download)r(   N)__name__
__module____qualname__staticmethodr   r&   r   r4   r=   r    r:   r$   r$   r$   r%   r   5   s    :
r   )__doc__r6   argparser   r   typingr   r   huggingface_hubr   "huggingface_hub._snapshot_downloadr   huggingface_hub.commandsr   huggingface_hub.file_downloadr	   huggingface_hub.utilsr
   r   
get_loggerrF   loggerr   r$   r$   r$   r%   <module>   s   
