Spaces:
Sleeping
Sleeping
Dynamically load sidebar and add closed average
#5
by
SmileXing
- opened
- app.py +10 -16
- app/backend/app_init_func.py +84 -0
- app/backend/constant.py +8 -13
- app/backend/data_page.py +44 -6
- app/ui/pages_sections.toml +0 -35
- utils/http_utils.py +2 -0
app.py
CHANGED
@@ -4,36 +4,30 @@ import streamlit as st
|
|
4 |
|
5 |
from st_pages import get_nav_from_toml, add_page_title
|
6 |
|
7 |
-
from app.backend.
|
8 |
from app.backend.data_engine import DataEngine
|
9 |
|
10 |
-
# init pages
|
11 |
-
with open("app/ui/pages/data_page.py", "r", encoding="utf-8") as f:
|
12 |
-
data_page = f.read()
|
13 |
-
for leaderboard, group_names in LEADERBOARD_MAP.items():
|
14 |
-
|
15 |
-
for group_name in group_names:
|
16 |
-
path = os.path.join("app/ui/pages", f"{group_name}.py")
|
17 |
-
with open(path, "w", encoding="utf-8") as f:
|
18 |
-
f.write(data_page.replace("$group_name$", group_name)
|
19 |
-
)
|
20 |
-
|
21 |
# init global data engine
|
22 |
data_engine = DataEngine()
|
|
|
23 |
st.session_state["data_engine"] = data_engine
|
24 |
st.set_page_config(layout="wide")
|
25 |
|
|
|
|
|
|
|
|
|
|
|
26 |
# load page tree
|
27 |
nav = get_nav_from_toml(
|
28 |
"app/ui/pages_sections.toml"
|
29 |
)
|
30 |
|
31 |
# Add custom CSS
|
32 |
-
|
|
|
33 |
<style>
|
34 |
-
|
35 |
-
text-indent: 2rem;
|
36 |
-
}
|
37 |
</style>
|
38 |
"""
|
39 |
, unsafe_allow_html=True)
|
|
|
4 |
|
5 |
from st_pages import get_nav_from_toml, add_page_title
|
6 |
|
7 |
+
from app.backend.app_init_func import LI_CSS, init_leaderboard, init_pages
|
8 |
from app.backend.data_engine import DataEngine
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# init global data engine
|
11 |
data_engine = DataEngine()
|
12 |
+
|
13 |
st.session_state["data_engine"] = data_engine
|
14 |
st.set_page_config(layout="wide")
|
15 |
|
16 |
+
# init leaderboard and pages
|
17 |
+
leaderboard_change, page_change = init_leaderboard()
|
18 |
+
|
19 |
+
init_pages(leaderboard_change, page_change)
|
20 |
+
|
21 |
# load page tree
|
22 |
nav = get_nav_from_toml(
|
23 |
"app/ui/pages_sections.toml"
|
24 |
)
|
25 |
|
26 |
# Add custom CSS
|
27 |
+
css = "\n".join(LI_CSS)
|
28 |
+
st.markdown(f"""
|
29 |
<style>
|
30 |
+
{css}
|
|
|
|
|
31 |
</style>
|
32 |
"""
|
33 |
, unsafe_allow_html=True)
|
app/backend/app_init_func.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
|
4 |
+
from app.backend.constant import LEADERBOARD_ICON_MAP
|
5 |
+
|
6 |
+
LEADERBOARD_MAP = {}
|
7 |
+
LI_CSS = []
|
8 |
+
PAGE_SECTIONS = []
|
9 |
+
|
10 |
+
|
11 |
+
def init_leaderboard():
|
12 |
+
data_engine = st.session_state["data_engine"]
|
13 |
+
leaderboard_map = {}
|
14 |
+
page_sections = []
|
15 |
+
li_css = []
|
16 |
+
sort_id = 0
|
17 |
+
leaderboard_change = False
|
18 |
+
page_change = False
|
19 |
+
|
20 |
+
for dataset in data_engine.datasets:
|
21 |
+
sort_id += 1
|
22 |
+
leaderboard = dataset["leaderboard"]
|
23 |
+
name = dataset["name"]
|
24 |
+
|
25 |
+
leaderboard_section = f"{leaderboard.capitalize()} Leaderboard"
|
26 |
+
if leaderboard_section not in leaderboard_map:
|
27 |
+
leaderboard_map[leaderboard_section] = []
|
28 |
+
if name.lower() == leaderboard.lower():
|
29 |
+
leaderboard_map[leaderboard_section].append((name, 0))
|
30 |
+
else:
|
31 |
+
leaderboard_map[leaderboard_section].append((name, sort_id))
|
32 |
+
li_css.append(f"""
|
33 |
+
ul[data-testid="stSidebarNavItems"] li:nth-child({sort_id}) {{
|
34 |
+
text-indent: 2rem;
|
35 |
+
}}
|
36 |
+
""")
|
37 |
+
page_name = leaderboard_section if name.lower() == leaderboard.lower() else name.capitalize()
|
38 |
+
page_sections.append(f"""
|
39 |
+
[[pages]]
|
40 |
+
path = "app/ui/pages/{name}.py"
|
41 |
+
name = "{page_name}"
|
42 |
+
icon = "{LEADERBOARD_ICON_MAP.get(page_name, "")}"
|
43 |
+
""")
|
44 |
+
|
45 |
+
# ensure leaderboard is first
|
46 |
+
for k, v in leaderboard_map.items():
|
47 |
+
v.sort(key=lambda x: x[1])
|
48 |
+
|
49 |
+
if leaderboard_map != LEADERBOARD_MAP:
|
50 |
+
LEADERBOARD_MAP.update(leaderboard_map)
|
51 |
+
leaderboard_change = True
|
52 |
+
if page_sections != PAGE_SECTIONS:
|
53 |
+
PAGE_SECTIONS.clear()
|
54 |
+
PAGE_SECTIONS.extend(page_sections)
|
55 |
+
page_change = True
|
56 |
+
if li_css != LI_CSS:
|
57 |
+
LI_CSS.clear()
|
58 |
+
LI_CSS.extend(li_css)
|
59 |
+
|
60 |
+
return leaderboard_change, page_change
|
61 |
+
|
62 |
+
|
63 |
+
def init_pages(leaderboard_change, page_change):
|
64 |
+
# init pages
|
65 |
+
if leaderboard_change:
|
66 |
+
with open("app/ui/pages/data_page.py", "r", encoding="utf-8") as f:
|
67 |
+
data_page = f.read()
|
68 |
+
for leaderboard, group_names in LEADERBOARD_MAP.items():
|
69 |
+
|
70 |
+
for group_name in group_names:
|
71 |
+
path = os.path.join("app/ui/pages", f"{group_name[0]}.py")
|
72 |
+
with open(path, "w", encoding="utf-8") as f:
|
73 |
+
f.write(data_page.replace("$group_name$", group_name[0])
|
74 |
+
)
|
75 |
+
if page_change:
|
76 |
+
with open("app/ui/pages_sections.toml", "w", encoding="utf-8") as f:
|
77 |
+
f.write("\n".join(PAGE_SECTIONS))
|
78 |
+
|
79 |
+
|
80 |
+
if __name__ == '__main__':
|
81 |
+
init_leaderboard()
|
82 |
+
init_pages()
|
83 |
+
print("\n".join(PAGE_SECTIONS))
|
84 |
+
print("\n".join(LI_CSS))
|
app/backend/constant.py
CHANGED
@@ -67,17 +67,12 @@ class Similarity(Enum):
|
|
67 |
EUCLIDEAN = "euclidean"
|
68 |
|
69 |
|
70 |
-
|
71 |
-
"Text":
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
],
|
80 |
-
"Multimodal": [
|
81 |
-
|
82 |
-
]
|
83 |
}
|
|
|
67 |
EUCLIDEAN = "euclidean"
|
68 |
|
69 |
|
70 |
+
LEADERBOARD_ICON_MAP = {
|
71 |
+
"Text Leaderboard":"📚",
|
72 |
+
"Law":"⚖️",
|
73 |
+
"Multilingual":"🌎",
|
74 |
+
"German":"🇩🇪",
|
75 |
+
"Code":"💻",
|
76 |
+
"Tech":"🛠️",
|
77 |
+
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
app/backend/data_page.py
CHANGED
@@ -7,6 +7,8 @@ from st_aggrid import AgGrid, JsCode, ColumnsAutoSizeMode
|
|
7 |
|
8 |
import streamlit as st
|
9 |
|
|
|
|
|
10 |
COLUMNS = ['model_name',
|
11 |
'embd_dtype', 'embd_dim', 'num_params', 'max_tokens', 'similarity',
|
12 |
'query_instruct', 'corpus_instruct', 'reference'
|
@@ -16,6 +18,26 @@ HEADER_STYLE = {'fontSize': '18px'}
|
|
16 |
CELL_STYLE = {'fontSize': '18px'}
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def render_page(group_name):
|
20 |
# Add theme color and grid styles
|
21 |
st.markdown("""
|
@@ -88,7 +110,7 @@ def render_page(group_name):
|
|
88 |
# get columns
|
89 |
column_list = []
|
90 |
avg_column = None
|
91 |
-
if group_name
|
92 |
avg_columns = []
|
93 |
for column in df.columns:
|
94 |
|
@@ -111,11 +133,16 @@ def render_page(group_name):
|
|
111 |
avg_column = new_column
|
112 |
|
113 |
dataset_list = []
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
118 |
column_list.extend(dataset_list)
|
|
|
|
|
|
|
|
|
119 |
|
120 |
df = df[COLUMNS + column_list].sort_values(by=avg_column, ascending=False)
|
121 |
|
@@ -148,17 +175,26 @@ def render_page(group_name):
|
|
148 |
'headerStyle': HEADER_STYLE,
|
149 |
'cellStyle': CELL_STYLE,
|
150 |
'suppressSizeToFit': True},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
{
|
152 |
'headerName': 'Data Type',
|
153 |
'field': 'embd_dtype',
|
154 |
'headerStyle': HEADER_STYLE,
|
155 |
'cellStyle': CELL_STYLE,
|
|
|
156 |
},
|
157 |
{
|
158 |
'headerName': 'Embd Dim',
|
159 |
'field': 'embd_dim',
|
160 |
'headerStyle': HEADER_STYLE,
|
161 |
'cellStyle': CELL_STYLE,
|
|
|
162 |
},
|
163 |
{
|
164 |
'headerName': 'Model Size (# of Parameters)',
|
@@ -166,12 +202,14 @@ def render_page(group_name):
|
|
166 |
'cellDataType': 'number',
|
167 |
'headerStyle': HEADER_STYLE,
|
168 |
'cellStyle': CELL_STYLE,
|
|
|
169 |
},
|
170 |
{
|
171 |
'headerName': 'Context Length',
|
172 |
'field': 'max_tokens',
|
173 |
'headerStyle': HEADER_STYLE,
|
174 |
'cellStyle': CELL_STYLE,
|
|
|
175 |
},
|
176 |
{
|
177 |
'headerName': 'Query Instruction',
|
@@ -193,7 +231,7 @@ def render_page(group_name):
|
|
193 |
'field': column,
|
194 |
'headerStyle': HEADER_STYLE,
|
195 |
'cellStyle': CELL_STYLE,
|
196 |
-
'suppressSizeToFit': True} for column in column_list if column
|
197 |
],
|
198 |
'defaultColDef': {
|
199 |
'filter': True,
|
|
|
7 |
|
8 |
import streamlit as st
|
9 |
|
10 |
+
from app.backend.app_init_func import LEADERBOARD_MAP
|
11 |
+
|
12 |
COLUMNS = ['model_name',
|
13 |
'embd_dtype', 'embd_dim', 'num_params', 'max_tokens', 'similarity',
|
14 |
'query_instruct', 'corpus_instruct', 'reference'
|
|
|
18 |
CELL_STYLE = {'fontSize': '18px'}
|
19 |
|
20 |
|
21 |
+
def is_section(group_name):
|
22 |
+
|
23 |
+
for k, v in LEADERBOARD_MAP.items():
|
24 |
+
leaderboard_name = v[0][0]
|
25 |
+
|
26 |
+
if group_name == leaderboard_name:
|
27 |
+
return True
|
28 |
+
return False
|
29 |
+
|
30 |
+
|
31 |
+
def get_closed_dataset():
|
32 |
+
data_engine = st.session_state["data_engine"]
|
33 |
+
closed_list = []
|
34 |
+
results = data_engine.results
|
35 |
+
for result in results:
|
36 |
+
if result.get("is_closed"):
|
37 |
+
closed_list.append(result.get("dataset_name"))
|
38 |
+
return closed_list
|
39 |
+
|
40 |
+
|
41 |
def render_page(group_name):
|
42 |
# Add theme color and grid styles
|
43 |
st.markdown("""
|
|
|
110 |
# get columns
|
111 |
column_list = []
|
112 |
avg_column = None
|
113 |
+
if is_section(group_name):
|
114 |
avg_columns = []
|
115 |
for column in df.columns:
|
116 |
|
|
|
133 |
avg_column = new_column
|
134 |
|
135 |
dataset_list = []
|
136 |
+
|
137 |
+
for dataset_dict in data_engine.datasets:
|
138 |
+
if dataset_dict["name"] == group_name:
|
139 |
+
dataset_list = dataset_dict["datasets"]
|
140 |
+
if not is_section(group_name):
|
141 |
column_list.extend(dataset_list)
|
142 |
+
closed_list = get_closed_dataset()
|
143 |
+
close_avg_list = list(set(dataset_list) & set(closed_list))
|
144 |
+
df["Closed average"] = df[close_avg_list].mean(axis=1)
|
145 |
+
column_list.append("Closed average")
|
146 |
|
147 |
df = df[COLUMNS + column_list].sort_values(by=avg_column, ascending=False)
|
148 |
|
|
|
175 |
'headerStyle': HEADER_STYLE,
|
176 |
'cellStyle': CELL_STYLE,
|
177 |
'suppressSizeToFit': True},
|
178 |
+
|
179 |
+
{'headerName': 'Closed average',
|
180 |
+
'field': 'Closed average',
|
181 |
+
'headerStyle': HEADER_STYLE,
|
182 |
+
'cellStyle': CELL_STYLE,
|
183 |
+
'suppressSizeToFit': True},
|
184 |
+
|
185 |
{
|
186 |
'headerName': 'Data Type',
|
187 |
'field': 'embd_dtype',
|
188 |
'headerStyle': HEADER_STYLE,
|
189 |
'cellStyle': CELL_STYLE,
|
190 |
+
'suppressSizeToFit': True,
|
191 |
},
|
192 |
{
|
193 |
'headerName': 'Embd Dim',
|
194 |
'field': 'embd_dim',
|
195 |
'headerStyle': HEADER_STYLE,
|
196 |
'cellStyle': CELL_STYLE,
|
197 |
+
'suppressSizeToFit': True,
|
198 |
},
|
199 |
{
|
200 |
'headerName': 'Model Size (# of Parameters)',
|
|
|
202 |
'cellDataType': 'number',
|
203 |
'headerStyle': HEADER_STYLE,
|
204 |
'cellStyle': CELL_STYLE,
|
205 |
+
'suppressSizeToFit': True,
|
206 |
},
|
207 |
{
|
208 |
'headerName': 'Context Length',
|
209 |
'field': 'max_tokens',
|
210 |
'headerStyle': HEADER_STYLE,
|
211 |
'cellStyle': CELL_STYLE,
|
212 |
+
'suppressSizeToFit': True,
|
213 |
},
|
214 |
{
|
215 |
'headerName': 'Query Instruction',
|
|
|
231 |
'field': column,
|
232 |
'headerStyle': HEADER_STYLE,
|
233 |
'cellStyle': CELL_STYLE,
|
234 |
+
'suppressSizeToFit': True} for column in column_list if column not in (avg_column, "Closed average")]
|
235 |
],
|
236 |
'defaultColDef': {
|
237 |
'filter': True,
|
app/ui/pages_sections.toml
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
[[pages]]
|
2 |
-
path = "app/ui/pages/text.py"
|
3 |
-
name = "Text Leaderboard"
|
4 |
-
icon = "📚"
|
5 |
-
#is_section = true
|
6 |
-
|
7 |
-
#[[pages]]
|
8 |
-
#path = "app/ui/pages/text.py"
|
9 |
-
#name = "Overall"
|
10 |
-
#icon = "🏆"
|
11 |
-
|
12 |
-
[[pages]]
|
13 |
-
path = "app/ui/pages/law.py"
|
14 |
-
name = "Law"
|
15 |
-
icon = "⚖️"
|
16 |
-
|
17 |
-
[[pages]]
|
18 |
-
path = "app/ui/pages/multilingual.py"
|
19 |
-
name = "Multilingual"
|
20 |
-
icon = "🌎"
|
21 |
-
|
22 |
-
[[pages]]
|
23 |
-
path = "app/ui/pages/german.py"
|
24 |
-
name = "German"
|
25 |
-
icon = "🇩🇪"
|
26 |
-
|
27 |
-
[[pages]]
|
28 |
-
path = "app/ui/pages/code.py"
|
29 |
-
name = "Code"
|
30 |
-
icon = "💻"
|
31 |
-
|
32 |
-
[[pages]]
|
33 |
-
path = "app/ui/pages/tech.py"
|
34 |
-
name = "Tech"
|
35 |
-
icon = "🛠️"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/http_utils.py
CHANGED
@@ -3,3 +3,5 @@ import requests
|
|
3 |
|
4 |
def get(url: str, params: str = None, verify: bool = False):
|
5 |
return requests.get(url, params, verify=verify)
|
|
|
|
|
|
3 |
|
4 |
def get(url: str, params: str = None, verify: bool = False):
|
5 |
return requests.get(url, params, verify=verify)
|
6 |
+
|
7 |
+
|