-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare_stage1_question.py
37 lines (27 loc) · 1.04 KB
/
prepare_stage1_question.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
import argparse
import os
def process_file(input_filename, output_filename):
with open(input_filename, "r") as file:
lines = file.readlines()
jsonlist = []
for line in lines:
json_data = json.loads(line)
json_data["text"] = (
json_data["text"].split("\n")[0]
+ "\nAccording to the information in the image and the question, \ndetail the following in JSON format:\n1. The text content.\n2. The bounding box of the text in the scene."
)
jsonlist.append(json_data)
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
with open(output_filename, "w") as file:
for item in jsonlist:
json.dump(item, file)
file.write("\n")
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("--input-filename", type=str)
parser.add_argument("--output-filename", type=str)
return parser.parse_args()
if __name__ == "__main__":
args = get_args()
process_file(args.input_filename, args.output_filename)