File size: 2,628 Bytes
59b2d96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 subprocess
from huggingface_hub import hf_hub_download


def run_command(command: str, cwd: str = None) -> tuple:
    """Run a shell command in the specified directory and return the output."""
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
    stdout, stderr = process.communicate()
    if process.returncode != 0:
        print(f"Error: {stderr.decode()}")
    else:
        print(f"Output: {stdout.decode()}")
    return stdout, stderr

def download_dataset():
    """Download the dataset."""
    print("Downloading the dataset...")
    repo_id = "valory/autocast"
    base_dir = os.getcwd()
    output_dir = os.path.join(base_dir, "olas-predict-benchmark", "benchmark", "data", "autocast")
    if not os.path.exists(output_dir):
        os.makedirs(output_dir, exist_ok=True)
    filenames = [
        "autocast_questions_filtered.json",
        "autocast_questions_filtered.pkl",
    ]
    for filename in filenames:
        hf_hub_download(repo_id=repo_id, filename=filename, local_dir=output_dir, repo_type="dataset")
    print("Dataset downloaded successfully.")

def start():
    """Start commands."""
    print("Starting commands...")
    base_dir = os.getcwd()
    olas_dir = os.path.join(base_dir, "olas-predict-benchmark")
    mech_dir = os.path.join(olas_dir, "benchmark", "mech")

    commands = [
        ("git submodule init", base_dir),
        ("git submodule update --init --recursive", base_dir),
        ("git submodule update --remote --recursive", base_dir),
        ('git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', olas_dir),
        ("git remote update", olas_dir),
        ("git fetch --all", olas_dir),
    ]

    # Check out the "fix/mech-packages" branch if it exists, otherwise use "main"
    _, stderr = run_command("git show-ref --verify --quiet \"refs/remotes/origin/fix/mech-packages\"", olas_dir)
    if stderr == b'':
        commands.append(("git checkout fix/mech-packages", olas_dir))
        commands.append(("git pull origin fix/mech-packages", olas_dir))
    else:
        print("'fix/mech-packages' branch not found on the remote repository.")
        commands.append(("git checkout main", mech_dir))
        commands.append(("git pull origin main", mech_dir))

    commands.extend([
        ("pip install -e .", os.path.join(olas_dir, "benchmark")),
        ("pip install -e .", mech_dir),
        ("pip install lxml[html_clean]", base_dir)
    ])

    for command, cwd in commands:
        run_command(command, cwd=cwd)

    # Download the dataset
    download_dataset()

start()