
    "ju                        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mZ dd
lmZmZ g dZdej        dddddddddej        fdedeee         dz   ej        d          f         dededeee         dz   ej        d          f         deee         dz   ej        d          f         deedz   ej        d          f         deedz   ej        d          f         dee ej        d          f         dee ej        d          f         d ed!ee ej        d"          f         d#ed$df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   )FormatWithAutoOpt	RepoIdArgRepoTypeOptRevisionOptTokenOpt)OutputFormatWithAuto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.formatreturnc                     	
 dt           t          z  t          t                   z  f	 
fd}dt           t          z  t          t                   z  ddfd} | |                       dS )zDownload files from the Hub.r    c                  \   		ng } d | D             }d |D             }d | D             }t          |          dk    rn5t                    dk    r"t          d|d          d|d          d          5t                    dk    r"t          d|d          d|d          d	          t          |          dk    rR't                    dk    rt          j        d
           't                    dk    rt          j        d           t          |          dk    r7t          |          dk    r$t	          j        |d         
d
  
        S t          |          dk    rt          |          dk    r}}n||z   }d }t          j        ||
d          S )Nc                 <    g | ]}|                     d           |S /endswith.0fs     f/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/huggingface_hub/cli/download.py
<listcomp>z2download.<locals>.run_download.<locals>.<listcomp>~   s'    CCCA1::c??CaCCC    c                 >    g | ]}|                     d            dS )r%   z/**)rstripr(   s     r+   r,   z2download.<locals>.run_download.<locals>.<listcomp>   s+    HHH#333HHHr-   c                 <    g | ]}|                     d           |S r$   r&   r(   s     r+   r,   z2download.<locals>.run_download.<locals>.<listcomp>   s'    NNN1ajjooNQNNNr-   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   r2   r   r   )lenr   warningswarnr   valuer   )filenames_list
subfolderssubfolder_patternsregular_filenamesr3   r4   r   r   r   r   r   r   r   r   r   r   r   r   s         r+   run_downloadzdownload.<locals>.run_downloady   sf   &/&; DCCCC
HHZHHHNNNNN !""Q&&"s7||a'7'7J:a= J J.8mJ J J   "s7||a'7'7[:a= [ [.8m[ [ [    !!A%%"s7||a'7'7_```"s7||a'7'7_```  !!Q&&3/A+B+Ba+G+G"#/!*1-#-#.     !!Q&&3/A+B+Ba+G+G$N%OO /1CCN"O o)+)*#
 
 
 	
r-   resultNc                    t          | t                    rt          j        d|            d S t          | t                    r| g} d | D             }t          j        dt          |           dt          |            dt          t          d |D                                  d           d	 t          | d
           D             }t          j
        |           d S )N
Downloaded)pathc                      g | ]}|j         	|S  )will_downloadr)   rs     r+   r,   z3download.<locals>._print_result.<locals>.<listcomp>   s    >>>qao>>>>r-   z[dry-run] Will download z files (out of z) totalling c              3   $   K   | ]}|j         V  d S N)	file_sizerE   s     r+   	<genexpr>z2download.<locals>._print_result.<locals>.<genexpr>   s$      *N*N11;*N*N*N*N*N*Nr-   .c                 X    g | ]'}|j         |j        rt          |j                  nd d(S )-)filesize)r1   rD   r   rI   )r)   infos     r+   r,   z3download.<locals>._print_result.<locals>.<listcomp>   sQ     
 
 

  8<8JST^444PS 
 
 
r-   c                     | j         S rH   )r1   )xs    r+   <lambda>z1download.<locals>._print_result.<locals>.<lambda>   s    QZ r-   )key)
isinstancestrr   r>   r   textr5   r   sumsortedtable)r>   rD   itemss      r+   _print_resultzdownload.<locals>._print_result   s   fc"" 	J|&1111F fn-- 	XF>>F>>>Ss='9'9 S SFS S&s*N*N*N*N*N'N'NOOS S S	
 	
 	


 

 v+?+?@@@
 
 
 		%r-   )rV   r   list)r   r   r   r   r   r   r   r   r   r   r   r   r   r=   r\   s   ````````````   r+   downloadr^   @   s    rD
#.n1EE D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
LcN2T.5II d    . M,,..!!!!!r-   )!__doc__r6   typingr   typer"huggingface_hub._snapshot_downloadr   huggingface_hub.errorsr   huggingface_hub.file_downloadr   r   huggingface_hub.utilsr   
_cli_utilsr
   r   r   r   r   _outputr   r   DOWNLOAD_EXAMPLESmodelautor]   rV   ArgumentOptionboolintr^   rC   r-   r+   <module>ro      s4   6         @ @ @ @ @ @ + + + + + + I I I I I I I I . . . . . . X X X X X X X X X X X X X X . . . . . . . .     	(.  	 	 	 	 	 	 	
 4 9kV" V"V"S	DQ	
 	
 	
	V" V" V" S	DN	
 	
 	
	V"  S	DC	
 	
 	
	!V", d
1	
 	
 	
	-V"8 d
 M	
 	
 	
	9V"D Y	
 	
 	
	EV"P T	
 	
 	
	QV"\ ]V"^ X	
 	
 	
	_V"j kV"l 
mV" V" V" V" V" V"r-   