
    h0                        S r SSKJr  SSKrSSKrSSKJr  SSKJrJ	r	  SSK
Jr  SSK
Jr   SSKJrJr  SS	KJrJr  S
r\R.                  " \5      rSS jr " S S5      rg! \ a    Sr N,f = f)zThis module provides mixin functionality for the Albumentations library.
It includes utility functions and classes to enhance the core capabilities.
    )annotationsN)Path)AnyCallable)load)save)HfApihf_hub_download)HfHubHTTPErrorSoftTemporaryDirectoryTFc                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )at  Decorator to require huggingface_hub.

This decorator ensures that the `huggingface_hub` package is installed before
executing the decorated function. If the package is not installed, it raises
an ImportError with instructions on how to install it.

Args:
    func (Callable[..., Any]): The function to decorate.

Returns:
    Callable[..., Any]: The decorated function.

c                 \   > [         (       d  [        STR                   S35      eT" U 0 UD6$ )Nz-You need to install `huggingface_hub` to use zJ. Run `pip install huggingface_hub`, or `pip install albumentations[hub]`.)is_huggingface_hub_availableImportError__name__)argskwargsfuncs     W/var/www/fran/franai/venv/lib/python3.13/site-packages/albumentations/core/hub_mixin.pywrapper(require_huggingface_hub.<locals>.wrapper)   s@    ++? O[ [  T$V$$    )r   r   r   r   returnr   )	functoolswraps)r   r   s   ` r   require_huggingface_hubr      s'     __T% % Nr   c            	         \ rS rSrSrSrSrSS jr\SS j5       r	SSS	SS
.             SS jjr
\SSS	S	S	SS	S.                   SS jj5       r\SSSSS	S	S	S.                 SS jj5       rSrg	)HubMixin5   a  Mixin class for Hugging Face Hub integration.

This class provides functionality for saving and loading transforms to/from
the Hugging Face Hub. It enables serialization, deserialization, and sharing
of transform configurations.

Args:
    _CONFIG_KEYS (tuple[str, ...]): Keys used for configuration files.
    _CONFIG_FILE_NAME_TEMPLATE (str): Template for configuration filenames.

)trainevalzalbumentations_config_{}.jsonc                X    [        U5      nUR                  SSS9  X-  n[        XSS9  U$ )a  Save the transform to a specified directory.

Args:
    save_directory (Union[str, Path]):
        Directory where the transform will be saved.
    filename (str):
        Name of the file to save the transform.

Returns:
    Path: Path to the saved transform file.

T)parentsexist_okjsondata_format)r   mkdirsave_transform)selfsave_directoryfilename	save_paths       r   _save_pretrainedHubMixin._save_pretrainedE   s;     n-TD9"-	 	tF;r   c                2    [        U5      U-  n[        USS9$ )a  Load a transform from a specified directory.

Args:
    save_directory (Union[str, Path]):
        Directory from where the transform will be loaded.
    filename (str):
        Name of the file to load the transform from.

Returns:
    A.Compose: Loaded transform.

