
    -:j)                     |   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
 ddlmZmZ ddlmZmZ d	d
lmZmZmZmZmZ d	dlmZ g dZ	 	 	 	 	 	 	 	 	 	 	 d$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"dfd#Z y)%an  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

    # Download using an hf:// URI (repo type, revision and file path are read from the URI)
    hf download hf://datasets/HuggingFaceM4/FineVision@refs/pr/1/data/train.parquet
    N)	Annotated)	constants)snapshot_download)CLIError)DryRunFileInfohf_hub_download)_format_sizeparse_hf_uri   )	RepoIdArgRepoTypeRepoTypeOptionalOpt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 datasetz6hf download hf://datasets/HuggingFaceH4/ultrachat_200k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                    	
 t        d       j                  t        j                        r|t        d  d      t        d  d      t	               }|j
                  rt        d      |j                  }|r j                  d      r|dz  }|j                  |j                  |j                  c |r6rt        d| d	 d
      |gn|xs t        j                  j                  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.NzCannot use both `--local-dir` and `--cache-dir` at the same time. Use `--cache-dir` (or set the HF_HOME environment variable) for shared caching, or `--local-dir` for a one-off download to a specific directory.z3'--repo-type' cannot be used with an 'hf://' URI ('z').z2'--revision' cannot be used with an 'hf://' URI ('zBBuckets are not supported by `hf download`. Use `hf sync` instead./z.Cannot combine a file path in the hf:// URI ('z') with positional filenames .r   c                  F   

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(  r&t        |      dk(  rt        |d   d
      S t        |      dk(  rt        |      dk(  r}	}n||z   }d }t        ||d      S c c}w c c}w c c}w )Nr!   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 been explicitly set.z>Ignoring `--exclude` since filenames have been 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   r   )filenames_listf
subfolderssubfolder_patternsregular_filenamesr&   r'   r   r   r   r   r   r   r   r   r   repo_type_strr   r   s          ^/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/huggingface_hub/cli/download.pyrun_downloadzdownload.<locals>.run_download   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 #)+)*#
 	
e DHNs   FFFF%Fresultc                    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   r"   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=   rI   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)r   
startswithr   HF_PROTOCOLr
   	is_bucketpath_in_repor(   idtyper   r   modelvaluerH   r   list)r   r   r   r   r   r   r   r   r   r   r   r   urirT   r4   rP   r2   s   `` `````````    @r3   downloadr[   E   st   n !6O
 	
 )//0 PQXPYY\]^^OPWyX[\]]7#==_`` ''G,,S1CL+.66388S\\(D\NRopyozz{|  &I"4hnn;;D
#.n1EE D
 D
 D
LcN2T.5II d . ,.!rB   )NNNNNNNFFN   )!__doc__r+   typingr   typerhuggingface_hubr   "huggingface_hub._snapshot_downloadr   huggingface_hub.errorsr   huggingface_hub.file_downloadr   r   huggingface_hub.utilsr	   r
   
_cli_utilsr   r   r   r   r   _outputr   DOWNLOAD_EXAMPLESrY   rH   ArgumentOptionboolintr[    rB   r3   <module>rm      s  <    % @ + I < W W  " 	%)  	 	 	 	 	 	 	
iy"y"S	DQ	
	y" #y" y" S	DN	
	y"  S	DC	
	!y", d
1	
	-y"8 d
 M	
	9y"D Y	
	Ey"P T	
	Qy"\ ]y"^ X	
	_y"j 
ky"rB   