o
    rri                     @   s   d Z ddlZddlmZ ddlZddlmZmZ ddl	m
Z
 ddlmZmZmZmZmZmZ ddlmZ eeZd	Zeejd
 Zg dZdZdd Zdd Zdeje e f fddZ!	dde dej"e fddZ#dd Z$dS )zLoading pretrained models.
    N)Path)fatalbold   )HDemucs)
RemoteRepo	LocalRepoModelOnlyRepoBagOnlyRepoAnyModelRepoModelLoadingError)_check_diffqz&https://dl.fbaipublicfiles.com/demucs/remote)drumsbassothervocalshtdemucsc                  C   s   t dtd} | S )N   )channelssources)r   SOURCES)model r   E/home/ubuntu/.local/lib/python3.10/site-packages/demucs/pretrained.pydemucs_unittest   s   r   c                 C   sB   | j dd}|jdddd |jddd d	d
 | jdtdd d S )NF)requiredz-sz--sigzLocally trained XP signature.)helpz-nz--namez8Pretrained model name or signature. Default is htdemucs.)defaultr   z--repoz9Folder containing all pre-trained models for use with -n.)typer   )add_mutually_exclusive_groupadd_argumentr   )parsergroupr   r   r   add_model_flags    s   

r$   returnc                 C   s   d}i }|   dD ]2}| }|drq|dr'|ddd  }q|ddd }||vs5J t| | ||< q|S )	N 
#zroot::r   -r   )	read_textsplitstrip
startswithROOT_URL)remote_file_listrootmodelslinesigr   r   r   _parse_remote_files)   s   

r5   namerepoc              
   C   s   | dkrt  S |du rttd }t|}tt|}n| s&t| d t|}t||}t||}z|	| }W n t
yR } zd|jd v rMt   d}~ww |  |S )z`name` must be a bag of models name or a pretrained signature
    from the remote AWS model repo or the specified local repo if `repo` is not None.
    r   Nz	files.txtz must exist and be a directory.diffqr   )r   r5   REMOTE_ROOTr   r
   is_dirr   r   r   	get_modelImportErrorargsr   eval)r6   r7   r2   
model_repobag_repoany_repor   excr   r   r   r;   9   s*   

r;   c                 C   s.   | j du rt| _ ttdd t| j | jdS )z8
    Load local model package or pre-trained model.
    Nz?Important: the default model was recently changed to `htdemucs`zthe latest Hybrid Transformer Demucs model. In some cases, this model can actually perform worse than previous models. To get back the old default model use `-n mdx_extra_q`.)r6   r7   )r6   DEFAULT_MODELprintr   r;   r7   )r=   r   r   r   get_model_from_argsV   s   
rE   )N)%__doc__loggingpathlibr   typingtpdora.logr   r   hdemucsr   r7   r   r   r	   r
   r   r   statesr   	getLogger__name__loggerr/   __file__parentr9   r   rC   r   r$   Dictstrr5   Optionalr;   rE   r   r   r   r   <module>   s*    
	