r%   r&   )r   load_transform)clsr+   r,   r-   s       r   _from_pretrainedHubMixin._from_pretrained\   s      (83	iV<<r   r!   FN)keyallow_custom_keysrepo_idpush_to_hubc               F   U(       d+  X R                   ;  a  [        SU SU R                    S35      eU R                  R                  U5      nU R	                  X5        U(       a<  UR                  5       nUc  [        U5      R                  nU R                  " SXBS.UD6$ g)a  Save the transform and optionally push it to the Huggingface Hub.

Args:
    save_directory (`str` or `Path`):
        Path to directory in which the transform configuration will be saved.
    key (`str`, *optional*):
        Key to identify the configuration type, one of ["train", "eval"]. Defaults to "eval".
    allow_custom_keys (`bool`, *optional*):
        Allow custom keys for the configuration. Defaults to False.
    push_to_hub (`bool`, *optional*, defaults to `False`):
        Whether or not to push your transform to the Huggingface Hub after saving it.
    repo_id (`str`, *optional*):
        ID of your repository on the Hub. Used only if `push_to_hub=True`. Will default to the folder name if
        not provided.
    push_to_hub_kwargs (`dict`, *optional*):
        Additional key word arguments passed along to the [`push_to_hub`] method.

Returns:
    `str` or `None`: url of the commit on the Hub if `push_to_hub=True`, `None` otherwise.

Invalid key: ``. Please use key from zP keys for upload. If you want to use a custom key, set `allow_custom_keys=True`.N)r7   r5    )	_CONFIG_KEYS
ValueError_CONFIG_FILE_NAME_TEMPLATEformatr.   copyr   namer8   )	r*   r+   r5   r6   r7   r8   push_to_hub_kwargsr,   r   s	            r   save_pretrainedHubMixin.save_pretrainedm   s    > !S0A0A%A %<T=N=N<O PQ Q  2299#>n7 ',,.F~.33##GGGGGr   )r5   force_downloadproxiestoken	cache_dirlocal_files_onlyrevisionc                  U R                   R                  U5      n	[        U5      nSn
UR                  5       (       a  XR	                  5        Vs/ s H  oR
                  PM     sn;   a  U R                  XS9n
Of[        (       a3  [        R                  U	 S[        U5      R                  5        S35        O([        U	 S[        U5      R                  5        S35      eU
b  U
$  [        [        U5      R                  SS5      U	UUUUUUS9n[        U5      R                  [        U5      R
                  pU R                  XS9$ s  snf ! [          a  n[!        U	 S	35      UeSnAff = f)
a0  Load a transform from the Huggingface Hub or a local directory.

Args:
    directory_or_repo_id (`str`, `Path`):
        - Either the `repo_id` (string) of a repo with hosted transform on the Hub, e.g. `qubvel-hf/albu`.
        - Or a path to a `directory` containing transform config saved using
            [`~albumentations.Compose.save_pretrained`], e.g., `../path/to/my_directory/`.
    key (`str`, *optional*):
        Key to identify the configuration type, one of ["train", "eval"]. Defaults to "eval".
    revision (`str`, *optional*):
        Revision of the repo on the Hub. Can be a branch name, a git tag or any commit id.
        Defaults to the latest commit on `main` branch.
    force_download (`bool`, *optional*, defaults to `False`):
        Whether to force (re-)downloading the transform configuration files from the Hub, overriding
        the existing cache.
    proxies (`dict[str, str]`, *optional*):
        A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
        'http://hostname': 'foo.bar:4012'}`. The proxies are used on every request.
    token (`str` or `bool`, *optional*):
        The token to use as HTTP bearer authorization for remote files. By default, it will use the token
        cached when running `huggingface-cli login`.
    cache_dir (`str`, `Path`, *optional*):
        Path to the folder where cached files are stored.
    local_files_only (`bool`, *optional*, defaults to `False`):
        If `True`, avoid downloading the file and return the path to the local cached file if it exists.

N)r+   r,   z not found in z, trying to load from the Hub.z8. Please install `huggingface_hub` to load from the Hub.\/)r7   r,   rK   rI   rF   rG   rH   rJ   z! not found on the HuggingFace Hub)r?   r@   r   is_diriterdirrB   r3   r   loggerinforesolveFileNotFoundErrorr
   strreplaceparentr   )r2   directory_or_repo_idr5   rF   rG   rH   rI   rJ   rK   r,   	transformfconfig_file	directoryes                  r   from_pretrainedHubMixin.from_pretrained   s   P 1188=#$89	  &&((,H,H,JK,JqFF,JKK00@T0h	--jt4H/I/Q/Q/S.TTrs (jt4H/I/Q/Q/S.T UN N   	X)0199$D!!#-!1	K #'{"3":":D<M<R<Rx''y'TT7 L:  	X H:-N!OPVWW	Xs   E'A E 
E+E&&E+z%Push transform using huggingface_hub.)r5   r6   commit_messageprivaterH   branch	create_prc          
        U(       d+  X R                   ;  a  [        SU SU R                    S35      e[        US9n	U	R                  XSS9R                  n[        5        n
[        U
5      U-  nU R                  R                  U5      nU R                  XS9nU	R                  UUUUUUS9sS	S	S	5        $ ! , (       d  f       g	= f)
a4  Push the transform to the Huggingface Hub.

Use `allow_patterns` and `ignore_patterns` to precisely filter which files should be pushed to the hub. Use
`delete_patterns` to delete existing remote files in the same commit. See [`upload_folder`] reference for more
details.

Args:
    repo_id (`str`):
        ID of the repository to push to (example: `"username/my-model"`).
    key (`str`, *optional*):
        Key to identify the configuration type, one of ["train", "eval"]. Defaults to "eval".
    allow_custom_keys (`bool`, *optional*):
        Allow custom keys for the configuration. Defaults to False.
    commit_message (`str`, *optional*):
        Message to commit while pushing.
    private (`bool`, *optional*, defaults to `False`):
        Whether the repository created should be private.
    token (`str`, *optional*):
        The token to use as HTTP bearer authorization for remote files. By default, it will use the token
        cached when running `huggingface-cli login`.
    branch (`str`, *optional*):
        The git branch on which to push the transform. This defaults to `"main"`.
    create_pr (`boolean`, *optional*):
        Whether or not to create a Pull Request from `branch` with that commit. Defaults to `False`.

Returns:
    str: The url of the commit of your transform in the given repository.

r:   r;   zV keys for upload. If you still want to use a custom key, set `allow_custom_keys=True`.)rH   T)r7   ra   r$   )r,   )path_or_fileobjpath_in_repor7   r`   rK   rc   N)r=   r>   r	   create_repor7   r   r   r?   r@   r.   upload_file)r*   r7   r5   r6   r`   ra   rH   rb   rc   apitmpr+   r,   r-   s                 r   r8   HubMixin.push_to_hub   s    T !S0A0A%A %<T=N=N<O PW W 
 % //'T/RZZ $%!#Y0N66==cBH--n-PI?? )%-# # 	 &%%s    AB66
Cr<   )r+   
str | Pathr,   rU   r   r   )r+   rl   r,   rU   r   object)r+   rl   r5   rU   r6   boolr7   
str | Noner8   rn   rC   r   r   ro   )r2   r   rX   rl   r5   rU   rF   rn   rG   zdict[str, str] | NonerH   zstr | bool | NonerI   zstr | Path | NonerJ   rn   rK   ro   r   rm   )r7   rU   r5   rU   r6   rn   r`   rU   ra   rn   rH   ro   rb   ro   rc   zbool | Noner   rU   )r   
__module____qualname____firstlineno____doc__r=   r?   r.   classmethodr3   rD   r^   r   r8   __static_attributes__r<   r   r   r   r   5   s   
 %L!@. = =( "'"!/"/ 	/
  / / / "/ 
/b 
 $)-#''+!&#KXKX(KX 	KX
 KX 'KX !KX %KX KX KX 
KX KXZ 
 "'E !!%>> 	>
  > > > > > > 
> >r   r   )r   Callable[..., Any]r   rv   )rs   
__future__r   r   loggingpathlibr   typingr   r   !albumentations.core.serializationr   r1   r   r)   huggingface_hubr	   r
   huggingface_hub.utilsr   r   r   r   	getLoggerr   rQ   r   r   r<   r   r   <module>r      sm    #      D D)6L#'  
		8	$6v vC  )#( )s   A   A+*A+