o
    8wi                  
   @   sP  d dl Z d dlZd dlZd dlmZmZ d dl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$iZ
d&ee fd'd(Zd)d* Zd+d, Z		-	d?d.ed/ee d0ed1ee fd2d3Z	-	4d@d5ed6ed7ed&efd8d9ZG d:d; d;e	Zd<ee d&ee fd=d>ZdS )A    N)ListOptional)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large-v3-turboz,mobiuslabsgmbh/faster-whisper-large-v3-turboturboreturnc                   C   s   t t S )z&Returns the names of available models.)list_MODELSkeys r   r   Q/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/faster_whisper/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.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_whisper)logging	getLoggerr   r   r   r   
get_logger,   s   
r   F
size_or_id
output_dirlocal_files_only	cache_dirc           	   
   C   s   t d| r	| }nt| }|du rtd| dt f g d}||td}|dur5||d< d|d	< |dur=||d
< z
tj	|fi |W S  tj
jtjjfy{ } z"t }|d|| |d d|d< tj	|fi |W  Y d}~S d}~ww )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.

    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_patterns
tqdm_class	local_dirFlocal_dir_use_symlinksr!   zOAn error occured while synchronizing the model %s from the Hugging Face Hub:
%szETrying to load the model directly from the local cache, if it exists.Tr    )rematchr   get
ValueErrorr   r   disabled_tqdmhuggingface_hubsnapshot_downloadutilsHfHubHTTPErrorrequests
exceptionsConnectionErrorr   warning)	r   r   r    r!   repo_idr"   kwargs	exceptionloggerr   r   r   download_model1   sL   
	r7   .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: 03d)round)r9   r:   r;   millisecondshoursminuteshours_markerr   r   r   format_timestamp~   s   rE   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argsr4   	__class__r   r   rH      s   zdisabled_tqdm.__init__)__name__
__module____qualname__rH   __classcell__r   r   rK   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>rS   )nextrT   )rQ   r   r   r   get_end   s   r[   )NFN)Fr8   )r   r   r&   typingr   r   r+   r/   	tqdm.autor   r   strr   r   r   boolr7   floatrE   r*   dictr[   r   r   r   r   <module>   s    	

O
