File size: 2,287 Bytes
793caea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import zipfile
from huggingface_hub import HfApi, HfFolder

# Define the root directory containing all datasets
base_root = "data"  # Replace with the directory containing all datasets
dataset_repo = "XavierJiezou/Cloud-Adapter"  # Hugging Face repository name
dataset_names = [
    "hrc_whu",
    "gf12ms_whu_gf1",
    "gf12ms_whu_gf2",
    "cloudsen12_high_l1c",
    "cloudsen12_high_l2a",
    "l8_biome",
]

# Function to create a ZIP file for a dataset directory
def create_zip(dataset_path, output_path):
    """
    Compress a dataset directory into a ZIP file.

    Args:
        dataset_path (str): Path to the dataset directory.
        output_path (str): Path to save the ZIP file.
    """
    with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
        for root, _, files in os.walk(dataset_path):
            for file in files:
                file_path = os.path.join(root, file)
                arcname = os.path.relpath(file_path, dataset_path)
                zipf.write(file_path, arcname)
    print(f"Compressed {dataset_path} into {output_path}")

# Function to upload ZIP files to Hugging Face Hub
def upload_zip_to_hub(dataset_name, zip_path, repo_name):
    """
    Upload a ZIP file to a Hugging Face repository.

    Args:
        dataset_name (str): Name of the dataset (used as a file identifier).
        zip_path (str): Path to the ZIP file.
        repo_name (str): Hugging Face repository name.
    """
    api = HfApi()
    token = HfFolder.get_token()
    file_name = f"{dataset_name}.zip"
    api.upload_file(
        path_or_fileobj=zip_path,
        path_in_repo=file_name,
        repo_id=repo_name,
        repo_type="dataset",
        token=token,
    )
    print(f"Uploaded {file_name} to {repo_name}")

# Main script
if __name__ == "__main__":
    for dataset_name in dataset_names:
        dataset_path = os.path.join(base_root, dataset_name)
        if not os.path.exists(dataset_path):
            print(f"Dataset directory does not exist: {dataset_path}")
            continue
        
        # Create ZIP file
        zip_path = f"{dataset_name}.zip"
        create_zip(dataset_path, zip_path)
        
        # Upload ZIP file to Hugging Face Hub
        upload_zip_to_hub(dataset_name, zip_path, dataset_repo)