oza75 commited on
Commit
1d280b8
1 Parent(s): fa19b71

add token for downloading gated model.

Browse files
Files changed (1) hide show
  1. tts.py +17 -4
tts.py CHANGED
@@ -15,12 +15,25 @@ from huggingface_hub import hf_hub_download, hf_hub_url
15
  from tqdm import tqdm
16
 
17
 
18
- def download_file_with_progress(url: str, destination: str):
19
  """
20
- Downloads a file from a web URL with a progress bar.
 
 
 
 
21
  """
22
- # Streaming GET request
23
- response = requests.get(url, stream=True)
 
 
 
 
 
 
 
 
 
24
 
25
  # Total size in bytes, set to zero if missing
26
  total_size = int(response.headers.get('content-length', 0))
 
15
  from tqdm import tqdm
16
 
17
 
18
+ def download_file_with_progress(url: str, destination: str, token: str = None):
19
  """
20
+ Downloads a file from a web URL with a progress bar. Supports Hugging Face API token for gated models.
21
+
22
+ :param url: The URL to download from.
23
+ :param destination: The destination file path to save the downloaded file.
24
+ :param token: Hugging Face API token (optional). If not provided, the HF_API_TOKEN from the environment will be used.
25
  """
26
+ # Use the token passed or fetch from environment variable
27
+ if token is None:
28
+ token = os.getenv("HF_TOKEN")
29
+
30
+ # Define headers for the request
31
+ headers = {}
32
+ if token:
33
+ headers['Authorization'] = f'Bearer {token}'
34
+
35
+ # Streaming GET request with headers
36
+ response = requests.get(url, stream=True, headers=headers)
37
 
38
  # Total size in bytes, set to zero if missing
39
  total_size = int(response.headers.get('content-length', 0))