Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Created by zd302 at 12/01/2025 | |
| import csv | |
| import json | |
| def convert_json_to_csv(file_json): | |
| with open(file_json) as f: | |
| samples = json.load(f) | |
| new_samples = [] | |
| for i, sample in enumerate(samples): | |
| claim = sample['claim'] | |
| label = sample['pred_label'] | |
| prediction_evidence = "" | |
| for src_qa in sample['evidence']: | |
| prediction_evidence += src_qa["question"] + "\t\t\n" + src_qa["answer"] + "\t\t\n\n" | |
| # | |
| new_samples.append([i, claim, prediction_evidence, label, 'pred']) | |
| with open("submission.csv", mode="w", newline="") as file: | |
| writer = csv.writer(file) | |
| writer.writerow(["id", "claim", "evi", "label", "split"]) # Write header | |
| writer.writerows(new_samples) | |
| print("{} have been converted to .csv".format(file_json)) | |
| def main(): | |
| user_submission_file = "prediction.json" | |
| convert_json_to_csv(user_submission_file) | |
| print("hello") | |
| if __name__ == "__main__": | |
| main() | |