-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_zip.py
51 lines (37 loc) · 1.19 KB
/
prepare_zip.py
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
import os
import argparse
import subprocess
from glob import glob
parser = argparse.ArgumentParser(description="Machine-generated text detection tool")
parser.add_argument(
"--submission-dir",
help="path to submission directory containing the jsonl files for submission",
default="./submission",
)
def validate_dir(dir_path: str):
if not os.path.exists(dir_path):
raise ValueError(
f"Directory {dir_path} does not exist"
)
def get_submission_files(submission_dir: str):
return glob(os.path.join(submission_dir, "*.jsonl"))
def main():
args = parser.parse_args()
validate_dir(args.submission_dir)
submission_files = get_submission_files(args.submission_dir)
if len(submission_files) == 0:
raise ValueError(
f"No submission files found in {args.submission_dir}"
)
try:
subprocess.run(
[
"zip",
f"{args.submission_dir}/predictions.zip",
*submission_files,
]
)
except Exception as ex:
print(f"Failed to zip submission files with error: {ex}")
print(f"Zip saved to {args.submission_dir}/predictions.zip")
main()