import csv import json # Given mapping mapping = { "humaneval": "humaneval-python", "multiple-lua": "lua", "multiple-java": "java", "multiple-jl": "julia", "multiple-cpp": "cpp", "multiple-rs": "rust", "multiple-rkt": "racket", "multiple-php": "php", "multiple-r": "r", "multiple-js": "javascript", "multiple-d": "d", "multiple-swift": "swift" } BASE_PATH = "/fsx/loubna/projects/bigcode-models-leaderboard" # JSON Data (replace this with your actual loaded JSON) json_path = f"/fsx/loubna/projects/bigcode-models-leaderboard/community_results/codeqwen/Qwen_CodeQwen1.5-7B-Chat_loubnabnl.json" with open(json_path, "r") as f: json_data = json.load(f) parsed_data = json_data['results'] # Create a dictionary with column names as keys and empty values csv_columns = ["Models", "Size (B)", "Throughput (tokens/s)", "Seq_length", "#Languages", "humaneval-python", "java", "javascript", "cpp", "php", "julia", "d", "lua", "r", "racket", "rust", "swift", "Throughput (tokens/s) bs=50", "Peak Memory (MB)"] row_data = {col: '' for col in csv_columns} # Fill the dictionary with data from the JSON for item in parsed_data: csv_col = mapping.get(item['task']) if csv_col: row_data[csv_col] = round(item['pass@1'] * 100, 2) # Set model name under the 'Models' column row_data['Models'] = json_data['meta']['model'] # Write to CSV csv_file = f"{BASE_PATH}/data/raw_scores.csv" with open(csv_file, 'a', newline='') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=row_data.keys()) writer.writerow(row_data) # print last 3 rows in csv with open(csv_file, 'r') as f: lines = f.readlines() for line in lines[-3:]: print(line)