
    ri                     t   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(Zd) Zd* Z	 	 	 	 	 d:d+ed,ee   d-ed.ee   d/ee   d0eeeef      fd1Z	 	 d;d2ed3ed4ed'efd5Z G d6 d7e	      Zd8ee   d'ee   fd9Zy)<    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.ensmallzSystran/faster-whisper-smallz	medium.enz Systran/faster-whisper-medium.en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-turboturboreturnc                  <    t        t        j                               S )z&Returns the names of available models.)list_MODELSkeys     J/home/jaya/work/projects/FASTER-ASR-WHISPER/faster-asr/faster_asr/utils.pyavailable_modelsr   "   s    r   c                      t         j                  j                  t         j                  j                  t         j                  j	                  t
                    d      S )z)Returns the path to the assets directory.assets)ospathjoindirnameabspath__file__r   r   r   get_assets_pathr   '   s1    77<<(ABHMMr   c                  ,    t        j                  d      S )zReturns the module logger.
faster_asr)logging	getLoggerr   r   r   
get_loggerr#   ,   s    \**r   
size_or_id
output_dirlocal_files_only	cache_dirrevisionuse_auth_tokenc           	      :   t        j                  d|       r| }nIt        j                  |       }|2t	        d| ddj                  t        j                                     g d}||t        |d}|||d<   |||d<   |||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.*/.*zInvalid model size 'z', expected one of: z, )zconfig.jsonzpreprocessor_config.jsonz	model.binztokenizer.jsonzvocabulary.*)r&   allow_patterns
tqdm_classr(   	local_dirr'   token)
rematchr   get
ValueErrorr   r   disabled_tqdmhuggingface_hubsnapshot_download)	r$   r%   r&   r'   r(   r)   repo_idr+   kwargss	            r   download_modelr8   1   s    @ 
xx*%++j)?tyy8: 
N -(#	F ({'{!(w,,W???r   secondsalways_include_hoursdecimal_markerc                     | dk\  sJ d       t        | dz        }|dz  }||dz  z  }|dz  }||dz  z  }|dz  } || dz  z  }|s|dkD  r|ddnd	}| |dd| d| |d
S )Nr   znon-negative timestamp expectedg     @@i6 i`  i  02d: 03d)round)r9   r:   r;   millisecondshoursminuteshours_markers          r   format_timestamprF   v   s    
 a<:::<6)*LI%EEI%%Lf$GGf$$Le#GGeO#L&:eaieC[?RL.QwsmN3CLQTCUVr   c                        e Zd Z fdZ xZS )r3   c                 .    d|d<   t        |   |i | y )NTdisable)super__init__)selfargsr7   	__class__s      r   rK   zdisabled_tqdm.__init__   s     y$)&)r   )__name__
__module____qualname__rK   __classcell__)rN   s   @r   r3   r3      s    * *r   r3   segmentsc                 V    t        d t        |       D        | r| d   d         S d       S )Nc              3   L   K   | ]  }t        |d          D ]	  }|d      yw)wordsendN)reversed).0sws      r   	<genexpr>zget_end.<locals>.<genexpr>   s)     Lax'
7KL!5LLs   "$rW   )nextrX   )rS   s    r   get_endr_      s7    L8H-L'U -1 r   )NFNNN)F.)r!   r   r/   typingr   r   r   r4   	tqdm.autor   r   strr   r   r#   boolr8   floatrF   r3   dictr_   r   r   r   <module>rg      s    	 	 ( (  /
) / )	
 1 + 3 - 1 1 1 . ? A ?  ?!" ?#$ E;'. $s)  
N
+ !%"#"15B@B@B@ B@ }	B@
 smB@ U39-.B@N "'  		.*D *d4j Xe_ r   