
    tnil	              	       d    d Z ddlZddlmZ  e            Z	 d	dededej        edf         fdZdS )
zQUtility function for transforming HuggingFace repositories into model-cache paths    N)RunPodLogger /runpod/cache/{model}/{revision}path_templatehuggingface_repositoryreturnc                    |                      dd          ^}}|s t                              d|  d           dS |                    ||r|d         nd          S )	a  
    Resolves the model-cache path for a HuggingFace model based on its repository string.

    Args:
        huggingface_repository (str): Repository string in format "model_name:revision" or
                                    "org/model_name:revision". If no revision is specified,
                                    "main" is used. For example:
                                    - "runwayml/stable-diffusion-v1-5:experimental"
                                    - "runwayml/stable-diffusion-v1-5" (uses "main" revision)
                                    - "stable-diffusion-v1-5:main"
        path_template (str, optional): Template string for the cache path. Must contain {model}
                                     and {revision} placeholders. Defaults to "/runpod/cache/{model}/{revision}".

    Returns:
        str | None: Absolute path where the model is cached, following the template provided in path_template. Returns None if no model name could be extracted.

    Examples:
        >>> resolve_model_cache_path_from_hugginface_repository("runwayml/stable-diffusion-v1-5:experimental")
        "/runpod/cache/runwayml/stable-diffusion-v1-5/experimental"
        >>> resolve_model_cache_path_from_hugginface_repository("runwayml/stable-diffusion-v1-5")
        "/runpod/cache/runwayml/stable-diffusion-v1-5/main"
        >>> resolve_model_cache_path_from_hugginface_repository(":experimental")
        None
    :   z,Unable to resolve the model-cache path for ""Nr   main)modelrevision)rsplitlogwarnformat)r   r   r   r   s       c/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/runpod/serverless/utils/rp_model_cache.py3resolve_model_cache_path_from_hugginface_repositoryr   	   s    : .44S!<<EH T;QTTT	
 	
 	
 tXAhqkk6         )r   )__doc__typing#runpod.serverless.modules.rp_loggerr   r   strUnionr    r   r   <module>r      s    W W  < < < < < <lnn <& & && \#t)	& & & & & &r   