
    ZiG!                        d Z ddlZddlmZmZmZ ddl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mZmZmZ d	d
lmZmZmZmZ g dZ ej        e          Zdej        ddddddddddfdedeeee                    ej!        d          f         dededeeee                    ej"        d          f         deeee                    ej"        d          f         deee           ej"        d          f         deee           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e$ ej"        d$          f         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OptionalUnion)logging)snapshot_download)CLIError)DryRunFileInfohf_hub_download)_format_sizedisable_progress_barsenable_progress_barstabulate   )	RepoIdArgRepoTypeOptRevisionOptTokenOpt)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quietzWIf True, progress bars are disabled and only the path to the download files is printed.max_workerszEMaximum number of workers to use for downloading files. Default is 8.returnc                 $   	
 dt           t          t          t          t                   f         f	 
fd}dt           t          t          t          t                   f         ddfd}|rpt	                       t          j                    5  t          j        d            | |                       ddd           n# 1 swxY w Y   t                       dS  | |                       t          j
                     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     W/root/projects/butler/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Hr0   c                 <    g | ]}|                     d           |S r'   r)   r+   s     r.   r/   z2download.<locals>.run_download.<locals>.<listcomp>   s'    NNN1ajjooNQNNNr0   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   r5   r"   r   )lenr   warningswarnr
   valuer   )filenames_list
subfolderssubfolder_patternsregular_filenamesr6   r7   r   r   r   r   r   r   r   r"   r   r   r   r    s         r.   run_downloadzdownload.<locals>.run_download   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)+)*#
 
 
 	
r0   resultNc                 $   t          | t                    rt          |            d S t          | t                    r| g} t          dt	          d | D                        dt	          |            dt          t          d | D                                  d           ddg}g }t          | d	 
          D ]9}|                    |j	        |j
        rt          |j                  ndg           :t          t          ||                     d S )Nz[dry-run] Will download c                      g | ]}|j         	|S  )will_downloadr,   rs     r.   r/   z3download.<locals>._print_result.<locals>.<listcomp>   s    +Q+Q+Q!+QA+Q+Q+Qr0   z files (out of z) totalling c              3   2   K   | ]}|j         	|j        V  d S N)rE   	file_sizerF   s     r.   	<genexpr>z2download.<locals>._print_result.<locals>.<genexpr>   sh        M}  M}  ^_  mn  m|  M}  NO  NY  M}  M}  M}  M}  M}  M}r0   .FilezBytes to downloadc                     | j         S rI   )r4   )xs    r.   <lambda>z1download.<locals>._print_result.<locals>.<lambda>   s     r0   )key-)headers)
isinstancestrprintr	   r8   r   sumsortedappendr4   rE   rJ   r   )rA   columnsitemsinfos       r.   _print_resultzdownload.<locals>._print_result   s   fc"" 	&MMMF fn-- 	XF As+Q+Qv+Q+Q+Q'R'R  A  Acfgmcncn  A  A  }I  JM  M}  M}  ci  M}  M}  M}  J}  J}  }~  }~  A  A  A	
 	
 	
 ./-/6';';<<< 	g 	gDLL$-I[)ddn)E)E)Eadeffffhug.../////r0   ignore)r   rU   r	   listr   r9   catch_warningssimplefilterr   r   set_verbosity_warning)r   r   r   r   r   r   r   r   r   r   r    r!   r"   r@   r]   s   ``````````` `  r.   downloadrc   D   s   |D
%^T.5I IJ D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
 D
L0eCn9M$MN 0SW 0 0 0 0"  ($&& 	* 	*!(+++M,,..)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	llnn%%%%'''''s   (CCC)&__doc__r9   typingr   r   r   typerhuggingface_hubr   "huggingface_hub._snapshot_downloadr   huggingface_hub.errorsr   huggingface_hub.file_downloadr	   r
   huggingface_hub.utilsr   r   r   r   
_cli_utilsr   r   r   r   DOWNLOAD_EXAMPLES
get_logger__name__loggermodelr_   rU   ArgumentOptionboolintrc   rD   r0   r.   <module>rv      s   6  - - - - - - - - - -  # # # # # # @ @ @ @ @ @ + + + + + + I I I I I I I I e e e e e e e e e e e e E E E E E E E E E E E E    
	H	%	% 	(.  	 	 	 	 	 	 	 	
u]( ](](cQ	
 	
 	
	]( ]( ]( cN	
 	
 	
	](  cC	
 	
 	
	!](, 1	
 	
 	
	-](8  M	
 	
 	
	9](D Y	
 	
 	
	E](P T	
 	
 	
	Q](\ ]](^ j	
 	
 	
	_](j X	
 	
 	
	k](v 
w]( ]( ]( ]( ]( ](r0   