merge_fine_grained_report.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import argparse
  2. import json
  3. def merge_fine_grained_report(od_output_file, fine_grained_report_file):
  4. merged_od_output_file = od_output_file.replace('.jsonl', '.merged.jsonl')
  5. merged_report = []
  6. fine_grained_report = json.load(open(fine_grained_report_file))
  7. for line in open(od_output_file):
  8. line = json.loads(line)
  9. instance_id = line['instance_id']
  10. line['fine_grained_report'] = fine_grained_report[instance_id]
  11. merged_report.append(line)
  12. # dump the merged report as a jsonl file
  13. with open(merged_od_output_file, 'w') as f:
  14. for line in merged_report:
  15. f.write(json.dumps(line) + '\n')
  16. print(f'Agent output with report merged created at {merged_od_output_file}')
  17. if __name__ == '__main__':
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument('--od_output_file', help='Path to the OD output file')
  20. parser.add_argument(
  21. '--fine_grained_report_file', help='Path to the fine grained report file'
  22. )
  23. args = parser.parse_args()
  24. merge_fine_grained_report(args.od_output_file, args.fine_grained_report_file)