File size: 922 Bytes
7b76145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json

# Load the converted JSON file
file_path = '/home/yiyangai/stephenqs/datasets/mehrankazemi___re_mi/default/0.0.0/converted_dataset-02.json'

with open(file_path, 'r') as f:
    converted_data = json.load(f)

# Function to update image paths by adding "./images/" before the image filenames
def update_image_paths(data):
    for item in data:
        for conversation in item["conversations"]:
            for content in conversation["content"]:
                if content["image"]:
                    content["image"] = "./images/" + content["image"]
    return data

# Update the image paths
updated_data = update_image_paths(converted_data)

# Save the updated dataset to a new file
updated_file_path = '/home/yiyangai/stephenqs/datasets/mehrankazemi___re_mi/remi_dataset-02.json'
with open(updated_file_path, 'w') as f:
    json.dump(updated_data, f, indent=4)

print("Image paths updated successfully.")