mirror of https://github.com/leafspark/AutoGGUF
feat(models): add HF upload/download class
This commit is contained in:
parent
5d6b6fb67d
commit
fb9addb8c0
|
@ -8,4 +8,6 @@ pynvml~=11.5.3
|
|||
PySide6~=6.7.2
|
||||
flask~=3.0.3
|
||||
python-dotenv~=1.0.1
|
||||
safetensors~=0.4.4
|
||||
safetensors~=0.4.4
|
||||
setuptools~=68.2.0
|
||||
huggingface-hub~=0.24.6
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue