o
    di                     @   sj  d dl Z d dlZd dlZd dlmZmZmZ d dlZd dlm	Z	 i dddddd	d
ddddddddddddddddddddddd d!d"d#d$d%d%d&Z
d'ee fd(d)Zd*d+ Zd,d- Z		.			dBd/ed0ee d1ed2ee d3ee d4eeeef  fd5d6Z	.	7dCd8ed9ed:ed'efd;d<ZG d=d> d>e	Zd?ee d'ee fd@dAZdS )D    N)ListOptionalUnion)tqdmztiny.enzSystran/faster-whisper-tiny.entinyzSystran/faster-whisper-tinyzbase.enzSystran/faster-whisper-base.enbasezSystran/faster-whisper-basezsmall.enzSystran/faster-whisper-small.enZsmallzSystran/faster-whisper-smallz	medium.enz Systran/faster-whisper-medium.enZmediumzSystran/faster-whisper-mediumzlarge-v1zSystran/faster-whisper-large-v1zlarge-v2zSystran/faster-whisper-large-v2zlarge-v3zSystran/faster-whisper-large-v3largezdistil-large-v2z&Systran/faster-distil-whisper-large-v2zdistil-medium.enz'Systran/faster-distil-whisper-medium.enzdistil-small.enz&Systran/faster-distil-whisper-small.enzdistil-large-v3z&Systran/faster-distil-whisper-large-v3zdistil-large-v3.5z$distil-whisper/distil-large-v3.5-ct2z,mobiuslabsgmbh/faster-whisper-large-v3-turbo)zlarge-v3-turboZturboreturnc                   C   s   t t S )z&Returns the names of available models.)list_MODELSkeys r   r   4/home/jaya/work/projects/WHISPER/faster_asr/utils.pyavailable_models"   s   r   c                   C   s   t jt jt jtdS )z)Returns the path to the assets directory.Zassets)ospathjoindirnameabspath__file__r   r   r   r   get_assets_path'   s   r   c                   C   s
   t dS )zReturns the module logger.
faster_asr)logging	getLoggerr   r   r   r   
get_logger,   s   
r   F
size_or_id
output_dirlocal_files_only	cache_dirrevisionuse_auth_tokenc           	      C   s   t d| r	| }nt| }|du rtd| dt f g d}||t|d}|dur2||d< |dur:||d< |durB||d	< tj	|fi |S )
a|  Downloads a CTranslate2 Whisper model from the Hugging Face Hub.

    Args:
      size_or_id: Size of the model to download from https://huggingface.co/Systran
        (tiny, tiny.en, base, base.en, small, small.en, distil-small.en, medium, medium.en,
        distil-medium.en, large-v1, large-v2, large-v3, large, distil-large-v2,
        distil-large-v3), or a CTranslate2-converted model ID from the Hugging Face Hub
        (e.g. Systran/faster-whisper-large-v3).
      output_dir: Directory where the model should be saved. If not set, the model is saved in
        the cache directory.
      local_files_only:  If True, avoid downloading the file and return the path to the local
        cached file if it exists.
      cache_dir: Path to the folder where cached files are stored.
      revision: An optional Git revision id which can be a branch name, a tag, or a
            commit hash.
      use_auth_token: HuggingFace authentication token or True to use the
            token stored by the HuggingFace config folder.

    Returns:
      The path to the downloaded model.

    Raises:
      ValueError: if the model size is invalid.
    z.*/.*Nz,Invalid model size '%s', expected one of: %sz, )zconfig.jsonzpreprocessor_config.jsonz	model.binztokenizer.jsonzvocabulary.*)r   allow_patternsZ
tqdm_classr   Z	local_dirr   token)
rematchr   get
ValueErrorr   r   disabled_tqdmhuggingface_hubsnapshot_download)	r   r   r   r   r   r    repo_idr!   kwargsr   r   r   download_model1   s,    
	r,   .secondsalways_include_hoursdecimal_markerc                 C   s   | dksJ dt | d }|d }||d 8 }|d }||d 8 }|d } || d 8 }|s2|dkr8|ddnd	}| |dd| d| |d
S )Nr   znon-negative timestamp expectedg     @@i6 i`  i  02d: Z03d)round)r.   r/   r0   ZmillisecondshoursminutesZhours_markerr   r   r   format_timestampv   s   r7   c                       s   e Zd Z fddZ  ZS )r'   c                    s   d|d< t  j|i | d S )NTdisable)super__init__)selfargsr+   	__class__r   r   r:      s   zdisabled_tqdm.__init__)__name__
__module____qualname__r:   __classcell__r   r   r=   r   r'      s    r'   segmentsc                 C   s*   t dd t| D | r| d d S d S )Nc                 s   s*    | ]}t |d  D ]}|d V  q
qdS )wordsendN)reversed).0swr   r   r   	<genexpr>   s   ( zget_end.<locals>.<genexpr>rE   )nextrF   )rC   r   r   r   get_end   s   rM   )NFNNN)Fr-   )r   r   r#   typingr   r   r   r(   Z	tqdm.autor   r   strr   r   r   boolr,   floatr7   r'   dictrM   r   r   r   r   <module>   s    	

G
