Spaces:
Sleeping
Sleeping
Modify Menu Size
#4
by
SmileXing
- opened
- app.py +29 -119
- app/backend/data_engine.py +0 -5
- app/backend/data_page.py +1 -2
- app/ui/__init__.py +0 -0
- app/ui/pages/__init__.py +0 -0
- app/ui/pages/data_page.py +3 -0
- app/ui/pages_sections.toml +35 -0
app.py
CHANGED
@@ -1,135 +1,45 @@
|
|
1 |
import os
|
|
|
2 |
import streamlit as st
|
3 |
|
|
|
|
|
4 |
from app.backend.constant import LEADERBOARD_MAP
|
5 |
from app.backend.data_engine import DataEngine
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# init global data engine
|
9 |
data_engine = DataEngine()
|
10 |
-
data_engine.jsons_to_df()
|
11 |
st.session_state["data_engine"] = data_engine
|
12 |
-
|
13 |
st.set_page_config(layout="wide")
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
# Add custom CSS
|
16 |
st.markdown("""
|
17 |
-
<style>
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
section[data-testid="stSidebar"] .stButton button {
|
25 |
-
width: 100%;
|
26 |
-
padding: 0.75rem 1rem;
|
27 |
-
background-color: transparent;
|
28 |
-
border: none;
|
29 |
-
text-align: left;
|
30 |
-
color: rgb(49, 51, 63);
|
31 |
-
font-size: 0.9rem;
|
32 |
-
font-weight: 400;
|
33 |
-
line-height: 1.6;
|
34 |
-
margin: 0.1rem 0;
|
35 |
-
}
|
36 |
-
|
37 |
-
.st-emotion-cache-64tehz {
|
38 |
-
|
39 |
-
gap: 0rem;
|
40 |
-
}
|
41 |
-
|
42 |
-
.st-emotion-cache-qsto9u {
|
43 |
-
|
44 |
-
justify-content: left;
|
45 |
-
|
46 |
-
}
|
47 |
-
|
48 |
-
[data-testid="stVerticalBlock"] .stVerticalBlock {
|
49 |
-
text-indent: 2rem;
|
50 |
-
}
|
51 |
-
|
52 |
-
/* Navigation button hover effect */
|
53 |
-
section[data-testid="stSidebar"] .stButton button:hover {
|
54 |
-
background-color: rgba(151, 166, 195, 0.15);
|
55 |
-
}
|
56 |
-
|
57 |
-
/* Selected state */
|
58 |
-
section[data-testid="stSidebar"] .stButton button.selected,
|
59 |
-
section[data-testid="stSidebar"] .stButton button:active,
|
60 |
-
section[data-testid="stSidebar"] .stButton button:focus {
|
61 |
-
background-color: #fff;
|
62 |
-
border: none;
|
63 |
-
box-shadow: none;
|
64 |
-
}
|
65 |
-
|
66 |
-
/* Page title style */
|
67 |
-
h1 {
|
68 |
-
font-size: 3rem !important;
|
69 |
-
font-weight: 600 !important;
|
70 |
-
color: rgb(49, 51, 63) !important;
|
71 |
-
margin-bottom: 1rem !important;
|
72 |
-
}
|
73 |
-
|
74 |
-
/* Divider style */
|
75 |
-
hr {
|
76 |
-
margin: 0.5rem 0;
|
77 |
-
border-color: rgba(49, 51, 63, 0.1);
|
78 |
-
}
|
79 |
-
|
80 |
-
/* Subpage indentation */
|
81 |
-
.child-page {
|
82 |
-
padding-left: 1rem;
|
83 |
-
}
|
84 |
-
</style>
|
85 |
-
""", unsafe_allow_html=True)
|
86 |
-
|
87 |
-
# Implement navigation using sidebar
|
88 |
-
with st.sidebar:
|
89 |
-
# Initialize session state
|
90 |
-
if "selected_page" not in st.session_state:
|
91 |
-
st.session_state.selected_page = "text"
|
92 |
-
|
93 |
-
# Text Leaderboard as clickable button
|
94 |
-
selected_class = "selected" if st.session_state.selected_page == "text" else ""
|
95 |
-
if st.button("📚 Text Leaderboard", key="text",
|
96 |
-
use_container_width=True,
|
97 |
-
):
|
98 |
-
st.session_state.selected_page = "text"
|
99 |
-
st.rerun()
|
100 |
-
|
101 |
-
# Subpage list
|
102 |
-
pages = [
|
103 |
-
("law", "⚖️ Law"),
|
104 |
-
("multilingual", "🌎 Multilingual"),
|
105 |
-
("german", "🇩🇪 German"),
|
106 |
-
("code", "💻 Code"),
|
107 |
-
("tech", "🛠️ Tech")
|
108 |
-
]
|
109 |
|
110 |
-
|
111 |
-
with st.container():
|
112 |
-
st.markdown('<div class="child-page">', unsafe_allow_html=True)
|
113 |
-
for page_id, page_title in pages:
|
114 |
-
selected_class = "selected" if st.session_state.selected_page == page_id else ""
|
115 |
-
if st.button(page_title, key=page_id, use_container_width=True):
|
116 |
-
st.session_state.selected_page = page_id
|
117 |
-
# st.rerun()
|
118 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
119 |
|
120 |
-
|
121 |
-
if st.session_state.selected_page == "text":
|
122 |
-
st.title("📚 Text Leaderboard")
|
123 |
-
elif st.session_state.selected_page == "law":
|
124 |
-
st.title("⚖️ Law")
|
125 |
-
elif st.session_state.selected_page == "multilingual":
|
126 |
-
st.title("🌎 Multilingual")
|
127 |
-
elif st.session_state.selected_page == "german":
|
128 |
-
st.title("🇩🇪 German")
|
129 |
-
elif st.session_state.selected_page == "code":
|
130 |
-
st.title("💻 Code")
|
131 |
-
elif st.session_state.selected_page == "tech":
|
132 |
-
st.title("🛠️ Tech")
|
133 |
|
134 |
-
|
135 |
-
render_page(st.session_state.selected_page)
|
|
|
1 |
import os
|
2 |
+
|
3 |
import streamlit as st
|
4 |
|
5 |
+
from st_pages import get_nav_from_toml, add_page_title
|
6 |
+
|
7 |
from app.backend.constant import LEADERBOARD_MAP
|
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 |
st.markdown("""
|
33 |
+
<style>
|
34 |
+
ul[data-testid="stSidebarNavItems"] li:not(:first-child) {
|
35 |
+
text-indent: 2rem;
|
36 |
+
}
|
37 |
+
</style>
|
38 |
+
"""
|
39 |
+
, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
pg = st.navigation(nav)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
add_page_title(pg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
pg.run()
|
|
app/backend/data_engine.py
CHANGED
@@ -141,8 +141,3 @@ class DataEngine:
|
|
141 |
df = self.jsons_to_df()
|
142 |
|
143 |
return df[df["group_name"] == group_name][COLUMNS][:]
|
144 |
-
|
145 |
-
def summarize_dataframe(self):
|
146 |
-
"""
|
147 |
-
Summarize data statistics
|
148 |
-
"""
|
|
|
141 |
df = self.jsons_to_df()
|
142 |
|
143 |
return df[df["group_name"] == group_name][COLUMNS][:]
|
|
|
|
|
|
|
|
|
|
app/backend/data_page.py
CHANGED
@@ -82,7 +82,6 @@ def render_page(group_name):
|
|
82 |
# title
|
83 |
st.markdown('<h2 class="center-text">Embedding Benchmark For Retrieval</h2>', unsafe_allow_html=True)
|
84 |
|
85 |
-
|
86 |
data_engine = st.session_state["data_engine"]
|
87 |
|
88 |
df = data_engine.jsons_to_df()[:]
|
@@ -213,4 +212,4 @@ def render_page(group_name):
|
|
213 |
allow_unsafe_jscode=True,
|
214 |
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
|
215 |
theme="streamlit",
|
216 |
-
)
|
|
|
82 |
# title
|
83 |
st.markdown('<h2 class="center-text">Embedding Benchmark For Retrieval</h2>', unsafe_allow_html=True)
|
84 |
|
|
|
85 |
data_engine = st.session_state["data_engine"]
|
86 |
|
87 |
df = data_engine.jsons_to_df()[:]
|
|
|
212 |
allow_unsafe_jscode=True,
|
213 |
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
|
214 |
theme="streamlit",
|
215 |
+
)
|
app/ui/__init__.py
ADDED
File without changes
|
app/ui/pages/__init__.py
ADDED
File without changes
|
app/ui/pages/data_page.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from app.backend.data_page import render_page
|
2 |
+
|
3 |
+
render_page("$group_name$")
|
app/ui/pages_sections.toml
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = "🛠️"
|