Desm0nt commited on
Commit
0380c20
1 Parent(s): bd52bc9

Upload jsconv_cpm.py

Browse files
Files changed (1) hide show
  1. jsconv_cpm.py +31 -0
jsconv_cpm.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ # Путь к файлу JSON
4
+ json_file = 'd:/Dropbox/YandexDisk/Dataset/output.json'
5
+
6
+ # Чтение JSON из файла
7
+ with open(json_file, 'r') as f:
8
+ data = json.load(f)
9
+
10
+ # Создание нового списка словарей
11
+ new_data = []
12
+
13
+ for item in data:
14
+ conversations = item['conversations']
15
+ for conv in conversations:
16
+ if conv['from'] == 'user':
17
+ query = conv['value']
18
+ elif conv['from'] == 'assistant':
19
+ response = conv['value']
20
+
21
+ new_item = {
22
+ "query": query,
23
+ "response": response,
24
+ "images": item['image']
25
+ }
26
+ new_data.append(new_item)
27
+
28
+ # Запись нового списка словарей в файл
29
+ new_json_file = 'd:/Dropbox/YandexDisk/Dataset/new2_vl_data.json'
30
+ with open(new_json_file, 'w') as f:
31
+ json.dump(new_data, f, indent=4)