-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(models): add HF upload/download class
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from huggingface_hub import HfApi, snapshot_download, hf_hub_url | ||
|
||
|
||
class HFTransfer: | ||
def __init__(self, token) -> None: | ||
self.api = HfApi(token=token) | ||
|
||
def upload_file(self, path, remote_path, repo, repo_type) -> str: | ||
status = self.api.upload_file( | ||
path_or_fileobj=path, | ||
path_in_repo=remote_path, | ||
repo_id=repo, | ||
repo_type=repo_type, | ||
) | ||
return status | ||
|
||
def upload_folder(self, local_folder, remote_path, repo, repo_type) -> str: | ||
status = self.api.upload_folder( | ||
folder_path=local_folder, | ||
path_in_repo=remote_path, | ||
repo_id=repo, | ||
repo_type=repo_type, | ||
) | ||
return status | ||
|
||
def download_repo(self, repo) -> str: | ||
return snapshot_download(repo_id=repo) | ||
|
||
def get_download_link(self, repo, file) -> str: | ||
return hf_hub_url(repo_id=repo, filename=file) |