Spaces:
Running
Running
| """ 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.") |