summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2025-07-19 03:15:43 -0400
committervin <git@vineetk.net>2025-07-19 03:15:43 -0400
commit534b7671e2d370bc498fa8d490121434b7a8e17f (patch)
tree27faf3704989752296f5a861e5917361d30a7398
parente4781586464f38f7b3ef1a663b2a50cca6cd2b56 (diff)
output data in jsonl
-rw-r--r--main.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/main.py b/main.py
index af76aca..283ea9a 100644
--- a/main.py
+++ b/main.py
@@ -3,6 +3,7 @@ import re
3import sys 3import sys
4import backoff 4import backoff
5import openai 5import openai
6import json
6from datetime import datetime, timedelta 7from datetime import datetime, timedelta
7from tqdm import tqdm 8from tqdm import tqdm
8 9
@@ -263,21 +264,22 @@ def process_file(input_file: str, output_file: str):
263 if ad_timestamps_str: 264 if ad_timestamps_str:
264 # Split by newlines in case the model returns multiple segments 265 # Split by newlines in case the model returns multiple segments
265 found_timestamps = [ts.strip() for ts in ad_timestamps_str.split('\n') if ts.strip()] 266 found_timestamps = [ts.strip() for ts in ad_timestamps_str.split('\n') if ts.strip()]
266 all_ad_timestamps.extend(found_timestamps) 267 all_ad_timestamps.append({"id": f"{"".join(input_file.split(".")[:-1])}_chunk{i}", f"text": chunk_text_for_api, "target": "\n".join(found_timestamps)})
267 268
268 with open(output_file, "w") as f: 269 with open(output_file, "w") as f:
269 f.write("\n".join(all_ad_timestamps)) 270 for s in all_ad_timestamps:
271 f.write(json.dumps(s) + "\n")
270 272
271def main(): 273def main():
272 paths = sys.argv[1:] 274 paths = sys.argv[1:]
273 for p in paths: 275 for p in paths:
274 out = "".join(p.split(".")[:-1]) + ".gpt" 276 out = "".join(p.split(".")[:-1]) + ".jsonl"
275 if os.path.isfile(out): 277 if os.path.isfile(out):
276 paths.remove(p) 278 paths.remove(p)
277 print(paths) 279 print(paths)
278 280
279 for p in tqdm(paths): 281 for p in tqdm(paths):
280 out = "".join(p.split(".")[:-1]) + ".gpt" 282 out = "".join(p.split(".")[:-1]) + ".jsonl"
281 process_file(p, out) 283 process_file(p, out)
282 284
283if __name__ == "__main__": 285if __name__ == "__main__":