Skip to content

The agent that grows with you

fix(stt): tolerate a missing huggingface_hub when checking the whisper cache

teknium10bb460b488d2
diff --git a/tests/tools/test_transcription_tools.py b/tests/tools/test_transcription_tools.py
index 8494627d264..2a69c07433e 100644
--- a/tests/tools/test_transcription_tools.py
+++ b/tests/tools/test_transcription_tools.py
@@ -366,9 +366,9 @@ class TestLocalModelLoading:
@pytest.mark.parametrize("download_error", [None, "Got: ConnectTimeout: [Errno 110] Connection timed out"])
def test_cache_miss_falls_back_with_actionable_download_failure(self, download_error):
- from huggingface_hub.errors import LocalEntryNotFoundError
- from tools.transcription_local import _create_whisper_model
+ from tools.transcription_local import _create_whisper_model, _hub_cache_miss_error
+ LocalEntryNotFoundError = _hub_cache_miss_error()
if download_error:
download_error = LocalEntryNotFoundError(download_error)
diff --git a/tools/transcription_local.py b/tools/transcription_local.py
index 7fb966e4c97..db444f83bde 100644
--- a/tools/transcription_local.py
+++ b/tools/transcription_local.py
@@ -120,15 +120,27 @@ def _get_idle_unload_seconds(local_cfg: Dict[str, Any]) -> int:
return max(_config_number(local_cfg, "unload_after_idle_seconds", 0, int), 0)
+def _hub_cache_miss_error() -> type:
+ """Exception faster-whisper raises for a model missing from the local Hub cache.
+
+ ``huggingface_hub`` is an optional dependency (it arrives with faster-whisper); when it is
+ absent, its ``LocalEntryNotFoundError`` base class ``OSError`` is the closest match.
+ """
+ try:
+ from huggingface_hub.errors import LocalEntryNotFoundError
+ except ImportError:
+ return OSError
+ return LocalEntryNotFoundError
+
+
def _create_whisper_model(model_name: str, *, device: str, compute_type: str):
"""Use a cached model without contacting the Hub, downloading only on a cache miss."""
from faster_whisper import WhisperModel
- from huggingface_hub.errors import LocalEntryNotFoundError
kwargs = {"device": device, "compute_type": compute_type}
try:
return WhisperModel(model_name, local_files_only=True, **kwargs)
- except LocalEntryNotFoundError:
+ except _hub_cache_miss_error():
logger.info("faster-whisper model '%s' is not cached; downloading it from the Hugging Face Hub", model_name)
# huggingface_hub surfaces every Hub/network failure as an OSError subclass