File size: 4,070 Bytes
4652a06 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# #!/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",
) |