from huggingface_hub import HfApi, create_repo import os class HFUploader: def __init__(self): self.hf_api = HfApi() self.repo_id = "HUGGINGFACE_REPO_ID" self._ensure_repo_exists() def _ensure_repo_exists(self): try: self.hf_api.repo_info(repo_id=self.repo_id, repo_type="dataset") except Exception: create_repo(self.repo_id, private=False, repo_type="dataset", token=os.getenv("HUGGINGFACE_TOKEN")) def ensure_folder_structure(self, sport_id: str): paths = [ f"{sport_id}/raw", f"{sport_id}/compressed" ] for path in paths: try: self.hf_api.upload_file( path_or_fileobj="", path_in_repo=f"{path}/.gitkeep", repo_id=self.repo_id, repo_type="dataset", token=os.getenv("HUGGINGFACE_TOKEN") ) except Exception: pass def upload_video(self, file_path: str, destination_path: str): self.hf_api.upload_file( path_or_fileobj=file_path, path_in_repo=destination_path, repo_id=self.repo_id, repo_type="dataset", token=os.getenv("HUGGINGFACE_TOKEN") ) return f"https://huggingface.co/datasets/{self.repo_id}/raw/main/{destination_path}"