WINDop's picture
Upload folder using huggingface_hub
58e7874 verified
import os
import json
from tqdm import tqdm
import os
import ast
def read_json(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
return data
def write_json(file_path, data):
with open(file_path, 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=4)
def read_jsonl(file_path):
data = []
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
json_obj = json.loads(line.strip()) # 每行解析为一个字典
data.append(json_obj)
return data
def write_jsonl(file_path, data):
with open(file_path, 'w', encoding='utf-8') as f:
for item in data:
json.dump(item, f, ensure_ascii=False) # 将每个字典写入文件
f.write('\n') # 每个 JSON 对象占一行
data = read_json('/Users/baixuehai/Downloads/Benchmark/singleturn/singleturn.json')
remove_data = []
for x in data:
type = data[x]["edit_type"]
if type == "remove":
sub_path = data[x]["id"]
img_path = os.path.join('/Users/baixuehai/Downloads/Benchmark/singleturn', sub_path)
if os.path.exists(img_path):
remove_data.append(data[x])
write_jsonl('/Users/baixuehai/Downloads/Benchmark/remove.jsonl', remove_data)