o
    siQ                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	Z	d dl
mZ d dlZe de jdZdd	d
dddddddddddZdd eD Zdd Zdd Zdd Ze ejdfdeeee f fd d!ZdS )"    N)	lru_cache)sha256)UnionDictList)hubASTEROID_CACHEz~/.cache/torch/asteroidz<https://zenodo.org/record/3862942/files/model.pth?download=1z<https://zenodo.org/record/3873670/files/model.pth?download=1z<https://zenodo.org/record/3903795/files/model.pth?download=1z<https://zenodo.org/record/3873572/files/model.pth?download=1z<https://zenodo.org/record/3874420/files/model.pth?download=1z<https://zenodo.org/record/3970768/files/model.pth?download=1z<https://zenodo.org/record/3994193/files/model.pth?download=1z<https://zenodo.org/record/3997047/files/model.pth?download=1z<https://zenodo.org/record/3998647/files/model.pth?download=1z<https://zenodo.org/record/4020529/files/model.pth?download=1z<https://zenodo.org/record/4301955/files/model.pth?download=1zFhttps://zenodo.org/record/4704231/files/pretrained_xumx.pth?download=1zGhttps://zenodo.org/record/7128659/files/pretrained_xumxl.pth?download=1)z#mpariente/ConvTasNet_WHAM!_sepcleanz$mpariente/DPRNNTasNet_WHAM!_sepcleanz+mpariente/DPRNNTasNet(ks=16)_WHAM!_sepcleanz'Cosentino/ConvTasNet_LibriMix_sep_cleanz'Cosentino/ConvTasNet_LibriMix_sep_noisyz(brijmohan/ConvTasNet_Libri1Mix_enhsinglez'groadabike/ConvTasNet_DAMP-VSEP_enhbothz5popcornell/DeMask_Surgical_mask_speech_enhancement_v1z)popcornell/DPRNNTasNet_WHAM_enhancesinglez-tmirzaev-dotcom/ConvTasNet_Libri3Mix_sepnoisyz(mhu-coder/ConvTasNet_Libri1Mix_enhsinglez&r-sawata/XUMX_MUSDB18_music_separationz'r-sawata/XUMXL_MUSDB18_music_separationc                 C   s   i | ]}|d |vrdndqS )DeMaskg     @@g     @@ ).0kr
   r
   L/home/ubuntu/.local/lib/python3.10/site-packages/asteroid/utils/hub_utils.py
<dictcomp>   s    r   c                 C   s  ddl m} tj| r| S | tjr| ttjd } | dr%| }n-| t	v r.t	|  }n$d| v rA| 
dd }| 
dd }n| }d}tj|tjt |d|d	S t|}tjt |}tj|d
}tj|dd tj|szt|| |S td|  d |S )a5  Download from URL and cache the result in ASTEROID_CACHE.

    Args:
        filename_or_url (str): Name of a model as named on the Zenodo Community
            page (ex: ``"mpariente/ConvTasNet_WHAM!_sepclean"``), or model id from
            the Hugging Face model hub (ex: ``"julien-c/DPRNNTasNet-ks16_WHAM_sepclean"``),
            or a URL to a model file (ex: ``"https://zenodo.org/.../model.pth"``), or a filename
            that exists locally (ex: ``"local/tmp_model.pth"``)

    Returns:
        str, normalized path to the downloaded (or not) model
       )__version__N)zhttp://zhttps://@r      asteroid)repo_idfilename	cache_dirrevisionlibrary_namelibrary_versionz	model.pthTexist_okzUsing cached model ``) r   ospathisfile
startswithhuggingface_hubHUGGINGFACE_CO_URL_HOMElenMODELS_URLS_HASHTABLEsplithf_hub_downloadPYTORCH_WEIGHTS_NAMEget_cache_dirurl_to_filenamejoinmakedirsr   download_url_to_fileprint)filename_or_urlasteroid_versionurlmodel_idr   cached_filename
cached_dircached_pathr
   r
   r   cached_download"   s>   

	r6   c                 C   s   |  d}t|}| }|S )z-Consistently convert ``url`` into a filename.zutf-8)encoder   	hexdigest)r1   _bytes_hashr   r
   r
   r   r*   [   s   
r*   c                   C   s   t jtdd tS )NTr   )r   r,   	CACHE_DIRr
   r
   r
   r   r)   c   s   r)   Freturnc                 C   s:   d | }t|}|  | }|rdd |D S |S )zLGet the public list of all the models on huggingface with an 'asteroid' tag.z&{}api/models?full=true&filter=asteroidc                 S   s   g | ]}|d  qS )modelIdr
   )r   xr
   r
   r   
<listcomp>r   s    zmodel_list.<locals>.<listcomp>)formatrequestsgetraise_for_statusjson)endpoint	name_onlyr   r
all_modelsr
   r
   r   
model_listh   s   

rI   )r   	functoolsr   hashlibr   typingr   r   r   rA   torchr   r"   getenvr   
expanduserr;   r%   SR_HASHTABLEr6   r*   r)   r#   strrI   r
   r
   r
   r   <module>   sD    
9