o
    㥵i                  	   @   s   d dl mZ d dlZd dlmZ d dlZejjZejZdddddZ	d	d
dddZ
ejdddd	ddededefddZ				ddedededefddZdS )    )PathN)ml0.0.10.0.40.0.51.0.0))44khz8kbps)24khzr	   )16khzr	   )r   16kbpszWhttps://github.com/descriptinc/descript-audio-codec/releases/download/0.0.1/weights.pthz]https://github.com/descriptinc/descript-audio-codec/releases/download/0.0.4/weights_24khz.pthz]https://github.com/descriptinc/descript-audio-codec/releases/download/0.0.5/weights_16khz.pthzdhttps://github.com/descriptinc/descript-audio-codec/releases/download/1.0.0/weights_44khz_16kbps.pth))r   r   r	   )r
   r   r	   )r   r   r	   )r   r   r   downloadT)group
positionalwithout_prefixr   r	   latest
model_typemodel_bitratetagc                 C   s   |   } |  }| dv sJ d|dv sJ d|dkr"t| |f }t| ||fd}|du r9td| d|  t d	 d
 d d|  d| d| d }| sw|jj	ddd ddl
}||}|jdkrqtd|j ||j |S )a>  
    Function that downloads the weights file from URL if a local cache is not found.

    Parameters
    ----------
    model_type : str
        The type of model to download. Must be one of "44khz", "24khz", or "16khz". Defaults to "44khz".
    model_bitrate: str
        Bitrate of the model. Must be one of "8kbps", or "16kbps". Defaults to "8kbps".
        Only 44khz model supports 16kbps.
    tag : str
        The tag of the model to download. Defaults to "latest".

    Returns
    -------
    Path
        Directory path required to load model via audiotools.
    )r   r
   r   z6model_type must be one of '44khz', '24khz', or '16khz')r	   r   z1model_bitrate must be one of '8kbps', or '16kbps'r   NzCould not find model with tag z and model type z.cachedescriptdacweights__z.pthT)parentsexist_okr      z1Could not download model. Received response code )lower__MODEL_LATEST_TAGS____MODEL_URLS__get
ValueErrorr   homeexistsparentmkdirrequestsstatus_codewrite_bytescontent)r   r   r   download_link
local_pathr%   response r,   F/home/ubuntu/.local/lib/python3.10/site-packages/dac/utils/__init__.pyr   *   sF   




	load_pathc                 C   s    |s	t | ||d}t|}|S )N)r   r   r   )r   DACload)r   r   r   r.   	generatorr,   r,   r-   
load_modelp   s   
r2   )r   r	   r   )r   r	   r   N)pathlibr   argbind
audiotoolsr   r   modelr/   Acceleratorr   r   bindstrr   r2   r,   r,   r,   r-   <module>   sL    F