File size: 11,585 Bytes
f623499
d868240
f623499
5f54938
 
d868240
 
f623499
5f54938
 
 
 
 
 
 
f623499
5b095ea
87043a7
 
 
 
 
5b095ea
 
 
 
 
 
 
 
 
 
 
5f54938
 
6ddaef7
0ef0084
 
 
 
9c5799a
 
 
 
 
 
 
 
18faeea
5f54938
 
 
 
 
 
 
 
 
 
 
 
 
 
18faeea
 
5f54938
7fde626
 
 
 
 
5f54938
 
5b095ea
 
 
 
9c5799a
5b095ea
 
 
 
2d6b1ed
5b095ea
 
 
9c5799a
8fed222
9c5799a
4a71a01
3118f65
5b095ea
3118f65
 
9c5799a
3118f65
 
 
5b095ea
 
7fde626
5b095ea
 
2d6b1ed
163abc1
 
 
 
 
 
 
 
 
 
 
e614523
 
18faeea
53d87ea
5a53749
9c5799a
7fde626
9c5799a
 
18faeea
 
 
 
 
 
 
c808603
9c5799a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82d7967
4a71a01
82d7967
9c5799a
 
7c06d03
 
c808603
18faeea
163abc1
9c5799a
53d87ea
6a6cccd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53d87ea
73af091
 
6a957b3
b8d53ac
 
 
 
 
 
 
f710121
6a6cccd
aef7c31
e614523
9c5799a
e614523
 
6a6cccd
9c5799a
 
6a6cccd
 
 
9c5799a
 
6a6cccd
 
 
15d0563
 
 
f710121
15d0563
f710121
15d0563
6a957b3
87043a7
5744aec
87043a7
 
 
 
 
 
 
 
 
 
 
 
5744aec
 
 
 
 
 
 
 
 
bd01c27
 
 
 
53d87ea
7fde626
 
8746bb4
bd01c27
 
 
7fde626
619ce72
 
 
7fde626
619ce72
7fde626
 
6552d8e
7fde626
0b2b1a4
7fde626
 
 
 
 
 
 
 
 
 
cf9ab47
 
7fde626
 
 
 
 
 
 
 
6552d8e
7fde626
 
 
6552d8e
 
24382ac
6552d8e
 
 
 
 
24382ac
6552d8e
 
 
 
619ce72
 
 
 
 
 
 
 
 
 
53d87ea
7659936
5f54938
 
7fde626
 
 
7044139
5b095ea
7044139
5f54938
 
82d7967
e614523
5b095ea
87043a7
82d7967
87043a7
5f54938
 
 
 
 
 
687e594
 
4745558
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import gradio as gr
import json
import pandas as pd
from urllib.request import urlopen
from urllib.error import URLError
import re
from datetime import datetime

CITATION_BUTTON_TEXT = r"""@misc{2023opencompass,
    title={OpenCompass: A Universal Evaluation Platform for Foundation Models},
    author={OpenCompass Contributors},
    howpublished = {\url{https://github.com/open-compass/opencompass}},
    year={2023}
}"""
CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"


Predictions_BUTTON_LABEL = "All model predictions are listed here. Access this URL for more details."

Predictions_BUTTON_TEXT = "https://huggingface.co/datasets/opencompass/compass_academic_predictions"


head_style = """
<style>
@media (min-width: 1536px)
{
    .gradio-container {
        min-width: var(--size-full) !important;
    }
}
</style>
"""

DATA_URL_BASE = "http://opencompass.oss-cn-shanghai.aliyuncs.com/dev-assets/hf-research/"

MAIN_LEADERBOARD_DESCRIPTION = """## Compass Academic Leaderboard (Full Version)
The CompassAcademic currently focuses on the comprehensive reasoning abilities of LLMs.
- The datasets selected so far include General Knowledge Reasoning (MMLU-Pro/GPQA-Diamond), Logical Reasoning (BBH), Mathematical Reasoning (MATH-500, AIME), Code Completion (LiveCodeBench, HumanEval), and Instruction Following (IFEval).
- Currently, the evaluation primarily targets chat models, with updates featuring the latest community models at irregular intervals. 
- Prompts and reproduction scripts can be found in [**OpenCompass**: A Toolkit for Evaluation of LLMs](https://github.com/open-compass/opencompass)🏆.

"""
Initial_title = 'Compass Academic Leaderboard'

MODEL_SIZE = ['<10B', '10B-70B', '>70B', 'Unknown']
MODEL_TYPE = ['API', 'OpenSource']



