import json import os # Load the input JSON file with open("train.json", "r") as f: data = json.load(f) jsonl_data = [] print("Before processing:", len(data)) # Convert the input JSON to JSONL format for key, value in enumerate(data): input_path = '/'.join(value["input"].split('/')[2:]) output_path = '/'.join(value["output"].split('/')[2:]) if os.path.exists(input_path) and os.path.exists(output_path): entry = { "id": f"{int(key):012d}", "images": ["AURORA/"+value["input"], "AURORA/"+value["output"]], "conversations": [ { "from": "human", "value": f"\nEditing the given image according to the following prompt: {value['instruction']}" }, { "from": "gpt", "value": "" } ] } jsonl_data.append(entry) else: continue # Save to a JSONL file with open("train.jsonl", "w") as f: for line in jsonl_data: f.write(json.dumps(line) + "\n") print("Final data size:", len(jsonl_data))