thinkersloop commited on
Commit
76e628e
1 Parent(s): 5790bc0

Upload 2 files

Browse files
Files changed (2) hide show
  1. 1.json2string.py +0 -1
  2. 2.listOfjsonl.py +34 -0
1.json2string.py CHANGED
@@ -16,7 +16,6 @@ def json2string(dir_path):
16
  data = json.dumps(data)
17
 
18
  # add double quotes to the string
19
- data = '"' + data + '"'
20
  print(data[:5])
21
 
22
  # write to file
 
16
  data = json.dumps(data)
17
 
18
  # add double quotes to the string
 
19
  print(data[:5])
20
 
21
  # write to file
2.listOfjsonl.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read all txt files and save them in a metadata.jsonl file
2
+
3
+ import os
4
+ import glob
5
+ import argparse
6
+ import json
7
+
8
+ def readTxt(dir_path):
9
+ # read all txt files
10
+ for file in glob.glob(dir_path + '/*.json'):
11
+ # read jsonl file
12
+ with open(file, 'r') as f:
13
+ # print the name of the file
14
+ print(file)
15
+ # read the lines
16
+ lines = f.readlines()
17
+ # create a dictionary
18
+ metadata = {}
19
+ # add the name of the file
20
+ metadata["file_name"] = file.split("/")[-1].split('json')[0][:-1].split("\\")[-1] + '.jpg'
21
+ # add the text
22
+ metadata['ground_truth'] = lines[0].strip()
23
+
24
+ print(metadata)
25
+
26
+ # append the metadata to the metadata.jsonl file on the directory
27
+ with open(os.path.join(dir_path, 'metadata.jsonl'), 'a') as f:
28
+ f.write(json.dumps(metadata) + '\n')
29
+
30
+ if __name__ == '__main__':
31
+ parser = argparse.ArgumentParser()
32
+ parser.add_argument('--dir_path', type=str, default='data')
33
+ args = parser.parse_args()
34
+ readTxt(args.dir_path)