File size: 1,535 Bytes
93cac16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import glob
import tarfile

def extract_archives(shards_dir: str, target_base: str):
    """
    Extract all .tar.gz archives in `shards_dir` into `target_base`, preserving internal paths.

    Args:
        shards_dir (str): Directory containing .tar.gz files (e.g., "inputs" or "outputs").
        target_base (str): Base directory to extract archives into (e.g., "data").
    """
    if not os.path.isdir(shards_dir):
        print(f"Directory '{shards_dir}' not found. Skipping.")
        return
    
    archives = sorted(glob.glob(os.path.join(shards_dir, "*.tar.gz")))
    if not archives:
        print(f"No archives found in '{shards_dir}'.")
        return

    for arch in archives:
        print(f"Extracting '{arch}' into '{target_base}'...")
        with tarfile.open(arch, 'r:gz') as tar:
            tar.extractall(path=target_base)
    print(f"Done extracting archives from '{shards_dir}'.\n")


def main():
    """
    Download and extract CausalDynamics data from HuggingFace
    
    Example usage:
        python process_causaldynamics.py
    """

    # Base directory for downloaded shards
    base_dir = os.getcwd()
    # Directory to place extracted files
    target_base = os.path.join(base_dir, "data")
    os.makedirs(target_base, exist_ok=True)

    # Extract data tarballs (inputs)
    extract_archives(os.path.join(base_dir, "inputs"), target_base)
    # Extract eval tarballs (outputs)
    extract_archives(os.path.join(base_dir, "outputs"), target_base)

if __name__ == "__main__":
    main()