TestFinetunes / jsconv_cpm.py
Desm0nt's picture
Upload jsconv_cpm.py
0380c20 verified
import json
# Путь к файлу JSON
json_file = 'd:/Dropbox/YandexDisk/Dataset/output.json'
# Чтение JSON из файла
with open(json_file, 'r') as f:
data = json.load(f)
# Создание нового списка словарей
new_data = []
for item in data:
conversations = item['conversations']
for conv in conversations:
if conv['from'] == 'user':
query = conv['value']
elif conv['from'] == 'assistant':
response = conv['value']
new_item = {
"query": query,
"response": response,
"images": item['image']
}
new_data.append(new_item)
# Запись нового списка словарей в файл
new_json_file = 'd:/Dropbox/YandexDisk/Dataset/new2_vl_data.json'
with open(new_json_file, 'w') as f:
json.dump(new_data, f, indent=4)