o
    0j                     @   s|  d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ dd	lmZmZmZmZ dd
lmZ g dZdejdddddddddfdedeee dB ejddf dededeee dB ejddf deee dB ejddf deedB ejddf deedB ejddf deeejddf deeejddf d ed!eeejd"df d#dfd$d%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

    # Download a subfolder
    hf download HuggingFaceM4/FineVision art/ --repo-type=dataset
    N)	Annotated)snapshot_download)CLIError)DryRunFileInfohf_hub_download)_format_size   )	RepoIdArgRepoTypeOptRevisionOptTokenOpt)out)z,hf download meta-llama/Llama-3.2-1B-InstructzGhf download meta-llama/Llama-3.2-1B-Instruct config.json tokenizer.jsonzXhf download meta-llama/Llama-3.2-1B-Instruct --include "*.safetensors" --exclude "*.bin"zGhf download meta-llama/Llama-3.2-1B-Instruct --local-dir ./models/llamaz=hf download HuggingFaceM4/FineVision art/ --repo-type datasetF   repo_id	filenamesz>Files to download (e.g. `config.json`, `data/metadata.jsonl`).)help	repo_typerevisionincludez;Glob patterns to include from files to download. eg: *.jsonexcludez0Glob patterns to exclude from files to download.	cache_dirzDirectory where to save files.	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-a-local-folder for more details.force_downloadzFIf True, the files will be downloaded even if they are already cached.dry_runzAIf True, perform a dry run without actually downloading the file.tokenmax_workerszEMaximum number of workers to use for downloading files. Default is 8.returnc                    s`   dt tB tt B f 	
fdd}dt tB tt B ddfdd}||  dS )zDownload files from the Hub.r   c                     s|  d urng } dd | D }dd |D }dd | D }t |dkrUd ur<t dkr<td|d  d|d  dd urUt dkrUtd|d  d	|d  d
t |dkryd urjt dkrjtd d uryt dkrytd t |dkrt |dkrt	j
|d  dd
S t |dkrt |dkr}}n|| }d }t	j
|| ddS )Nc                 S   s   g | ]	}| d r|qS /endswith.0f r$   ]/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/cli/download.py
<listcomp>}       z2download.<locals>.run_download.<locals>.<listcomp>c                 S   s   g | ]
}| d  dqS )r   z/**)rstripr!   r$   r$   r%   r&   ~   s    c                 S   s   g | ]	}| d s|qS r   r   r!   r$   r$   r%   r&      r'   r   z$Cannot combine subfolder argument ('z,') with `--include`. Please use `--include "z*"` instead.z,') with `--exclude`. Please use `--include "z*"` with `--exclude` instead.z?Ignoring `--include` since filenames have being explicitly set.z?Ignoring `--exclude` since filenames have being explicitly set.r   zhuggingface-cli)
r   r   r   filenamer   r   r   r   library_namer   )r   r   r   allow_patternsignore_patternsr   r   r   r   r*   r   r   )lenr   warningswarnr   valuer   )Zfilenames_listZ
subfoldersZsubfolder_patternsZregular_filenamesr+   r,   r   r   r   r   r   r   r   r   r   r   r   r   r$   r%   run_downloadx   sl   

zdownload.<locals>.run_downloadresultNc                 S   s   t | trtjd| d d S t | tr| g} dd | D }tdt| dt|  dttdd	 |D  d
 dd t	| dd dD }t
| d S )NZ
Downloaded)pathc                 S   s   g | ]}|j r|qS r$   )will_downloadr"   rr$   r$   r%   r&      s    z3download.<locals>._print_result.<locals>.<listcomp>z[dry-run] Will download z files (out of z) totalling c                 s   s    | ]}|j V  qd S N)	file_sizer6   r$   r$   r%   	<genexpr>   s    z2download.<locals>._print_result.<locals>.<genexpr>.c                 S   s(   g | ]}|j |jrt|jnd dqS )-)filesize)r)   r5   r   r9   )r"   infor$   r$   r%   r&      s    c                 S   s   | j S r8   )r)   )xr$   r$   r%   <lambda>   s    z1download.<locals>._print_result.<locals>.<lambda>)key)
isinstancestrr   r3   r   textr-   r   sumsortedtable)r3   r5   itemsr$   r$   r%   _print_result   s"   

zdownload.<locals>._print_result)rD   r   list)r   r   r   r   r   r   r   r   r   r   r   r   r2   rJ   r$   r1   r%   download@   s   48FrL   )__doc__r.   typingr   ZtyperZ"huggingface_hub._snapshot_downloadr   Zhuggingface_hub.errorsr   Zhuggingface_hub.file_downloadr   r   Zhuggingface_hub.utilsr   Z
_cli_utilsr	   r
   r   r   _outputr   ZDOWNLOAD_EXAMPLESmodelrK   rD   ZArgumentOptionboolintrL   r$   r$   r$   r%   <module>   s   
	


"(./5