o
    hv                      @   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 d
dl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Optional)logging)snapshot_download)BaseHuggingfaceCLICommand)hf_hub_download)disable_progress_barsenable_progress_bars   )show_deprecation_warningc                   @   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 |jdd 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--local-dir-use-symlinks)autoTrueFalsezWDeprecated and ignored. Downloading to a local directory does not use symlinks anymore.)r   r   z--force-download
store_truezFIf True, the files will be downloaded even if they are already cached.)actionr   z--resume-downloadzDeprecated and ignored. Downloading a file to local dir always attempts to resume previously interrupted downloads (unless hf-transfer is enabled).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)   ^/var/www/Befach/backend/venv/lib/python3.10/site-packages/huggingface_hub/commands/download.pyregister_subcommand8   s|   	z#DownloadCommand.register_subcommandargsreturnNc                 C   s   |j | _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
p,d | _
|j| _|j| _|jd urCtdt d S d S )NzbIgnoring --local-dir-use-symlinks. Downloading to a local directory does not use symlinks anymore.)tokenr   r   	repo_typerevisionincludeexclude	cache_dir	local_dirforce_downloadresume_downloadquietmax_workerslocal_dir_use_symlinkswarningswarnFutureWarning)selfr,   r)   r)   r*   __init__}   s&   
zDownloadCommand.__init__c                 C   s~   t dd | jr/t  t  td t|   W d    n1 s%w   Y  t  d S t	
  t|   t	  d S )Nzhuggingface-cli downloadzhf downloadignore)r   r7   r
   r:   catch_warningssimplefilterprint	_downloadr   r   set_verbosity_info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 | jdkrIt| j| j| j	| jd | j
| j| j| j| jdd
S t | jdkrW| j}| j}n| j}d }t| j| 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.r   zhuggingface-cli)
r   r/   r0   filenamer3   r6   r5   r.   r4   library_name)r   r/   r0   allow_patternsignore_patternsr6   r5   r3   r.   r4   rH   r8   )lenr   r1   r:   r;   r2   r	   r   r/   r0   r3   r6   r5   r.   r4   r   r8   )r=   rI   rJ   r)   r)   r*   rC      sJ   

zDownloadCommand._download)r-   N)__name__
__module____qualname__staticmethodr   r+   r   r>   rF   r%   rC   r)   r)   r)   r*   r   7   s    D
r   )__doc__r:   argparser   r   typingr   r   huggingface_hubr   "huggingface_hub._snapshot_downloadr   huggingface_hub.commandsr   huggingface_hub.file_downloadr	   huggingface_hub.utilsr
   r   
_cli_utilsr   
get_loggerrL   loggerr   r)   r)   r)   r*   <module>   s   
