Skip to content

Commit d3bfd0a

Browse files
authored
feat: Allow loading of private HF models (#1309)
* feat: add HuggingFace auth token support to model download * Format
1 parent 43d4163 commit d3bfd0a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

faster_whisper/transcribe.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ def __init__(
597597
local_files_only: bool = False,
598598
files: dict = None,
599599
revision: Optional[str] = None,
600+
use_auth_token: Optional[Union[str, bool]] = None,
600601
**model_kwargs,
601602
):
602603
"""Initializes the Whisper model.
@@ -631,6 +632,8 @@ def __init__(
631632
revision:
632633
An optional Git revision id which can be a branch name, a tag, or a
633634
commit hash.
635+
use_auth_token: HuggingFace authentication token or True to use the
636+
token stored by the HuggingFace config folder.
634637
"""
635638
self.logger = get_logger()
636639

@@ -647,6 +650,7 @@ def __init__(
647650
local_files_only=local_files_only,
648651
cache_dir=download_root,
649652
revision=revision,
653+
use_auth_token=use_auth_token,
650654
)
651655

652656
self.model = ctranslate2.models.Whisper(

faster_whisper/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import re
44

5-
from typing import List, Optional
5+
from typing import List, Optional, Union
66

77
import huggingface_hub
88
import requests
@@ -53,6 +53,7 @@ def download_model(
5353
local_files_only: bool = False,
5454
cache_dir: Optional[str] = None,
5555
revision: Optional[str] = None,
56+
use_auth_token: Optional[Union[str, bool]] = None,
5657
):
5758
"""Downloads a CTranslate2 Whisper model from the Hugging Face Hub.
5859
@@ -69,6 +70,8 @@ def download_model(
6970
cache_dir: Path to the folder where cached files are stored.
7071
revision: An optional Git revision id which can be a branch name, a tag, or a
7172
commit hash.
73+
use_auth_token: HuggingFace authentication token or True to use the
74+
token stored by the HuggingFace config folder.
7275
7376
Returns:
7477
The path to the downloaded model.
@@ -108,6 +111,9 @@ def download_model(
108111
if cache_dir is not None:
109112
kwargs["cache_dir"] = cache_dir
110113

114+
if use_auth_token is not None:
115+
kwargs["token"] = use_auth_token
116+
111117
try:
112118
return huggingface_hub.snapshot_download(repo_id, **kwargs)
113119
except (

0 commit comments

Comments
 (0)