import json import argparse import os if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--dataset", type=str, required=True) parser.add_argument("--training-format", type=str, required=True) args = parser.parse_args() # Load the input JSON file with open("data/{s}/train.json".format(s=args.dataset), "r") as f: data = json.load(f) jsonl_data = [] # Convert the input JSON to JSONL format for key, value in enumerate(data): if args.dataset == "something": input_path = value["input"] output_path = value["output"] file_check = os.path.exists(input_path) and os.path.exists(output_path) else: file_check = True if file_check: if args.training_format == "sft-editing": 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": "" } ] } elif args.training_format == "sft-action-verbolise": entry = { "id": f"{int(key):012d}", "images": ["AURORA/"+value["input"], "AURORA/"+value["output"]], "conversations": [ { "from": "human", "value": f"You are given two sequential observations in the form of images.\n\nPast observations:\n\nNext observation after taking the action:\n\n\nYour task is to infer and describe the most likely action that occurred between the past and next observations. The action should be described concisely in natural language, capturing key changes that explain the state transition." }, { "from": "gpt", "value": "The most likely action that occurred between the observations is: "+value['instruction'] } ] } else: raise NotImplementedError jsonl_data.append(entry) else: continue # Save to a JSONL file with open("data/{s}/{f}-train.jsonl".format(s=args.dataset, f=args.training_format), "w") as f: for line in jsonl_data: f.write(json.dumps(line) + "\n")