Spaces:
Sleeping
Sleeping
File size: 1,109 Bytes
9dd777e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
""" Hugging Face Hub utilities for repository management and file uploads. """
from typing import Optional
import huggingface_hub as hf
from huggingface_hub import repo_info
from huggingface_hub.utils import RepositoryNotFoundError
def repo_exists(repo_id: str, token: Optional[str] = None) -> bool:
""" Checks if a Hugging Face repository exists. """
try:
print(repo_info(repo_id, token=token))
return True
except RepositoryNotFoundError:
return False
def create_hf_repository(**kwargs):
"""Creates a new Hugging Face repository."""
api = hf.HfApi()
return api.create_repo(**kwargs)
def delete_hf_repository(**kwargs):
"""Creates a new Hugging Face repository."""
print(f'Deleting repository {kwargs["repo_id"]}.')
api = hf.HfApi()
return api.delete_repo(**kwargs)
def upload_single_file(**kwargs):
"""Uploads a single file to a Hugging Face repository."""
try:
api = hf.HfApi()
api.upload_file(**kwargs)
except Exception as e:
print(e)
print("WARNING. Best parameters NOT pushed to the hub.") |