ubowang commited on
Commit
e353a82
·
verified ·
1 Parent(s): 003d870

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +111 -0
utils.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+ import csv
4
+ import json
5
+ import os
6
+ import shutil
7
+ from huggingface_hub import Repository
8
+
9
+ HF_TOKEN = os.environ.get("HF_TOKEN")
10
+
11
+ SUBJECTS = ["Biology", "Business", "Chemistry", "Computer Science", "Economics", "Engineering",
12
+ "Health", "History", "Law", "Math", "Philosophy", "Physics", "Psychology", "Other"]
13
+
14
+ MODEL_INFO = [
15
+ "Model (CoT)",
16
+ "Overall",
17
+ "Biology", "Business", "Chemistry", "Computer Science", "Economics", "Engineering",
18
+ "Health", "History", "Law", "Math", "Philosophy", "Physics", "Psychology", "Other"]
19
+
20
+ DATA_TITILE_TYPE = ['markdown', 'number', 'number', 'number', 'number', 'number', 'number',
21
+ 'number', 'number', 'number', 'number', 'number', 'number', 'number',
22
+ 'number', 'number']
23
+
24
+ SUBMISSION_NAME = "mmlu_pro_leaderboard_submission"
25
+ SUBMISSION_URL = os.path.join("https://huggingface.co/datasets/TIGER-Lab/", SUBMISSION_NAME)
26
+ CSV_DIR = "./mmlu_pro_leaderboard_submission/results.csv"
27
+
28
+ COLUMN_NAMES = MODEL_INFO
29
+
30
+ LEADERBORAD_INTRODUCTION = """# MMLU-Pro Leaderboard
31
+ MMLU-Pro dataset, a more robust and challenging massive multi-task understanding dataset tailored to more \
32
+ rigorously benchmark large language models' capabilities. This dataset contains 12K \
33
+ complex questions across various disciplines.
34
+ """
35
+
36
+ TABLE_INTRODUCTION = """
37
+ """
38
+
39
+ LEADERBORAD_INFO = """
40
+ We list the information of the used datasets as follows:<br>
41
+
42
+ """
43
+
44
+ CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
45
+ CITATION_BUTTON_TEXT = r""""""
46
+
47
+ SUBMIT_INTRODUCTION = """# Submit on Science Leaderboard Introduction
48
+
49
+ ## ⚠ Please note that you need to submit the json file with following format:
50
+
51
+ ```json
52
+ {
53
+ "Model": "[NAME]",
54
+ "Repo": "https://huggingface.co/[MODEL_NAME],"
55
+ "Overall": 56.7,
56
+ "Biology": 23.4,
57
+ "Business": 45.6,
58
+ ...,
59
+ "Other: 56.7"
60
+ }
61
+ ```
62
+ After submitting, you can click the "Refresh" button to see the updated leaderboard(it may takes few seconds).
63
+
64
+ """
65
+
66
+
67
+ def get_df():
68
+ repo = Repository(local_dir=SUBMISSION_NAME, clone_from=SUBMISSION_URL, use_auth_token=HF_TOKEN)
69
+ repo.git_pull()
70
+ df = pd.read_csv(CSV_DIR)
71
+ df = df.sort_values(by=['Overall'], ascending=False)
72
+ return df[COLUMN_NAMES]
73
+
74
+
75
+ def add_new_eval(
76
+ input_file,
77
+ ):
78
+ if input_file is None:
79
+ return "Error! Empty file!"
80
+
81
+ upload_data = json.loads(input_file)
82
+ data_row = [f'[{upload_data["Model"]}]({upload_data["Repo"]})', upload_data['Overall']]
83
+ for subject in SUBJECTS:
84
+ data_row += [upload_data[subject]]
85
+
86
+ submission_repo = Repository(local_dir=SUBMISSION_NAME, clone_from=SUBMISSION_URL,
87
+ use_auth_token=HF_TOKEN, repo_type="dataset")
88
+ submission_repo.git_pull()
89
+
90
+ already_submitted = []
91
+ with open(CSV_DIR, mode='r') as file:
92
+ reader = csv.reader(file, delimiter=',')
93
+ for row in reader:
94
+ already_submitted.append(row[0])
95
+
96
+ if data_row[0] not in already_submitted:
97
+ with open(CSV_DIR, mode='a', newline='') as file:
98
+ writer = csv.writer(file)
99
+ writer.writerow(data_row)
100
+
101
+ submission_repo.push_to_hub()
102
+ print('Submission Successful')
103
+ else:
104
+ print('The entry already exists')
105
+
106
+
107
+ def refresh_data():
108
+ return get_df()
109
+
110
+
111
+