Spaces:
Running
Running
Sidebar and dataset table
#28
by fzoll - opened
- app.py +13 -13
- app/backend/app_init_func.py +65 -32
- app/backend/constant.py +3 -0
- app/backend/data_page.py +32 -1
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import streamlit as st
|
|
| 4 |
|
| 5 |
from st_pages import get_nav_from_toml, add_page_title
|
| 6 |
|
| 7 |
-
from app.backend.app_init_func import
|
| 8 |
from app.backend.data_engine import DataEngine
|
| 9 |
|
| 10 |
# init global data engine
|
|
@@ -24,20 +24,20 @@ nav = get_nav_from_toml(
|
|
| 24 |
)
|
| 25 |
|
| 26 |
# Add custom CSS
|
| 27 |
-
|
| 28 |
-
st.markdown(f"""
|
| 29 |
<style>
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
</style>
|
| 39 |
-
"""
|
| 40 |
-
, unsafe_allow_html=True)
|
| 41 |
|
| 42 |
pg = st.navigation(nav)
|
| 43 |
|
|
|
|
| 4 |
|
| 5 |
from st_pages import get_nav_from_toml, add_page_title
|
| 6 |
|
| 7 |
+
from app.backend.app_init_func import init_leaderboard, init_pages
|
| 8 |
from app.backend.data_engine import DataEngine
|
| 9 |
|
| 10 |
# init global data engine
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
# Add custom CSS
|
| 27 |
+
st.markdown("""
|
|
|
|
| 28 |
<style>
|
| 29 |
+
div[data-testid="stToolbar"] {visibility: hidden; height: 0px;}
|
| 30 |
+
footer {visibility: hidden;}
|
| 31 |
+
|
| 32 |
+
/* Indent Domain and Languages sections under Text Leaderboard */
|
| 33 |
+
ul[data-testid="stSidebarNavItems"] > div:nth-child(2),
|
| 34 |
+
ul[data-testid="stSidebarNavItems"] > div:nth-child(3) {
|
| 35 |
+
padding-left: 1.5rem;
|
| 36 |
+
border-left: 2px solid rgba(129, 150, 64, 0.3);
|
| 37 |
+
margin-left: 0.75rem;
|
| 38 |
+
}
|
| 39 |
</style>
|
| 40 |
+
""", unsafe_allow_html=True)
|
|
|
|
| 41 |
|
| 42 |
pg = st.navigation(nav)
|
| 43 |
|
app/backend/app_init_func.py
CHANGED
|
@@ -1,22 +1,47 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
from app.backend.constant import
|
|
|
|
|
|
|
|
|
|
| 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"]
|
|
@@ -25,27 +50,42 @@ def init_leaderboard():
|
|
| 25 |
leaderboard_section = f"{leaderboard.capitalize()} Leaderboard"
|
| 26 |
if leaderboard_section not in leaderboard_map:
|
| 27 |
leaderboard_map[leaderboard_section] = []
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
else
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 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
|
|
@@ -53,25 +93,19 @@ def init_leaderboard():
|
|
| 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))
|
|
@@ -79,6 +113,5 @@ def init_pages(leaderboard_change, page_change):
|
|
| 79 |
|
| 80 |
if __name__ == '__main__':
|
| 81 |
init_leaderboard()
|
| 82 |
-
init_pages()
|
| 83 |
print("\n".join(PAGE_SECTIONS))
|
| 84 |
-
print("\n".join(LI_CSS))
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
from app.backend.constant import (
|
| 5 |
+
LEADERBOARD_ICON_MAP, get_display_name,
|
| 6 |
+
DOMAIN_GROUPS, LANGUAGE_GROUPS,
|
| 7 |
+
)
|
| 8 |
|
| 9 |
LEADERBOARD_MAP = {}
|
|
|
|
| 10 |
PAGE_SECTIONS = []
|
| 11 |
|
| 12 |
|
| 13 |
+
def _page_toml(name, page_name):
|
| 14 |
+
icon = LEADERBOARD_ICON_MAP.get(page_name, "")
|
| 15 |
+
return f"""
|
| 16 |
+
[[pages]]
|
| 17 |
+
path = "app/ui/pages/{name}.py"
|
| 18 |
+
name = "{page_name}"
|
| 19 |
+
icon = "{icon}"
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _section_toml(section_name):
|
| 24 |
+
return f"""
|
| 25 |
+
[[pages]]
|
| 26 |
+
name = "{section_name}"
|
| 27 |
+
icon = ""
|
| 28 |
+
is_section = true
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
def init_leaderboard():
|
| 33 |
data_engine = st.session_state["data_engine"]
|
| 34 |
leaderboard_map = {}
|
|
|
|
|
|
|
|
|
|
| 35 |
leaderboard_change = False
|
| 36 |
page_change = False
|
| 37 |
|
| 38 |
+
text_root = []
|
| 39 |
+
domain_pages = []
|
| 40 |
+
language_pages = []
|
| 41 |
+
multimodal_root = []
|
| 42 |
+
multimodal_sub = []
|
| 43 |
+
sort_id = 0
|
| 44 |
+
|
| 45 |
for dataset in data_engine.datasets:
|
| 46 |
sort_id += 1
|
| 47 |
leaderboard = dataset["leaderboard"]
|
|
|
|
| 50 |
leaderboard_section = f"{leaderboard.capitalize()} Leaderboard"
|
| 51 |
if leaderboard_section not in leaderboard_map:
|
| 52 |
leaderboard_map[leaderboard_section] = []
|
| 53 |
+
|
| 54 |
+
is_root = name.lower() == leaderboard.lower()
|
| 55 |
+
leaderboard_map[leaderboard_section].append((name, 0 if is_root else sort_id))
|
| 56 |
+
|
| 57 |
+
page_name = leaderboard_section if is_root else get_display_name(name)
|
| 58 |
+
entry = _page_toml(name, page_name)
|
| 59 |
+
|
| 60 |
+
if leaderboard.lower() == "text":
|
| 61 |
+
if is_root:
|
| 62 |
+
text_root.append(entry)
|
| 63 |
+
elif name in DOMAIN_GROUPS:
|
| 64 |
+
domain_pages.append(entry)
|
| 65 |
+
elif name in LANGUAGE_GROUPS:
|
| 66 |
+
language_pages.append(entry)
|
| 67 |
+
elif leaderboard.lower() == "multimodal":
|
| 68 |
+
if is_root:
|
| 69 |
+
multimodal_root.append(entry)
|
| 70 |
+
else:
|
| 71 |
+
multimodal_sub.append(entry)
|
| 72 |
+
|
| 73 |
for k, v in leaderboard_map.items():
|
| 74 |
v.sort(key=lambda x: x[1])
|
| 75 |
|
| 76 |
+
page_sections = []
|
| 77 |
+
page_sections.extend(text_root)
|
| 78 |
+
if domain_pages:
|
| 79 |
+
page_sections.append(_section_toml("Domain"))
|
| 80 |
+
page_sections.extend(domain_pages)
|
| 81 |
+
if language_pages:
|
| 82 |
+
page_sections.append(_section_toml("Languages"))
|
| 83 |
+
page_sections.extend(language_pages)
|
| 84 |
+
if multimodal_root or multimodal_sub:
|
| 85 |
+
page_sections.append(_section_toml("Multimodal"))
|
| 86 |
+
page_sections.extend(multimodal_root)
|
| 87 |
+
page_sections.extend(multimodal_sub)
|
| 88 |
+
|
| 89 |
if leaderboard_map != LEADERBOARD_MAP:
|
| 90 |
LEADERBOARD_MAP.update(leaderboard_map)
|
| 91 |
leaderboard_change = True
|
|
|
|
| 93 |
PAGE_SECTIONS.clear()
|
| 94 |
PAGE_SECTIONS.extend(page_sections)
|
| 95 |
page_change = True
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
return leaderboard_change, page_change
|
| 98 |
|
| 99 |
|
| 100 |
def init_pages(leaderboard_change, page_change):
|
|
|
|
| 101 |
if leaderboard_change:
|
| 102 |
with open("app/ui/pages/data_page.py", "r", encoding="utf-8") as f:
|
| 103 |
data_page = f.read()
|
| 104 |
for leaderboard, group_names in LEADERBOARD_MAP.items():
|
|
|
|
| 105 |
for group_name in group_names:
|
| 106 |
path = os.path.join("app/ui/pages", f"{group_name[0]}.py")
|
| 107 |
with open(path, "w", encoding="utf-8") as f:
|
| 108 |
+
f.write(data_page.replace("$group_name$", group_name[0]))
|
|
|
|
| 109 |
if page_change:
|
| 110 |
with open("app/ui/pages_sections.toml", "w", encoding="utf-8") as f:
|
| 111 |
f.write("\n".join(PAGE_SECTIONS))
|
|
|
|
| 113 |
|
| 114 |
if __name__ == '__main__':
|
| 115 |
init_leaderboard()
|
| 116 |
+
init_pages(True, True)
|
| 117 |
print("\n".join(PAGE_SECTIONS))
|
|
|
app/backend/constant.py
CHANGED
|
@@ -93,6 +93,9 @@ LEADERBOARD_ICON_MAP = {
|
|
| 93 |
"Document": "π",
|
| 94 |
}
|
| 95 |
|
|
|
|
|
|
|
|
|
|
| 96 |
USERNAME = "embedding-benchmark"
|
| 97 |
SPACENAME = "RTEB"
|
| 98 |
|
|
|
|
| 93 |
"Document": "π",
|
| 94 |
}
|
| 95 |
|
| 96 |
+
DOMAIN_GROUPS = {"legal", "code", "healthcare", "finance"}
|
| 97 |
+
LANGUAGE_GROUPS = {"english", "french", "german", "japanese"}
|
| 98 |
+
|
| 99 |
USERNAME = "embedding-benchmark"
|
| 100 |
SPACENAME = "RTEB"
|
| 101 |
|
app/backend/data_page.py
CHANGED
|
@@ -9,8 +9,10 @@ from st_aggrid import AgGrid, JsCode, ColumnsAutoSizeMode
|
|
| 9 |
|
| 10 |
import streamlit as st
|
| 11 |
|
|
|
|
|
|
|
| 12 |
from app.backend.data_engine import DataEngine
|
| 13 |
-
from app.backend.multi_header_util import get_header_options
|
| 14 |
from utils.st_copy_to_clipboard import st_copy_to_clipboard
|
| 15 |
from streamlit_theme import st_theme
|
| 16 |
|
|
@@ -133,6 +135,33 @@ def table_only_css():
|
|
| 133 |
""", unsafe_allow_html=True)
|
| 134 |
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
def table_area(group_name, grid_state, data_engine=None, df=None):
|
| 137 |
"""
|
| 138 |
table_area
|
|
@@ -404,6 +433,8 @@ def main_page(group_name, grid_state):
|
|
| 404 |
|
| 405 |
data_engine = st.session_state.get("data_engine", DataEngine())
|
| 406 |
|
|
|
|
|
|
|
| 407 |
df = data_engine.jsons_to_df().copy()
|
| 408 |
|
| 409 |
csv = convert_df_to_csv(df)
|
|
|
|
| 9 |
|
| 10 |
import streamlit as st
|
| 11 |
|
| 12 |
+
import pandas as pd
|
| 13 |
+
|
| 14 |
from app.backend.data_engine import DataEngine
|
| 15 |
+
from app.backend.multi_header_util import get_header_options, get_dataset_url_name, LINK
|
| 16 |
from utils.st_copy_to_clipboard import st_copy_to_clipboard
|
| 17 |
from streamlit_theme import st_theme
|
| 18 |
|
|
|
|
| 135 |
""", unsafe_allow_html=True)
|
| 136 |
|
| 137 |
|
| 138 |
+
def datasets_table(group_name, data_engine):
|
| 139 |
+
dataset_list = []
|
| 140 |
+
for dataset_dict in data_engine.datasets:
|
| 141 |
+
if dataset_dict["name"] == group_name:
|
| 142 |
+
dataset_list = dataset_dict["datasets"]
|
| 143 |
+
break
|
| 144 |
+
|
| 145 |
+
if not dataset_list:
|
| 146 |
+
return
|
| 147 |
+
|
| 148 |
+
base_url = LINK.strip()
|
| 149 |
+
rows = []
|
| 150 |
+
for ds_name in dataset_list:
|
| 151 |
+
url_name = get_dataset_url_name(ds_name)
|
| 152 |
+
rows.append({"Dataset": ds_name, "URL": f"{base_url}{url_name}"})
|
| 153 |
+
|
| 154 |
+
df_datasets = pd.DataFrame(rows)
|
| 155 |
+
st.dataframe(
|
| 156 |
+
df_datasets,
|
| 157 |
+
column_config={
|
| 158 |
+
"URL": st.column_config.LinkColumn("URL", display_text="Open β")
|
| 159 |
+
},
|
| 160 |
+
hide_index=True,
|
| 161 |
+
use_container_width=True,
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
def table_area(group_name, grid_state, data_engine=None, df=None):
|
| 166 |
"""
|
| 167 |
table_area
|
|
|
|
| 433 |
|
| 434 |
data_engine = st.session_state.get("data_engine", DataEngine())
|
| 435 |
|
| 436 |
+
datasets_table(group_name, data_engine)
|
| 437 |
+
|
| 438 |
df = data_engine.jsons_to_df().copy()
|
| 439 |
|
| 440 |
csv = convert_df_to_csv(df)
|