Datasets:
Download scripts/json2tsv_pair.py from ch-chenyu/All-Angles-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/datasets/ch-chenyu/All-Angles-Bench/resolve/refs%2Fpr%2F3/scripts/json2tsv_pair.py
- Command line
-
hf download hf://datasets/ch-chenyu/All-Angles-Bench@refs/pr/3/scripts/json2tsv_pair.py
-
curl -L -o json2tsv_pair.py https://huggingface.co/datasets/ch-chenyu/All-Angles-Bench/resolve/refs%2Fpr%2F3/scripts/json2tsv_pair.py
2.01 kB
| import json | |
| import csv | |
| import os | |
| import argparse | |
| from pathlib import Path | |
| def process_question(question, A, B, C): | |
| options = [A, B, C] | |
| question_no_options = question.replace(A, "").replace(B, "").replace(C, "") | |
| question_no_options = question_no_options.strip().replace(",", "").strip() | |
| while len(options) < 3: | |
| options.append("") | |
| return question_no_options, options | |
| def main(json_path): | |
| json_path = Path(json_path).resolve() | |
| base_path = json_path.parent # All-Angles-Bench/ | |
| output_dir = base_path / "bench_tsv" | |
| output_dir.mkdir(parents=True, exist_ok=True) | |
| output_path = output_dir / "all_angles_bench_huggingface.tsv" | |
| with open(json_path, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| tsv_data = [] | |
| for entry in data: | |
| folder = entry["folder"] | |
| category = entry["category"] | |
| image_paths = entry["image_path"] | |
| modified_input_images = [str(base_path / p) for p in image_paths] | |
| question = entry["question"] | |
| answer = entry["answer"] | |
| index = entry["index"] | |
| pair_idx = entry["pair_idx"] | |
| A = entry["A"] | |
| B = entry["B"] | |
| C = entry["C"] | |
| question_no_options, options = process_question(question, A, B, C) | |
| tsv_data.append([ | |
| index, folder, category, pair_idx, modified_input_images, | |
| question_no_options | |
| ] + options + [answer]) | |
| with open(output_path, 'w', newline='', encoding='utf-8') as tsv_file: | |
| tsv_writer = csv.writer(tsv_file, delimiter='\t') | |
| tsv_writer.writerow(['index', 'folder', 'category', 'pair_idx', 'image_path', 'question', 'A', 'B', 'C', 'answer']) | |
| tsv_writer.writerows(tsv_data) | |
| print(f"Saved TSV to {output_path}") | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--input', required=True, help='Path to the data.json file (e.g., All-Angles-Bench/data.json)') | |
| args = parser.parse_args() | |
| main(args.input) | |