my-remi-dataset / try.py
StarThomas1002's picture
Upload folder using huggingface_hub
7b76145 verified
raw
history blame contribute delete
922 Bytes
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.")