U
    9%e>"                     @   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m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_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g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spacez/Type of repo to download from (e.g. `dataset`).)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Falseaw  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%   `/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/huggingface_hub/commands/download.pyregister_subcommand2   s                 
    z#DownloadCommand.register_subcommandN)argsreturnc                 C   s   |j | _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
|j| _|  |j }|dkr~d| _n2|dkrd| _n"|dkrd| _ntd|j dd S )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__v   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)r6   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rR| jd k	r0t | jdkr0td | jd k	rRt | jdkrRtd t | jdkrt| 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.   zhuggingface-cli)r   r.   r/   filenamer2   r5   r4   r-   r3   r7   library_name)r   r.   r/   allow_patternsignore_patternsr5   r4   r2   r-   r3   r7   rE   )lenr   r0   r=   warnr1   r   r   r.   r/   r2   r5   r4   r-   r3   r7   r	   )r:   rF   rG   r%   r%   r&   rA      sL    

zDownloadCommand._download)__name__
__module____qualname__staticmethodr   r'   r   r;   rB   r#   rA   r%   r%   r%   r&   r   1   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.file_downloadr   Zhuggingface_hub.utilsr   r   r   r%   r%   r%   r&   <module>   s   