Skip to content

Commit

Permalink
support env variable 'HF_TOKEN' to download files from private repos
Browse files Browse the repository at this point in the history
  • Loading branch information
breezedeus committed Sep 21, 2023
1 parent 9c1ad0a commit 8e5dd83
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cnstd/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ def download(url, path=None, overwrite=False, sha1_hash=None):
os.makedirs(dirname)

logger.info('Downloading %s from %s...' % (fname, url))
HF_TOKEN = os.environ.get('HF_TOKEN')
with tempfile.TemporaryDirectory() as tmp_dir:
local_path = hf_hub_download(
repo_id=url["repo_id"],
subfolder=url["subfolder"],
filename=url["filename"],
repo_type="model",
cache_dir=tmp_dir,
token=HF_TOKEN,
)
shutil.copy2(local_path, fname)

Expand Down

0 comments on commit 8e5dd83

Please sign in to comment.