File size: 3,901 Bytes
f623499 d868240 f623499 5f54938 d868240 f623499 5f54938 f623499 5b095ea 5f54938 01383fd 5f54938 01383fd 5f54938 5b095ea 163abc1 7659936 5b095ea d487c27 163abc1 7659936 163abc1 7659936 163abc1 7659936 163abc1 d487c27 163abc1 d487c27 163abc1 5b095ea 7659936 5f54938 7044139 5b095ea 7044139 5f54938 5b095ea 7659936 5b095ea 163abc1 5f54938 687e594 |
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 |
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"
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/"
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
MAIN_LEADERBOARD_DESCRIPTION = """## Compass Academic Leaderboard
--WIP--
"""
Initial_title = 'Compass Academic Leaderboard'
def make_results_tab(model_info, results):
models_list, datasets_list = [], []
for i in model_info:
models_list.append([i['abbr'], i['display_name']])
for i in results.keys():
datasets_list.append(i)
result_list = []
index = 0
for model in models_list:
this_result = {}
this_result['Index'] = index
this_result['Model Name'] = model[1]
index += 1
for dataset in datasets_list:
this_result[dataset] = results[dataset][model[0]]
result_list.append(this_result)
df = pd.DataFrame(result_list)
return df
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, model_info, results):
with gr.Row():
model_name = gr.Textbox(value='Input the Model Name (fuzzy)', label='Model Name')
def filter_df(model_name):
df = make_results_tab(model_info, results)
default_val = 'Input the Model Name (fuzzy)'
if model_name != default_val:
method_names = [x.split('</a>')[0].split('>')[-1].lower() for x in df['Model Name']]
flag = [model_name.lower() in name for name in method_names]
df['TEMP'] = flag
df = df[df['TEMP'] == True]
df.pop('TEMP')
return df
model_name.submit(fn=filter_df, inputs=[model_name,], outputs=df)
with gr.Column():
table = gr.DataFrame(
value=df,
interactive=False,
wrap=False,
column_widths=calculate_column_widths(df),
)
def create_interface():
model_info, results = findfile()
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):
df = make_results_tab(model_info, results)
show_results_tab(df, model_info, results)
with gr.TabItem('Predictions', elem_id='notmain', id=1):
# dataset_tab(results, structs[i], dataset)
pass
return demo
# model_info, results = findfile()
# breakpoint()
if __name__ == '__main__':
demo = create_interface()
demo.queue()
demo.launch(server_name='0.0.0.0')
|