o
    0i,                  #   @   s  d Z ddlZddlZddlZddl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mZmZmZ e	eZg d
Zddejdddddddddddfdedeee ejddf deee ejddf dedededeee e  ej!ddf deee e  ej!ddf deee e  ej!ddf deee ej!ddf deee ej!ddf dee"ej!d df d!eee# ej!d"df d#ed$ee"ej!d%df d&df d'd(Z$dedee dee dee e  d&e%eeee e  f f
d)d*Z&dS )+a  Contains command to upload a repo or file with the CLI.

Usage:
    # Upload file (implicit)
    hf upload my-cool-model ./my-cool-model.safetensors

    # Upload file (explicit)
    hf upload my-cool-model ./my-cool-model.safetensors  model.safetensors

    # Upload directory (implicit). If `my-cool-model/` is a directory it will be uploaded, otherwise an exception is raised.
    hf upload my-cool-model

    # Upload directory (explicit)
    hf upload my-cool-model ./models/my-cool-model .

    # Upload filtered directory (example: tensorboard logs except for the last run)
    hf upload my-cool-model ./model/training /logs --include "*.tfevents.*" --exclude "*20230905*"

    # Upload with wildcard
    hf upload my-cool-model "./model/training/*.safetensors"

    # Upload private dataset
    hf upload Wauplin/my-cool-dataset ./data . --repo-type=dataset --private

    # Upload with token
    hf upload Wauplin/my-cool-model --token=hf_****

    # Sync local Space with Hub (upload new files, delete removed files)
    hf upload Wauplin/space-example --repo-type=space --exclude="/logs/*" --delete="*" --commit-message="Sync local Space with Hub"

    # Schedule commits every 30 minutes
    hf upload Wauplin/my-cool-model --every=30
    N)	AnnotatedOptional)logging)CommitScheduler)RevisionNotFoundError)disable_progress_barsenable_progress_bars   )
PrivateOpt	RepoIdArgRepoTypeRepoTypeOptRevisionOptTokenOpt
get_hf_api)zhf upload my-cool-model . .z:hf upload Wauplin/my-cool-model ./models/model.safetensorszChf upload Wauplin/my-cool-dataset ./data /train --repo-type=datasetzrhf upload Wauplin/my-cool-model ./models . --commit-message="Epoch 34/50" --commit-description="Val accuracy: 68%"z?hf upload bigcode/the-stack . . --repo-type dataset --create-prFrepo_id
local_pathzkLocal path to the file or folder to upload. Wildcard patterns are supported. Defaults to current directory.)helppath_in_repoz\Path of the file or folder in the repo. Defaults to the relative path of the file or folder.	repo_typerevisionprivateincludez'Glob patterns to match files to upload.excludez.Glob patterns to exclude from files to upload.deletezDGlob patterns for file to be deleted from the repo while committing.commit_messagez9The summary / title / first line of the generated commit.commit_descriptionz(The description of the generated commit.	create_prz0Whether to upload content as a new Pull Request.everyzNIf set, a background job is scheduled to create commits every `every` minutes.tokenquietzADisable progress bars and warnings; print only the returned path.returnc                    s   durdkrt jddd|j	t|d t|||d\
dtf 	
fd	d
}|r`t  t  t	d t
|  W d   n1 sVw   Y  t  dS t
|  t  dS )zLUpload a file or a folder to the Hub. Recommended for single-commit uploads.Nr   z --every must be a positive valuer   )Z
param_hint)r   )r   r   r   r   r!   c                     s4  t jr8
d urt
dkrt
trtd d ur)tdkr)td d ur8tdkr8td d urt jr^t j} 	rVd t  n}g}g }n} }
}}d urutdkrutd t
| 	||| d
}td d|j d	 z	 td q ty   |  Y dS w t jst jstd d j	d
	dkrdnd dj}d ursz
 j|	d W n ty   td d  j|	d
d Y nw t jr
 j|	dS  j|	
dS )Nr   z3Ignoring --include since a single file is uploaded.z3Ignoring --exclude since a single file is uploaded.z2Ignoring --delete since a single file is uploaded.z8Ignoring --delete when uploading with scheduled commits.)
folder_pathr   r   r   allow_patternsignore_patternsr   r   r   Zhf_apizScheduling commits every z minutes to .Td   zStopped scheduled commits.zNo such file or directory: 'z'.spaceZgradio)r   r   exist_okr   Z	space_sdk)r   r   r   zBranch 'z' not found. Creating it...)r   r   branchr(   )Zpath_or_fileobjr   r   r   r   r   r   r   )r"   r   r   r   r   r   r   r   r#   r$   Zdelete_patterns)ospathisfilelen
isinstancelistwarningswarndirnameendswithr   printr   timesleepKeyboardInterruptstopisdirFileNotFoundErrorZcreate_repoZ	repo_infor   loggerinfoZcreate_branchZupload_fileZupload_folder)r"   pir#   r$   Z	schedulercreatedapir   r   r   r   r   r   r   r   Zrepo_type_strresolved_includeZresolved_local_pathZresolved_path_in_repor    T/home/kim/smarthome/.venv/lib/python3.10/site-packages/huggingface_hub/cli/upload.py
run_upload   s   




zupload.<locals>.run_uploadignore)typerZBadParametervaluer   _resolve_upload_pathsstrr   r0   catch_warningssimplefilterr4   r   r   Zset_verbosity_warning)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    rD   rB   r?   rC   uploadT   s"   E
,e



rL   c                    s   |  dd }|} d ur2t fdddD r2|d ur td|d ur,|dkr,tdd dgfS  d u rAtj|rA|||fS  d u rPtj|rP|d|fS  d u r\td	| d
|d u rotj ro tj |fS |d u rx d|fS  ||fS )N/c                 3   s    | ]}| v V  qd S )NrB   ).0cr   rB   rC   	<genexpr>  s    z(_resolve_upload_paths.<locals>.<genexpr>)*?[z9Cannot set --include when local_path contains a wildcard.r%   z<Cannot set path_in_repo when local_path contains a wildcard.'zB' is not a local file or folder. Please set local_path explicitly.)splitany
ValueErrorr*   r+   r,   r9   basename)r   r   r   r   	repo_namerA   rB   rQ   rC   rH     s&   



rH   )'__doc__r*   r5   r0   typingr   r   rF   Zhuggingface_hubr   Z!huggingface_hub._commit_schedulerr   Zhuggingface_hub.errorsr   Zhuggingface_hub.utilsr   r   Z
_cli_utilsr
   r   r   r   r   r   r   Z
get_logger__name__r;   ZUPLOAD_EXAMPLESmodelrI   ZArgumentr/   OptionboolfloatrL   tuplerH   rB   rB   rB   rC   <module>   s  "$



#)/5;<B
 B
