From 53d247b0bba992c65670b85a5054b3780df4c812 Mon Sep 17 00:00:00 2001 From: David Axelrod Date: Tue, 9 May 2023 11:20:22 -0400 Subject: [PATCH] retry model download locally if huggingface throws an http error. (#215) * rety model download locally if huggingface throws an http error. * appease the linter * key error fix * use non internal lib error Co-authored-by: Guillaume Klein --------- Co-authored-by: Guillaume Klein --- faster_whisper/utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/faster_whisper/utils.py b/faster_whisper/utils.py index fe56ab9..bf274aa 100644 --- a/faster_whisper/utils.py +++ b/faster_whisper/utils.py @@ -77,13 +77,20 @@ def download_model( "tokenizer.json", "vocabulary.txt", ] + kwargs["allow_patterns"] = allow_patterns + kwargs["tqdm_class"] = disabled_tqdm - return huggingface_hub.snapshot_download( - repo_id, - allow_patterns=allow_patterns, - tqdm_class=disabled_tqdm, - **kwargs, - ) + try: + return huggingface_hub.snapshot_download( + repo_id, + **kwargs, + ) + except huggingface_hub.utils.HfHubHTTPError: + kwargs["local_files_only"] = True + return huggingface_hub.snapshot_download( + repo_id, + **kwargs, + ) def format_timestamp(