Expose function available_models (#475)

* Expose function available_models

* Add test case
This commit is contained in:
Guillaume Klein
2023-09-14 17:17:01 +02:00
committed by GitHub
parent a49097e655
commit 0048844f54
3 changed files with 15 additions and 3 deletions

View File

@@ -1,9 +1,10 @@
from faster_whisper.audio import decode_audio from faster_whisper.audio import decode_audio
from faster_whisper.transcribe import WhisperModel from faster_whisper.transcribe import WhisperModel
from faster_whisper.utils import download_model, format_timestamp from faster_whisper.utils import available_models, download_model, format_timestamp
from faster_whisper.version import __version__ from faster_whisper.version import __version__
__all__ = [ __all__ = [
"available_models",
"decode_audio", "decode_audio",
"WhisperModel", "WhisperModel",
"download_model", "download_model",

View File

@@ -2,7 +2,7 @@ import logging
import os import os
import re import re
from typing import Optional from typing import List, Optional
import huggingface_hub import huggingface_hub
import requests import requests
@@ -24,6 +24,11 @@ _MODELS = {
} }
def available_models() -> List[str]:
"""Returns the names of available models."""
return list(_MODELS.keys())
def get_assets_path(): def get_assets_path():
"""Returns the path to the assets directory.""" """Returns the path to the assets directory."""
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets") return os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")

View File

@@ -1,6 +1,12 @@
import os import os
from faster_whisper import download_model from faster_whisper import available_models, download_model
def test_available_models():
models = available_models()
assert isinstance(models, list)
assert "tiny" in models
def test_download_model(tmpdir): def test_download_model(tmpdir):