
    iu                        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j0                  dddddddddej2                  fdedeee   dz   ej8                  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 y)&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} | |              y)zDownload files from the Hub.r    c                  n   

ng } | D cg c]  }|j                  d      s| }}|D cg c]  }|j                  d       d }}| D cg c]  }|j                  d      r| }}t        |      dkD  rP&t              dkD  rt        d|d    d|d    d      	&t        	      dkD  rt        d|d    d|d    d      t        |      dkD  rJ#t              dkD  rt	        j
                  d	       	#t        	      dkD  rt	        j
                  d
       t        |      dk(  r0t        |      dk(  r"t        j                  |d   d
      S t        |      dk(  rt        |      dk(  r}	}n||z   }d }t        j                  ||d      S c c}w c c}w c c}w )N/z/**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   )	endswithrstriplenr   warningswarnr   valuer   )filenames_listf
subfolderssubfolder_patternsregular_filenamesr&   r'   r   r   r   r   r   r   r   r   r   r   r   r   s          m/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/huggingface_hub/cli/download.pyrun_downloadzdownload.<locals>.run_downloady   s   &/&; "0CA1::c?aC
C=GH#s3HH(6N1ajjoQNN !"Q&"s7|a'7::a=/ J..8m_LJ  "s7|a'7::a=/ J..8m_<Y[   !A%"s7|a'7_`"s7|a'7_`  !Q&3/A+Ba+G"#//!*1-#-#.   !Q&3/A+Ba+G$N%O /1CCN"O oo)+)*#
 	
e DHNs   F(F(F-F2%F2resultNc                    t        | t              rt        j                  d|        y t        | t              r| g} | D cg c]  }|j
                  s| }}t        j                  dt        |       dt        |        dt        t        d |D                     d       t        | d 	      D cg c]2  }|j                  |j
                  rt        |j                        nd
d4 }}t        j                  |       y c c}w c c}w )N
Downloaded)pathz[dry-run] Will download z files (out of z) totalling c              3   4   K   | ]  }|j                     y wN)	file_size).0rs     r3   	<genexpr>z2download.<locals>._print_result.<locals>.<genexpr>   s     *N11;;*Ns   .c                     | j                   S r:   )r$   )xs    r3   <lambda>z1download.<locals>._print_result.<locals>.<lambda>   s
    QZZ     )key-)filesize)
isinstancestrr   r5   r   will_downloadtextr*   r   sumsortedr$   r;   table)r5   r=   rJ   infoitemss        r3   _print_resultzdownload.<locals>._print_result   s    fc"JJ|&1 fn-XF$*>qaoo>>&s='9&: ;F} %&s*N*N'NOPPQS	
 v+?@

  8<8J8JT^^4PS
 
 			% ?
s    DD27D)rI   r   list)r   r   r   r   r   r   r   r   r   r   r   r   r   r4   rQ   s   ````````````   r3   downloadrS   @   s]    rD
#.n1EE D
 D
 D
LcN2T.5II d . ,.!rC   )!__doc__r+   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autorR   rI   ArgumentOptionboolintrS    rC   r3   <module>re      s1  6    @ + I . X X .   	(..  	 	 	 	 	 	 	
 4 9 9k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"rC   