StarThomas1002
commited on
Upload replace.py with huggingface_hub
Browse files- replace.py +22 -0
replace.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
# 输入文件路径
|
4 |
+
input_file_path = '/home/yiyangai/stephenqs/datasets/VIST/sis/test.story-in-sequence.json'
|
5 |
+
# 输出文件路径
|
6 |
+
output_file_path = '/home/yiyangai/stephenqs/datasets/VIST/sis/updated_test.story-in-sequence.json'
|
7 |
+
|
8 |
+
# 读取 JSON 文件
|
9 |
+
with open(input_file_path, 'r') as file:
|
10 |
+
data = json.load(file)
|
11 |
+
|
12 |
+
# 遍历 images 列表
|
13 |
+
for image in data['images']:
|
14 |
+
image_id = image['id'] # 获取 id 的值
|
15 |
+
# 替换 url_o 的值
|
16 |
+
image['url_o'] = f"./../test/{image_id}.jpg"
|
17 |
+
|
18 |
+
# 将更新后的数据写入新文件
|
19 |
+
with open(output_file_path, 'w') as file:
|
20 |
+
json.dump(data, file, indent=4)
|
21 |
+
|
22 |
+
print(f"URL 替换已完成,并保存到: {output_file_path}")
|