Spaces:
Sleeping
Sleeping
update
Browse files- app.py +62 -66
- requirements.txt +2 -1
app.py
CHANGED
@@ -2,15 +2,6 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
from functools import reduce
|
4 |
|
5 |
-
import pandas as pd
|
6 |
-
import gradio as gr
|
7 |
-
from collections import defaultdict
|
8 |
-
import os
|
9 |
-
from yaml import safe_load
|
10 |
-
|
11 |
-
from collections import defaultdict
|
12 |
-
import os
|
13 |
-
|
14 |
CONFIG = safe_load(open("config.yaml"))
|
15 |
|
16 |
data = defaultdict(dict)
|
@@ -19,12 +10,12 @@ data = defaultdict(dict)
|
|
19 |
for settings in CONFIG['settings']:
|
20 |
for type in CONFIG['types']:
|
21 |
# 根据配置文件中的路径读取数据
|
22 |
-
data[settings][type] = pd.read_excel('data/'+CONFIG["settings_mapping"][settings] + f"-{type}.xlsx")
|
23 |
|
24 |
-
#
|
25 |
for settings in CONFIG['settings']:
|
26 |
for type in CONFIG['types']:
|
27 |
-
data[settings][type]["Average"] = data[settings][type].iloc[:,1:].mean(axis=1)
|
28 |
# 添加rank列
|
29 |
for settings in CONFIG['settings']:
|
30 |
for type in CONFIG['types']:
|
@@ -36,6 +27,11 @@ for settings in CONFIG['settings']:
|
|
36 |
cols = cols[-1:] + cols[:-1]
|
37 |
data[settings][type] = data[settings][type][cols]
|
38 |
|
|
|
|
|
|
|
|
|
|
|
39 |
css = """
|
40 |
table > thead {
|
41 |
white-space: normal;
|
@@ -59,7 +55,6 @@ table > tbody > tr > td:nth-child(2) {
|
|
59 |
width: auto;
|
60 |
}
|
61 |
|
62 |
-
|
63 |
/* 紧凑显示其他列 */
|
64 |
table > tbody > tr > td:not(:nth-child(2)) {
|
65 |
white-space: normal;
|
@@ -67,15 +62,6 @@ table > tbody > tr > td:not(:nth-child(2)) {
|
|
67 |
}
|
68 |
"""
|
69 |
|
70 |
-
"""
|
71 |
-
Each inner tab can have the following keys:
|
72 |
-
- language: The language of the leaderboard
|
73 |
-
- language_long: [optional] The long form of the language
|
74 |
-
- description: The description of the leaderboard
|
75 |
-
- credits: [optional] The credits for the leaderboard
|
76 |
-
- desc: [optional] The description of the leaderboard
|
77 |
-
- data: The data for the leaderboard
|
78 |
-
"""
|
79 |
# 定义模型类型和大小(占位符)
|
80 |
MODEL_TYPES = [
|
81 |
"Open",
|
@@ -95,7 +81,7 @@ NUMERIC_INTERVALS = {
|
|
95 |
">1B": pd.Interval(1000, 1_000_000, closed="right"),
|
96 |
}
|
97 |
|
98 |
-
|
99 |
def filter_data(search_query, model_types, model_sizes):
|
100 |
output_df = df.copy()
|
101 |
|
@@ -117,52 +103,62 @@ def filter_data(search_query, model_types, model_sizes):
|
|
117 |
# Placeholder logic for model size filtering
|
118 |
pass
|
119 |
|
120 |
-
return output_df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
# Create the Gradio interface
|
123 |
with gr.Blocks(css=css) as demo:
|
124 |
-
gr.
|
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 |
-
gr.
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
# Initially display the entire DataFrame
|
161 |
-
# vis = gr.DataFrame(df)
|
162 |
-
|
163 |
-
# submit_button.click(fn=filter_data, inputs=[search_box, model_type_checkbox_group, model_size_checkbox_group], outputs=result_table)
|
164 |
-
|
165 |
-
# Display the initial DataFrame
|
166 |
|
167 |
demo.launch()
|
168 |
|
|
|
2 |
import pandas as pd
|
3 |
from functools import reduce
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
CONFIG = safe_load(open("config.yaml"))
|
6 |
|
7 |
data = defaultdict(dict)
|
|
|
10 |
for settings in CONFIG['settings']:
|
11 |
for type in CONFIG['types']:
|
12 |
# 根据配置文件中的路径读取数据
|
13 |
+
data[settings][type] = pd.read_excel('data/' + CONFIG["settings_mapping"][settings] + f"-{type}.xlsx")
|
14 |
|
15 |
+
# 添加平均分列并四舍五入到小数点后两位
|
16 |
for settings in CONFIG['settings']:
|
17 |
for type in CONFIG['types']:
|
18 |
+
data[settings][type]["Average"] = data[settings][type].iloc[:,1:].mean(axis=1).round(2)
|
19 |
# 添加rank列
|
20 |
for settings in CONFIG['settings']:
|
21 |
for type in CONFIG['types']:
|
|
|
27 |
cols = cols[-1:] + cols[:-1]
|
28 |
data[settings][type] = data[settings][type][cols]
|
29 |
|
30 |
+
# 四舍五入整个DataFrame到小数点后两位
|
31 |
+
for settings in CONFIG['settings']:
|
32 |
+
for type in CONFIG['types']:
|
33 |
+
data[settings][type] = data[settings][type].round(2)
|
34 |
+
|
35 |
css = """
|
36 |
table > thead {
|
37 |
white-space: normal;
|
|
|
55 |
width: auto;
|
56 |
}
|
57 |
|
|
|
58 |
/* 紧凑显示其他列 */
|
59 |
table > tbody > tr > td:not(:nth-child(2)) {
|
60 |
white-space: normal;
|
|
|
62 |
}
|
63 |
"""
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
# 定义模型类型和大小(占位符)
|
66 |
MODEL_TYPES = [
|
67 |
"Open",
|
|
|
81 |
">1B": pd.Interval(1000, 1_000_000, closed="right"),
|
82 |
}
|
83 |
|
84 |
+
# 定义过滤函数
|
85 |
def filter_data(search_query, model_types, model_sizes):
|
86 |
output_df = df.copy()
|
87 |
|
|
|
103 |
# Placeholder logic for model size filtering
|
104 |
pass
|
105 |
|
106 |
+
return output_df.round(2)
|
107 |
+
|
108 |
+
# 创建示例 DataFrame (假设 df 是一个示例 DataFrame)
|
109 |
+
df = pd.DataFrame({
|
110 |
+
'Model': ['ModelA', 'ModelB'],
|
111 |
+
'Metric1': [0.123456, 0.789123],
|
112 |
+
'Metric2': [0.654321, 0.321654],
|
113 |
+
'Average': [0.0, 0.0],
|
114 |
+
'Rank': [0, 0]
|
115 |
+
})
|
116 |
+
|
117 |
+
# 计算 Average 和 Rank 并四舍五入
|
118 |
+
df['Average'] = df.iloc[:, 1:-1].mean(axis=1).round(2)
|
119 |
+
df['Rank'] = df['Average'].rank(ascending=False, method='min').astype(int)
|
120 |
+
cols = df.columns.tolist()
|
121 |
+
cols = cols[-1:] + cols[:-1]
|
122 |
+
df = df[cols]
|
123 |
|
124 |
# Create the Gradio interface
|
125 |
with gr.Blocks(css=css) as demo:
|
126 |
+
with gr.Box(className="container"):
|
127 |
+
gr.Markdown("# Model Leaderboard")
|
128 |
+
|
129 |
+
with gr.Row():
|
130 |
+
search_box = gr.Textbox(
|
131 |
+
label="Search Models (separate by ';')",
|
132 |
+
placeholder="🔍 Search for a model and press enter...",
|
133 |
+
scale=3
|
134 |
+
)
|
135 |
+
model_type_checkbox_group = gr.CheckboxGroup(
|
136 |
+
label="Model types",
|
137 |
+
choices=MODEL_TYPES,
|
138 |
+
value=MODEL_TYPES,
|
139 |
+
interactive=True,
|
140 |
+
elem_classes=["filter-checkbox-group"],
|
141 |
+
scale=3
|
142 |
+
)
|
143 |
+
model_size_checkbox_group = gr.CheckboxGroup(
|
144 |
+
label="Model sizes (in number of parameters)",
|
145 |
+
choices=list(NUMERIC_INTERVALS.keys()),
|
146 |
+
value=list(NUMERIC_INTERVALS.keys()),
|
147 |
+
interactive=True,
|
148 |
+
elem_classes=["filter-checkbox-group"],
|
149 |
+
scale=2,
|
150 |
+
)
|
151 |
+
submit_button = gr.Button("Filter Data")
|
152 |
+
|
153 |
+
with gr.Tabs() as result_table:
|
154 |
+
for settings in CONFIG['settings']:
|
155 |
+
with gr.Tab(label=settings):
|
156 |
+
for type in CONFIG['types']:
|
157 |
+
with gr.Box(className="container"):
|
158 |
+
gr.Markdown(f"### {type} Leaderboard")
|
159 |
+
gr.DataFrame(data[settings][type], type="pandas")
|
160 |
+
|
161 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
demo.launch()
|
164 |
|
requirements.txt
CHANGED
@@ -13,4 +13,5 @@ python-dateutil
|
|
13 |
tqdm
|
14 |
transformers
|
15 |
tokenizers>=0.15.0
|
16 |
-
sentencepiece
|
|
|
|
13 |
tqdm
|
14 |
transformers
|
15 |
tokenizers>=0.15.0
|
16 |
+
sentencepiece
|
17 |
+
openpyxl
|