from huggingface_hub import HfApi from pathlib import Path class HuggingFaceUploader: def __init__(self, hf_token: str, repo_id: str): self.api = HfApi(token=hf_token) self.repo_id = repo_id def upload_folder_with_structure(self, folder_path: str, destination_folder: str): folder_path = Path(folder_path) destination_folder = Path(destination_folder) for local_path in folder_path.rglob('*'): if local_path.is_file(): # Define the path in the repository relative_path = local_path.relative_to(folder_path) path_in_repo = str(destination_folder / relative_path).replace("\\", "/") # Ensuring forward slashes # Upload each file to the correct path in the repository self.api.upload_file( path_or_fileobj=str(local_path), path_in_repo=path_in_repo, repo_id=self.repo_id, repo_type="model" ) print(f"Uploaded '{local_path}' to '{path_in_repo}' in the Hugging Face repository '{self.repo_id}'.") if __name__ == "__main__": hf_token = "" repo_id = "" folder_path = "content" # Set the local folder path destination_folder = "hindi" # Adjust the destination folder structure as needed uploader = HuggingFaceUploader(hf_token, repo_id) uploader.upload_folder_with_structure(folder_path, destination_folder)