diff options
| author | vin <git@vineetk.net> | 2025-07-19 03:15:43 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2025-07-19 03:15:43 -0400 |
| commit | 534b7671e2d370bc498fa8d490121434b7a8e17f (patch) | |
| tree | 27faf3704989752296f5a861e5917361d30a7398 /main.py | |
| parent | e4781586464f38f7b3ef1a663b2a50cca6cd2b56 (diff) | |
output data in jsonl
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 10 |
1 files changed, 6 insertions, 4 deletions
| @@ -3,6 +3,7 @@ import re | |||
| 3 | import sys | 3 | import sys |
| 4 | import backoff | 4 | import backoff |
| 5 | import openai | 5 | import openai |
| 6 | import json | ||
| 6 | from datetime import datetime, timedelta | 7 | from datetime import datetime, timedelta |
| 7 | from tqdm import tqdm | 8 | from 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 | ||
| 271 | def main(): | 273 | def 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 | ||
| 283 | if __name__ == "__main__": | 285 | if __name__ == "__main__": |
