#!/usr/bin/env python3 import json import os # Load the existing train.json file with open('default/train.json', 'r') as f: data = json.load(f) # Create the directory for the new format os.makedirs('default-fixed', exist_ok=True) # Convert to the correct format (JSONL - one JSON object per line) with open('default-fixed/train.jsonl', 'w') as f: for i in range(len(data['file_name'])): example = { 'file_name': data['file_name'][i], 'file_path': data['file_path'][i], 'file_size': data['file_size'][i], 'content_type': data['content_type'][i] } f.write(json.dumps(example) + '\n') print(f"Converted {len(data['file_name'])} examples to JSONL format") # Update the dataset_infos.json file with open('dataset_infos.json', 'r') as f: dataset_infos = json.load(f) # Rename the default config to default-fixed dataset_infos['default-fixed'] = dataset_infos.pop('default') with open('dataset_infos.json', 'w') as f: json.dump(dataset_infos, f, indent=2) # Update the dataset_dict.json file with open('dataset_dict.json', 'r') as f: dataset_dict = json.load(f) # Rename the default config to default-fixed dataset_dict['default-fixed'] = dataset_dict.pop('default') with open('dataset_dict.json', 'w') as f: json.dump(dataset_dict, f, indent=2) print("Updated dataset configuration files")