def findfile():
    model_meta_info = 'model-meta-info'
    results_sum = 'hf-academic'

    url = f"{DATA_URL_BASE}{model_meta_info}.json"
    response = urlopen(url)
    model_info = json.loads(response.read().decode('utf-8'))

    url = f"{DATA_URL_BASE}{results_sum}.json"
    response = urlopen(url)
    results = json.loads(response.read().decode('utf-8'))

    return model_info, results

model_info, results = findfile()


def findfile_predictions():
    with open('data/hf-academic-predictions.json', 'r') as file:
        predictions = json.load(file)
    file.close()
    return predictions



def make_results_tab(model_info, results):
    models_list, datasets_list = [], []
    for i in model_info:
        models_list.append(i)
    for i in results.keys():
        datasets_list.append(i)
    
    result_list = []
    index = 1
    for model in models_list:
        this_result = {}
        this_result['Index'] = index
        this_result['Model Name'] = model['display_name']
        this_result['Release Time'] = model['release_time']
        this_result['Parameters'] = model['num_param']
        this_result['OpenSource'] = model['release_type']
        is_all_results_none = 1
        for dataset in datasets_list:
            if results[dataset][model['abbr']] != '-':
                is_all_results_none = 0
            this_result[dataset] = results[dataset][model['abbr']]
        if is_all_results_none == 0:
            result_list.append(this_result)
            index += 1 

    df = pd.DataFrame(result_list)
    return df, models_list, datasets_list



def calculate_column_widths(df):
    column_widths = []
    for column in df.columns:
        header_length = len(str(column))
        max_content_length = df[column].astype(str).map(len).max()
        width = max(header_length * 10, max_content_length * 8) + 20
        width = max(160, min(400, width))
        column_widths.append(width)
    return column_widths



def show_results_tab(df):

    
    def filter_df(model_name, size_ranges, model_types):
        
        newdf, modellist, datasetlist = make_results_tab(model_info, results)

        # search model name
        default_val = 'Input the Model Name'
        if model_name != default_val:
            method_names = [x.split('</a>')[0].split('>')[-1].lower() for x in newdf['Model Name']]
            flag = [model_name.lower() in name for name in method_names]
            newdf['TEMP'] = flag
            newdf = newdf[newdf['TEMP'] == True] 
            newdf.pop('TEMP')
            
        
        # filter size
        if size_ranges:
            def get_size_in_B(param):
                if param == 'N/A':
                    return None
                try:
                    return float(param.replace('B', ''))
                except:
                    return None
            
            newdf['size_in_B'] = newdf['Parameters'].apply(get_size_in_B)
            mask = pd.Series(False, index=newdf.index)
            
            for size_range in size_ranges:
                if size_range == '<10B':
                    mask |= (newdf['size_in_B'] < 10) & (newdf['size_in_B'].notna())
                elif size_range == '10B-70B':
                    mask |= (newdf['size_in_B'] >= 10) & (newdf['size_in_B'] < 70)
                elif size_range == '>70B':
                    mask |= newdf['size_in_B'] >= 70
                elif size_range == 'Unknown':
                    mask |= newdf['size_in_B'].isna()
                    
            newdf = newdf[mask]
            newdf.drop('size_in_B', axis=1, inplace=True)

        # filter opensource
        if model_types:
            type_mask = pd.Series(False, index=newdf.index)
            for model_type in model_types:
                if model_type == 'API':
                    type_mask |= newdf['OpenSource'] == 'API'
                elif model_type == 'OpenSource':
                    type_mask |= newdf['OpenSource'] == 'OpenSource'
            newdf = newdf[type_mask]

        # for i in range(len(newdf)):
        #     newdf.loc[i, 'Index'] = i+1
        
        return newdf

        
    with gr.Row():
        with gr.Column():
            model_name = gr.Textbox(
                value='Input the Model Name', 
                label='Search Model Name',
                interactive=True
            )
        with gr.Column():
            size_filter = gr.CheckboxGroup(
                choices=MODEL_SIZE,
                value=MODEL_SIZE,
                label='Model Size',
                interactive=True,
            )
        with gr.Column():
            type_filter = gr.CheckboxGroup(
                choices=MODEL_TYPE,
                value=MODEL_TYPE,
                label='Model Type',
                interactive=True,
            )

    # with gr.Row():
    #     btn = gr.Button(value="生成表格", interactive=True)
    
    with gr.Column():
        table = gr.DataFrame(
                value=df,
                interactive=False,
                wrap=False,
                column_widths=calculate_column_widths(df),
        )
        
    
    model_name.submit(
        fn=filter_df,
        inputs=[model_name, size_filter, type_filter],
        outputs=table
    )
    size_filter.change(
        fn=filter_df,
        inputs=[model_name, size_filter, type_filter],
        outputs=table,
    )
    type_filter.change(
        fn=filter_df,
        inputs=[model_name, size_filter, type_filter],
        outputs=table,
    )

    # def download_table():
    #     newdf, modellist, datasetlist = make_results_tab(model_info, results)
    #     return newdf.to_csv('df.csv',index=False,sep=',',encoding='utf-8',header=True)
        
    # download_btn = gr.File(visible=True)
    
    # btn.click(fn=download_table, inputs=None, outputs=download_btn)


    with gr.Row():
        with gr.Accordion("Storage of Model Predictions", open=True):
            citation_button = gr.Textbox(
                value=Predictions_BUTTON_TEXT,
                label=Predictions_BUTTON_LABEL,
                elem_id='predictions-button',
                lines=2,  # 增加行数
                max_lines=4,  # 设置最大行数
                show_copy_button=True  # 添加复制按钮使其更方便使用
            )
    
    with gr.Row():
        with gr.Accordion("Citation", open=True):
            citation_button = gr.Textbox(
                value=CITATION_BUTTON_TEXT,
                label=CITATION_BUTTON_LABEL,
                elem_id='citation-button',
                lines=6,  # 增加行数
                max_lines=8,  # 设置最大行数
                show_copy_button=True  # 添加复制按钮使其更方便使用
            )

