| # #!/usr/bin/env python3 | |
| # """ | |
| # Script to upload multiple datasets to Hugging Face Hub | |
| # Uploads all datasets except CTCdataset_COCO to ItsMaxNorm/CytoCTCs | |
| # """ | |
| # import os | |
| # import sys | |
| # from pathlib import Path | |
| # from huggingface_hub import HfApi, create_repo, upload_folder | |
| # import argparse | |
| # def upload_datasets_to_hf(base_path, repo_id, token=None): | |
| # """ | |
| # Upload multiple dataset folders to Hugging Face Hub | |
| # Args: | |
| # base_path: Path to the directory containing dataset folders | |
| # repo_id: Hugging Face repository ID (e.g., "ItsMaxNorm/CytoCTCs") | |
| # token: Hugging Face API token (optional if already logged in via CLI) | |
| # """ | |
| # # Initialize the Hugging Face API | |
| # api = HfApi(token=token) | |
| # # Define folders to upload (excluding CTCdataset_COCO) | |
| # folders_to_upload = ["Bacteria", "CTCDataset", "DEEPCELL"] | |
| # # Convert base_path to Path object | |
| # base_path = Path(base_path) | |
| # # Check if base path exists | |
| # if not base_path.exists(): | |
| # print(f"Error: Base path {base_path} does not exist!") | |
| # return | |
| # # Try to create the repository (will not fail if it already exists) | |
| # try: | |
| # create_repo(repo_id, repo_type="dataset", token=token, exist_ok=True) | |
| # print(f"Repository {repo_id} is ready") | |
| # except Exception as e: | |
| # print(f"Note: {e}") | |
| # # Upload each folder | |
| # for folder_name in folders_to_upload: | |
| # folder_path = base_path / folder_name | |
| # if not folder_path.exists(): | |
| # print(f"Warning: Folder {folder_path} does not exist, skipping...") | |
| # continue | |
| # if not folder_path.is_dir(): | |
| # print(f"Warning: {folder_path} is not a directory, skipping...") | |
| # continue | |
| # print(f"\nUploading {folder_name}...") | |
| # try: | |
| # # Upload the folder to a subdirectory in the repo | |
| # upload_folder( | |
| # folder_path=str(folder_path), | |
| # path_in_repo=folder_name, # This creates a subdirectory in the repo | |
| # repo_id=repo_id, | |
| # repo_type="dataset", | |
| # token=token, | |
| # ignore_patterns=["*.pyc", "__pycache__", ".git", ".DS_Store"] | |
| # ) | |
| # print(f"✓ Successfully uploaded {folder_name}") | |
| # except Exception as e: | |
| # print(f"✗ Error uploading {folder_name}: {e}") | |
| # continue | |
| # print(f"\nAll uploads completed! Check your repository at: https://huggingface.co/datasets/{repo_id}") | |
| # def main(): | |
| # parser = argparse.ArgumentParser(description="Upload datasets to Hugging Face Hub") | |
| # parser.add_argument( | |
| # "--path", | |
| # type=str, | |
| # default="/l/users/sahal.mullappilly/Komal/documents/Cell", | |
| # help="Base path containing the dataset folders" | |
| # ) | |
| # parser.add_argument( | |
| # "--repo", | |
| # type=str, | |
| # default="ItsMaxNorm/CytoCTCs", | |
| # help="Hugging Face repository ID" | |
| # ) | |
| # parser.add_argument( | |
| # "--token", | |
| # type=str, | |
| # default=None, | |
| # help="Hugging Face API token (optional if logged in via CLI)" | |
| # ) | |
| # args = parser.parse_args() | |
| # # If no token provided, try to get it from environment variable | |
| # if args.token is None: | |
| # args.token = os.environ.get("HF_TOKEN") | |
| # print(f"Starting upload process...") | |
| # print(f"Base path: {args.path}") | |
| # print(f"Repository: {args.repo}") | |
| # print(f"Folders to upload: Bacteria, CTCDataset, DEEPCELL, finetuning") | |
| # print(f"Excluding: CTCdataset_COCO") | |
| # print("-" * 50) | |
| # upload_datasets_to_hf(args.path, args.repo, args.token) | |
| if __name__ == "__main__": | |
| from huggingface_hub import HfApi | |
| api = HfApi() | |
| api.upload_large_folder( | |
| folder_path="/l/users/sahal.mullappilly/Komal/documents/Cell", | |
| repo_id="ItsMaxNorm/CytoCTCs", | |
| repo_type="dataset", | |
| ) |