ERROR_DF = {
    "Type": ['NoneType'],
    "Details": ["Do not find the combination predictions of the two options above."]
}

def show_predictions_tab(model_list, dataset_list, predictions):

    def get_pre_df(model_name, dataset_name):
        if dataset_name not in predictions.keys() or model_name not in predictions[dataset_name].keys():
            return pd.DataFrame(ERROR_DF)

        this_predictions = predictions[dataset_name][model_name]['predictions']
        for i in range(len(this_predictions)):
            this_predictions[i]['origin_prompt'] = str(this_predictions[i]['origin_prompt'])
            this_predictions[i]['gold'] = str(this_predictions[i]['gold'])
        this_predictions = pd.DataFrame(this_predictions)

        return this_predictions


    model_list = [i['abbr'] for i in model_list]
    initial_predictions = get_pre_df('MiniMax-Text-01', 'IFEval')

    with gr.Row():
        with gr.Column():
            model_drop = gr.Dropdown(
                label="Model Name",
                choices=model_list,  # 去重获取主类别
                interactive=True
            )
        with gr.Column():
            dataset_drop = gr.Dropdown(
                label="Dataset Name",
                choices=dataset_list,  # 去重获取主类别
                interactive=True
            )

    with gr.Column():
        table = gr.DataFrame(
                value=initial_predictions,
                interactive=False,
                wrap=False,
                max_height=1000,
                column_widths=calculate_column_widths(initial_predictions),
        )

    model_drop.change(
        fn=get_pre_df,
        inputs=[model_drop, dataset_drop],
        outputs=table,
    )

    dataset_drop.change(
        fn=get_pre_df,
        inputs=[model_drop, dataset_drop],
        outputs=table,
    )


    with gr.Row():
        with gr.Accordion("Citation", open=False):
            citation_button = gr.Textbox(
                value=CITATION_BUTTON_TEXT,
                label=CITATION_BUTTON_LABEL,
                elem_id='citation-button',
                lines=6,  # 增加行数
                max_lines=8,  # 设置最大行数
                show_copy_button=True  # 添加复制按钮使其更方便使用
            )


def create_interface():

    df, model_list, dataset_list = make_results_tab(model_info, results)
    predictions = findfile_predictions()

    with gr.Blocks() as demo:
        # title_comp = gr.Markdown(Initial_title)
        gr.Markdown(MAIN_LEADERBOARD_DESCRIPTION)
        with gr.Tabs(elem_classes='tab-buttons') as tabs:
            with gr.TabItem('Results', elem_id='main', id=0):
                
                show_results_tab(df)

            # with gr.TabItem('Predictions', elem_id='notmain', id=1):
                
            #     show_predictions_tab(model_list, dataset_list, predictions)

    return demo

# model_info, results = findfile()
# breakpoint()

if __name__ == '__main__':
    demo = create_interface()
    demo.queue()
    demo.launch(server_name='0.0.0.0')