Spaces:
Running
Running
init
#1
by
q275343119
- opened
- README.md +15 -8
- app.py +0 -46
- app/__init__.py +0 -1
- app/backend/__init__.py +0 -1
- app/backend/app_init_func.py +0 -84
- app/backend/constant.py +0 -92
- app/backend/data_engine.py +0 -148
- app/backend/data_page.py +0 -502
- app/backend/json_util.py +0 -15
- app/ui/__init__.py +0 -0
- app/ui/pages/__init__.py +0 -0
- app/ui/pages/data_page.py +0 -3
- app/ui/pages_sections.toml +0 -54
- requirements.txt +3 -6
- src/streamlit_app.py +40 -0
- utils/__init__.py +0 -0
- utils/cache_decorator.py +0 -54
- utils/http_utils.py +0 -7
- utils/st_copy_to_clipboard/__init__.py +0 -66
- utils/st_copy_to_clipboard/frontend/index.html +0 -19
- utils/st_copy_to_clipboard/frontend/main.js +0 -61
- utils/st_copy_to_clipboard/frontend/streamlit-component-lib.js +0 -36
- utils/st_copy_to_clipboard/frontend/style.css +0 -31
README.md
CHANGED
@@ -1,12 +1,19 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk:
|
7 |
-
|
8 |
-
|
|
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Streamlit Rteb
|
3 |
+
emoji: π
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
+
sdk: docker
|
7 |
+
app_port: 8501
|
8 |
+
tags:
|
9 |
+
- streamlit
|
10 |
pinned: false
|
11 |
+
short_description: Streamlit template space
|
12 |
---
|
13 |
|
14 |
+
# Welcome to Streamlit!
|
15 |
+
|
16 |
+
Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
|
17 |
+
|
18 |
+
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
19 |
+
forums](https://discuss.streamlit.io).
|
app.py
DELETED
@@ -1,46 +0,0 @@
|
|
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.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 |
-
|
31 |
-
div[data-testid="stToolbar"] {{visibility: hidden; height: 0px;}}
|
32 |
-
|
33 |
-
footer {{visibility: hidden;}}
|
34 |
-
</style>
|
35 |
-
|
36 |
-
<style>
|
37 |
-
{css}
|
38 |
-
</style>
|
39 |
-
"""
|
40 |
-
, unsafe_allow_html=True)
|
41 |
-
|
42 |
-
pg = st.navigation(nav)
|
43 |
-
|
44 |
-
# add_page_title(pg)
|
45 |
-
|
46 |
-
pg.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
|
|
|
|
app/backend/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
|
|
|
|
app/backend/app_init_func.py
DELETED
@@ -1,84 +0,0 @@
|
|
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
DELETED
@@ -1,92 +0,0 @@
|
|
1 |
-
from enum import Enum
|
2 |
-
|
3 |
-
|
4 |
-
class Navigation(Enum):
|
5 |
-
TEXT_LEADERBOARD = "Text Leaderboard"
|
6 |
-
MULTIMODAL_LEADERBOARD = "Multimodal Leaderboard"
|
7 |
-
|
8 |
-
|
9 |
-
class TaskCategory(Enum):
|
10 |
-
LAW = "Law"
|
11 |
-
CODE = "Code"
|
12 |
-
CONVERSATIONAL = "Conversational"
|
13 |
-
TECH = "Tech"
|
14 |
-
LONG_CONTEXT = "Long-context"
|
15 |
-
MULTILINGUAL = "Multilingual"
|
16 |
-
|
17 |
-
|
18 |
-
class ModelProvider(Enum):
|
19 |
-
OPENAI = "OpenAI"
|
20 |
-
VOYAGEAI = "VoyageAI"
|
21 |
-
COHERE = "Cohere"
|
22 |
-
OTHERS = "Others"
|
23 |
-
|
24 |
-
|
25 |
-
class EvaluationMetric(Enum):
|
26 |
-
NDCG_1 = "NDCG@1"
|
27 |
-
NDCG_3 = "NDCG@3"
|
28 |
-
NDCG_5 = "NDCG@5"
|
29 |
-
NDCG_10 = "NDCG@10"
|
30 |
-
NDCG_20 = "NDCG@20"
|
31 |
-
NDCG_50 = "NDCG@50"
|
32 |
-
NDCG_100 = "NDCG@100"
|
33 |
-
RECALL_1 = "RECALL@1"
|
34 |
-
RECALL_3 = "RECALL@3"
|
35 |
-
RECALL_5 = "RECALL@5"
|
36 |
-
RECALL_10 = "RECALL@10"
|
37 |
-
RECALL_20 = "RECALL@20"
|
38 |
-
RECALL_50 = "RECALL@50"
|
39 |
-
RECALL_100 = "RECALL@100"
|
40 |
-
PRECISION_1 = "PRECISION@1"
|
41 |
-
PRECISION_3 = "PRECISION@3"
|
42 |
-
PRECISION_5 = "PRECISION@5"
|
43 |
-
PRECISION_10 = "PRECISION@10"
|
44 |
-
PRECISION_20 = "PRECISION@20"
|
45 |
-
PRECISION_50 = "PRECISION@50"
|
46 |
-
PRECISION_100 = "PRECISION@100"
|
47 |
-
|
48 |
-
|
49 |
-
class EmbdDtype(Enum):
|
50 |
-
ALL = "all"
|
51 |
-
FLOAT_32 = "float32"
|
52 |
-
INT_8 = "int8"
|
53 |
-
BINARY = "binary"
|
54 |
-
|
55 |
-
|
56 |
-
class EmbdDim(Enum):
|
57 |
-
OP1 = "<=1k"
|
58 |
-
OP2 = "1k-2k"
|
59 |
-
OP3 = "2k-5k"
|
60 |
-
OP4 = ">=5k"
|
61 |
-
|
62 |
-
|
63 |
-
class Similarity(Enum):
|
64 |
-
ALL = "all"
|
65 |
-
COSINE = "cosine"
|
66 |
-
DOT = "dot"
|
67 |
-
EUCLIDEAN = "euclidean"
|
68 |
-
|
69 |
-
|
70 |
-
LEADERBOARD_ICON_MAP = {
|
71 |
-
"Text Leaderboard": "π",
|
72 |
-
"Law": "βοΈ",
|
73 |
-
"Multilingual": "π",
|
74 |
-
"German": "π©πͺ",
|
75 |
-
"Code": "π»",
|
76 |
-
"Tech": "π οΈ",
|
77 |
-
"Legal": "π",
|
78 |
-
"English": "π¬π§",
|
79 |
-
"Healthcare": "π₯",
|
80 |
-
"Finance": "π°",
|
81 |
-
"French": "π«π·",
|
82 |
-
"Japanese": "π―π΅",
|
83 |
-
|
84 |
-
}
|
85 |
-
|
86 |
-
|
87 |
-
# USERNAME = "embedding-benchmark"
|
88 |
-
# SPACENAME = "RTEB"
|
89 |
-
USERNAME = "q275343119"
|
90 |
-
SPACENAME = "streamlit-rteb"
|
91 |
-
# https://{UserName}-{SpaceName}.hf.space/
|
92 |
-
BASE_URL = f"https://{USERNAME}-{SPACENAME}.hf.space/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/backend/data_engine.py
DELETED
@@ -1,148 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Data service provider
|
3 |
-
"""
|
4 |
-
import json
|
5 |
-
from typing import List
|
6 |
-
|
7 |
-
import pandas as pd
|
8 |
-
|
9 |
-
from utils.cache_decorator import cache_df_with_custom_key, cache_dict_with_custom_key
|
10 |
-
from utils.http_utils import get
|
11 |
-
|
12 |
-
COLUMNS = ['model_name',
|
13 |
-
'embd_dtype', 'embd_dim', 'num_params', 'max_tokens', 'similarity',
|
14 |
-
'query_instruct', 'corpus_instruct',
|
15 |
-
|
16 |
-
]
|
17 |
-
COLUMNS_TYPES = ["markdown",
|
18 |
-
'str', 'str', 'number', 'number', 'str',
|
19 |
-
'str', 'str',
|
20 |
-
|
21 |
-
]
|
22 |
-
|
23 |
-
GIT_URL = "https://raw.githubusercontent.com/embedding-benchmark/rteb/refs/heads/main/results/"
|
24 |
-
DATASET_URL = f"{GIT_URL}datasets.json"
|
25 |
-
MODEL_URL = f"{GIT_URL}models.json"
|
26 |
-
RESULT_URL = f"{GIT_URL}results.json"
|
27 |
-
|
28 |
-
|
29 |
-
class DataEngine:
|
30 |
-
|
31 |
-
def __init__(self):
|
32 |
-
self.df = self.init_dataframe()
|
33 |
-
|
34 |
-
@property
|
35 |
-
@cache_dict_with_custom_key("models")
|
36 |
-
def models(self):
|
37 |
-
"""
|
38 |
-
Get models data
|
39 |
-
"""
|
40 |
-
res = get(MODEL_URL)
|
41 |
-
if res.status_code == 200:
|
42 |
-
return res.json()
|
43 |
-
return {}
|
44 |
-
|
45 |
-
@property
|
46 |
-
@cache_dict_with_custom_key("datasets")
|
47 |
-
def datasets(self):
|
48 |
-
"""
|
49 |
-
Get tasks data
|
50 |
-
"""
|
51 |
-
res = get(DATASET_URL)
|
52 |
-
if res.status_code == 200:
|
53 |
-
return res.json()
|
54 |
-
return {}
|
55 |
-
|
56 |
-
@property
|
57 |
-
@cache_dict_with_custom_key("results")
|
58 |
-
def results(self):
|
59 |
-
"""
|
60 |
-
Get results data
|
61 |
-
"""
|
62 |
-
res = get(RESULT_URL)
|
63 |
-
if res.status_code == 200:
|
64 |
-
return res.json()
|
65 |
-
return {}
|
66 |
-
|
67 |
-
def init_dataframe(self):
|
68 |
-
"""
|
69 |
-
Initialize DataFrame
|
70 |
-
"""
|
71 |
-
d = {"hello": [123], "world": [456]}
|
72 |
-
return pd.DataFrame(d)
|
73 |
-
|
74 |
-
@cache_df_with_custom_key("json_result")
|
75 |
-
def jsons_to_df(self):
|
76 |
-
|
77 |
-
results_list = self.results
|
78 |
-
df_results_list = []
|
79 |
-
for result_dict in results_list:
|
80 |
-
dataset_name = result_dict["dataset_name"]
|
81 |
-
df_result_row = pd.DataFrame(result_dict["results"])
|
82 |
-
df_result_row["dataset_name"] = dataset_name
|
83 |
-
df_results_list.append(df_result_row)
|
84 |
-
df_result = pd.concat(df_results_list)
|
85 |
-
|
86 |
-
df_result = df_result[["model_name", "dataset_name", "ndcg_at_10", "embd_dim", "embd_dtype"]]
|
87 |
-
|
88 |
-
df_result["ndcg_at_10"] = (df_result["ndcg_at_10"] * 100).round(2)
|
89 |
-
|
90 |
-
df_datasets_list = []
|
91 |
-
for item in self.datasets:
|
92 |
-
dataset_names = item["datasets"]
|
93 |
-
df_dataset_row = pd.DataFrame(
|
94 |
-
{
|
95 |
-
"group_name": [item["name"] for _ in range(len(dataset_names))],
|
96 |
-
"dataset_name": dataset_names,
|
97 |
-
"leaderboard": [item["leaderboard"] for _ in range(len(dataset_names))]
|
98 |
-
}
|
99 |
-
)
|
100 |
-
df_datasets_list.append(df_dataset_row)
|
101 |
-
df_dataset = pd.concat(df_datasets_list).drop_duplicates()
|
102 |
-
|
103 |
-
models_list = self.models
|
104 |
-
|
105 |
-
df_model = pd.DataFrame(models_list)
|
106 |
-
|
107 |
-
df = pd.merge(df_result, df_dataset, on=["dataset_name"], how="inner")
|
108 |
-
|
109 |
-
# set dataset default value to 0
|
110 |
-
df = df.pivot(index=["model_name", "embd_dim", "embd_dtype", "group_name"], columns="dataset_name",
|
111 |
-
values=["ndcg_at_10"]).fillna(0).stack(level=1).reset_index()
|
112 |
-
# df = pd.merge(df, df_model, on=["model_name"], how="inner")
|
113 |
-
|
114 |
-
# dataset_num_map = {}
|
115 |
-
# grouped_dataset_count = df.groupby(["group_name"]).agg({
|
116 |
-
# "dataset_name": "nunique"
|
117 |
-
# }).reset_index()
|
118 |
-
#
|
119 |
-
# for _, row in grouped_dataset_count.iterrows():
|
120 |
-
# dataset_num_map[row["group_name"]] = row["dataset_name"]
|
121 |
-
|
122 |
-
grouped_model = df.groupby(["model_name", "group_name", "embd_dim", "embd_dtype"]).agg({
|
123 |
-
"ndcg_at_10": "mean",
|
124 |
-
}).reset_index()
|
125 |
-
|
126 |
-
pivot = grouped_model.pivot(index=["model_name", "embd_dim", "embd_dtype"], columns="group_name",
|
127 |
-
values=["ndcg_at_10"]).round(2).fillna(0)
|
128 |
-
|
129 |
-
# Rename columns
|
130 |
-
pivot.columns = list(
|
131 |
-
map(lambda x: f"{x[1].capitalize()} Average" if x[1] != 'text' else f"Average", pivot.columns))
|
132 |
-
|
133 |
-
pivot_dataset = df_result.pivot(index=["model_name", "embd_dim", "embd_dtype"], columns="dataset_name", values="ndcg_at_10").fillna(0)
|
134 |
-
|
135 |
-
df = pd.merge(df_model, pivot, on=["model_name", "embd_dim", "embd_dtype"])
|
136 |
-
df = pd.merge(df, pivot_dataset, on=["model_name", "embd_dim", "embd_dtype"])
|
137 |
-
|
138 |
-
if df.empty:
|
139 |
-
return pd.DataFrame(columns=COLUMNS + ["reference"])
|
140 |
-
return df
|
141 |
-
|
142 |
-
def filter_df(self, group_name: str):
|
143 |
-
"""
|
144 |
-
filter_by_providers
|
145 |
-
"""
|
146 |
-
df = self.jsons_to_df()
|
147 |
-
|
148 |
-
return df[df["group_name"] == group_name][COLUMNS][:]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/backend/data_page.py
DELETED
@@ -1,502 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
# @Date : 2025/2/5 16:26
|
3 |
-
# @Author : q275343119
|
4 |
-
# @File : data_page.py
|
5 |
-
# @Description:
|
6 |
-
import io
|
7 |
-
|
8 |
-
from st_aggrid import AgGrid, JsCode, ColumnsAutoSizeMode
|
9 |
-
import streamlit as st
|
10 |
-
from utils.st_copy_to_clipboard import st_copy_to_clipboard
|
11 |
-
from streamlit_theme import st_theme
|
12 |
-
|
13 |
-
from app.backend.app_init_func import LEADERBOARD_MAP
|
14 |
-
from app.backend.constant import LEADERBOARD_ICON_MAP, BASE_URL
|
15 |
-
from app.backend.json_util import compress_msgpack, decompress_msgpack
|
16 |
-
|
17 |
-
COLUMNS = ['model_name',
|
18 |
-
'embd_dtype', 'embd_dim', 'num_params', 'max_tokens', 'similarity',
|
19 |
-
'query_instruct', 'corpus_instruct', 'reference'
|
20 |
-
|
21 |
-
]
|
22 |
-
HEADER_STYLE = {'fontSize': '18px'}
|
23 |
-
CELL_STYLE = {'fontSize': '18px'}
|
24 |
-
|
25 |
-
|
26 |
-
def is_section(group_name):
|
27 |
-
for k, v in LEADERBOARD_MAP.items():
|
28 |
-
leaderboard_name = v[0][0]
|
29 |
-
|
30 |
-
if group_name == leaderboard_name:
|
31 |
-
return True
|
32 |
-
return False
|
33 |
-
|
34 |
-
|
35 |
-
def get_closed_dataset():
|
36 |
-
data_engine = st.session_state["data_engine"]
|
37 |
-
closed_list = []
|
38 |
-
results = data_engine.results
|
39 |
-
for result in results:
|
40 |
-
if result.get("is_closed"):
|
41 |
-
closed_list.append(result.get("dataset_name"))
|
42 |
-
return closed_list
|
43 |
-
|
44 |
-
|
45 |
-
def convert_df_to_csv(df):
|
46 |
-
output = io.StringIO()
|
47 |
-
df.to_csv(output, index=False)
|
48 |
-
return output.getvalue()
|
49 |
-
|
50 |
-
|
51 |
-
def get_column_state():
|
52 |
-
"""
|
53 |
-
get column state from url
|
54 |
-
"""
|
55 |
-
query_params = st.query_params.get("grid_state", None)
|
56 |
-
sider_bar_hidden = st.query_params.get("sider_bar_hidden", "False")
|
57 |
-
table_only = st.query_params.get("table_only", "False")
|
58 |
-
if query_params:
|
59 |
-
grid_state = decompress_msgpack(query_params)
|
60 |
-
st.session_state.grid_state = grid_state
|
61 |
-
if sider_bar_hidden.upper() == 'FALSE':
|
62 |
-
st.session_state.sider_bar_hidden = False
|
63 |
-
if table_only.upper() == 'FALSE':
|
64 |
-
st.session_state.table_only = False
|
65 |
-
return None
|
66 |
-
|
67 |
-
|
68 |
-
def sidebar_css():
|
69 |
-
"""
|
70 |
-
|
71 |
-
:return:
|
72 |
-
"""
|
73 |
-
if st.session_state.sider_bar_hidden:
|
74 |
-
st.markdown("""
|
75 |
-
<style>
|
76 |
-
[data-testid="stSidebar"] {
|
77 |
-
display: none !important;
|
78 |
-
}
|
79 |
-
[data-testid="stSidebarNav"] {
|
80 |
-
display: none !important;
|
81 |
-
}
|
82 |
-
|
83 |
-
[data-testid="stBaseButton-headerNoPadding"] {
|
84 |
-
display: none !important;
|
85 |
-
}
|
86 |
-
|
87 |
-
h1#retrieval-embedding-benchmark-rteb {
|
88 |
-
text-align: center;
|
89 |
-
}
|
90 |
-
|
91 |
-
</style>
|
92 |
-
""", unsafe_allow_html=True)
|
93 |
-
|
94 |
-
|
95 |
-
def table_only_css():
|
96 |
-
if st.session_state.table_only:
|
97 |
-
st.markdown("""
|
98 |
-
<style>
|
99 |
-
|
100 |
-
[data-testid="stMainBlockContainer"] {
|
101 |
-
padding-top: 0px;
|
102 |
-
padding-left: 0px;
|
103 |
-
padding-bottom: 0px;
|
104 |
-
padding-right: 0px;
|
105 |
-
}
|
106 |
-
|
107 |
-
[data-testid="stHeader"] {
|
108 |
-
height: 0px;
|
109 |
-
}
|
110 |
-
|
111 |
-
[data-testid="stApp"] {
|
112 |
-
height: 456px;
|
113 |
-
}
|
114 |
-
|
115 |
-
.st-emotion-cache-1dp5vir {
|
116 |
-
|
117 |
-
height: 0px;
|
118 |
-
|
119 |
-
}
|
120 |
-
</style>
|
121 |
-
""", unsafe_allow_html=True)
|
122 |
-
|
123 |
-
|
124 |
-
def table_area(group_name, grid_state, data_engine=None, df=None):
|
125 |
-
"""
|
126 |
-
table_area
|
127 |
-
:param group_name:
|
128 |
-
:param grid_state:
|
129 |
-
:param data_engine:
|
130 |
-
:param df:
|
131 |
-
:return:
|
132 |
-
"""
|
133 |
-
table_only_css()
|
134 |
-
|
135 |
-
if data_engine is None:
|
136 |
-
data_engine = st.session_state["data_engine"]
|
137 |
-
if df is None:
|
138 |
-
df = data_engine.jsons_to_df().copy()
|
139 |
-
|
140 |
-
# get columns
|
141 |
-
column_list = []
|
142 |
-
avg_column = None
|
143 |
-
if is_section(group_name):
|
144 |
-
avg_columns = []
|
145 |
-
for column in df.columns:
|
146 |
-
|
147 |
-
if column.startswith("Average"):
|
148 |
-
avg_columns.insert(0, column)
|
149 |
-
continue
|
150 |
-
if "Average" in column:
|
151 |
-
avg_columns.append(column)
|
152 |
-
continue
|
153 |
-
avg_column = avg_columns[0]
|
154 |
-
column_list.extend(avg_columns)
|
155 |
-
else:
|
156 |
-
for column in df.columns:
|
157 |
-
|
158 |
-
if column.startswith(group_name.capitalize() + " "):
|
159 |
-
avg_column = column
|
160 |
-
|
161 |
-
column_list.append(avg_column)
|
162 |
-
|
163 |
-
dataset_list = []
|
164 |
-
|
165 |
-
for dataset_dict in data_engine.datasets:
|
166 |
-
if dataset_dict["name"] == group_name:
|
167 |
-
dataset_list = dataset_dict["datasets"]
|
168 |
-
if not is_section(group_name):
|
169 |
-
column_list.extend(dataset_list)
|
170 |
-
closed_list = get_closed_dataset()
|
171 |
-
close_avg_list = list(set(dataset_list) & set(closed_list))
|
172 |
-
df["Closed average"] = df[close_avg_list].mean(axis=1).round(2)
|
173 |
-
column_list.append("Closed average")
|
174 |
-
|
175 |
-
open_avg_list = list(set(dataset_list) - set(closed_list))
|
176 |
-
df["Open average"] = df[open_avg_list].mean(axis=1).round(2)
|
177 |
-
column_list.append("Open average")
|
178 |
-
|
179 |
-
df = df[COLUMNS + column_list].sort_values(by=avg_column, ascending=False)
|
180 |
-
|
181 |
-
# rename avg column name
|
182 |
-
if not is_section(group_name):
|
183 |
-
new_column = avg_column.replace(group_name.capitalize(), "").strip()
|
184 |
-
df.rename(columns={avg_column: new_column}, inplace=True)
|
185 |
-
column_list.remove(avg_column)
|
186 |
-
avg_column = new_column
|
187 |
-
|
188 |
-
# setting column config
|
189 |
-
grid_options = {
|
190 |
-
'columnDefs': [
|
191 |
-
{
|
192 |
-
'headerName': 'Model Name',
|
193 |
-
'field': 'model_name',
|
194 |
-
'pinned': 'left',
|
195 |
-
'sortable': False,
|
196 |
-
'headerStyle': HEADER_STYLE,
|
197 |
-
'cellStyle': CELL_STYLE,
|
198 |
-
"tooltipValueGetter": JsCode(
|
199 |
-
"""function(p) {return p.value}"""
|
200 |
-
),
|
201 |
-
"width": 250,
|
202 |
-
'cellRenderer': JsCode("""class CustomHTML {
|
203 |
-
init(params) {
|
204 |
-
const link = params.data.reference;
|
205 |
-
this.eGui = document.createElement('div');
|
206 |
-
this.eGui.innerHTML = link ?
|
207 |
-
`<a href="${link}" class="a-cell" target="_blank">${params.value} </a>` :
|
208 |
-
params.value;
|
209 |
-
}
|
210 |
-
|
211 |
-
getGui() {
|
212 |
-
return this.eGui;
|
213 |
-
}
|
214 |
-
}"""),
|
215 |
-
'suppressSizeToFit': True
|
216 |
-
|
217 |
-
},
|
218 |
-
{'headerName': "Overall Score",
|
219 |
-
'field': avg_column,
|
220 |
-
'headerStyle': HEADER_STYLE,
|
221 |
-
'cellStyle': CELL_STYLE,
|
222 |
-
# 'suppressSizeToFit': True
|
223 |
-
},
|
224 |
-
|
225 |
-
# Add Open average column definition
|
226 |
-
{'headerName': 'Open Average',
|
227 |
-
'field': 'Open average',
|
228 |
-
'headerStyle': HEADER_STYLE,
|
229 |
-
'cellStyle': CELL_STYLE,
|
230 |
-
# 'suppressSizeToFit': True
|
231 |
-
},
|
232 |
-
|
233 |
-
{'headerName': 'Closed Average',
|
234 |
-
'field': 'Closed average',
|
235 |
-
'headerStyle': HEADER_STYLE,
|
236 |
-
'cellStyle': CELL_STYLE,
|
237 |
-
# 'suppressSizeToFit': True
|
238 |
-
},
|
239 |
-
|
240 |
-
{
|
241 |
-
'headerName': 'Embd Dtype',
|
242 |
-
'field': 'embd_dtype',
|
243 |
-
'headerStyle': HEADER_STYLE,
|
244 |
-
'cellStyle': CELL_STYLE,
|
245 |
-
# 'suppressSizeToFit': True,
|
246 |
-
},
|
247 |
-
{
|
248 |
-
'headerName': 'Embd Dim',
|
249 |
-
'field': 'embd_dim',
|
250 |
-
'headerStyle': HEADER_STYLE,
|
251 |
-
'cellStyle': CELL_STYLE,
|
252 |
-
# 'suppressSizeToFit': True,
|
253 |
-
},
|
254 |
-
{
|
255 |
-
'headerName': 'Number of Parameters',
|
256 |
-
'field': 'num_params',
|
257 |
-
'cellDataType': 'number',
|
258 |
-
"colId": "num_params",
|
259 |
-
'headerStyle': HEADER_STYLE,
|
260 |
-
'cellStyle': CELL_STYLE,
|
261 |
-
'valueFormatter': JsCode(
|
262 |
-
"""function(params) {
|
263 |
-
const num = params.value;
|
264 |
-
if (num >= 1e9) return (num / 1e9).toFixed(2) + "B";
|
265 |
-
if (num >= 1e6) return (num / 1e6).toFixed(2) + "M";
|
266 |
-
if (num >= 1e3) return (num / 1e3).toFixed(2) + "K";
|
267 |
-
return num;
|
268 |
-
}"""
|
269 |
-
),
|
270 |
-
"width": 120,
|
271 |
-
# 'suppressSizeToFit': True,
|
272 |
-
},
|
273 |
-
{
|
274 |
-
'headerName': 'Context Length',
|
275 |
-
'field': 'max_tokens',
|
276 |
-
'headerStyle': HEADER_STYLE,
|
277 |
-
'cellStyle': CELL_STYLE,
|
278 |
-
# 'suppressSizeToFit': True,
|
279 |
-
},
|
280 |
-
|
281 |
-
*[{'headerName': column if "Average" not in column else column.replace("Average", "").strip().capitalize(),
|
282 |
-
'field': column,
|
283 |
-
'headerStyle': HEADER_STYLE,
|
284 |
-
'cellStyle': CELL_STYLE,
|
285 |
-
"headerTooltip": column if "Average" not in column else column.replace("Average",
|
286 |
-
"").strip().capitalize()
|
287 |
-
# 'suppressSizeToFit': True
|
288 |
-
} for column in column_list if
|
289 |
-
column not in (avg_column, "Closed average", "Open average")]
|
290 |
-
],
|
291 |
-
'defaultColDef': {
|
292 |
-
'filter': True,
|
293 |
-
'sortable': True,
|
294 |
-
'resizable': True,
|
295 |
-
'headerClass': "multi-line-header",
|
296 |
-
'autoHeaderHeight': True,
|
297 |
-
'width': 105
|
298 |
-
},
|
299 |
-
|
300 |
-
"autoSizeStrategy": {
|
301 |
-
"type": 'fitCellContents',
|
302 |
-
"colIds": [column for column in column_list if column not in (avg_column, "Closed average", "Open average")]
|
303 |
-
},
|
304 |
-
"tooltipShowDelay": 500,
|
305 |
-
"initialState": grid_state,
|
306 |
-
}
|
307 |
-
|
308 |
-
custom_css = {
|
309 |
-
# Model Name Cell
|
310 |
-
".a-cell": {
|
311 |
-
"display": "inline-block",
|
312 |
-
"white-space": "nowrap",
|
313 |
-
"overflow": "hidden",
|
314 |
-
"text-overflow": "ellipsis",
|
315 |
-
"width": "100%",
|
316 |
-
"min-width": "0"
|
317 |
-
},
|
318 |
-
# Header
|
319 |
-
".multi-line-header": {
|
320 |
-
"text-overflow": "clip",
|
321 |
-
"overflow": "visible",
|
322 |
-
"white-space": "normal",
|
323 |
-
"height": "auto",
|
324 |
-
"font-family": 'Arial',
|
325 |
-
"font-size": "14px",
|
326 |
-
"font-weight": "bold",
|
327 |
-
"padding": "10px",
|
328 |
-
"text-align": "left",
|
329 |
-
}
|
330 |
-
,
|
331 |
-
# Filter Options and Input
|
332 |
-
".ag-theme-streamlit .ag-popup": {
|
333 |
-
"font-family": 'Arial',
|
334 |
-
"font-size": "14px",
|
335 |
-
|
336 |
-
}
|
337 |
-
, ".ag-picker-field-display": {
|
338 |
-
"font-family": 'Arial',
|
339 |
-
"font-size": "14px",
|
340 |
-
|
341 |
-
},
|
342 |
-
".ag-input-field-input .ag-text-field-input": {
|
343 |
-
"font-family": 'Arial',
|
344 |
-
"font-size": "14px",
|
345 |
-
|
346 |
-
}
|
347 |
-
|
348 |
-
}
|
349 |
-
|
350 |
-
grid = AgGrid(
|
351 |
-
df,
|
352 |
-
enable_enterprise_modules=False,
|
353 |
-
gridOptions=grid_options,
|
354 |
-
allow_unsafe_jscode=True,
|
355 |
-
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_ALL_COLUMNS_TO_VIEW,
|
356 |
-
theme="streamlit",
|
357 |
-
custom_css=custom_css,
|
358 |
-
update_on=["stateUpdated"],
|
359 |
-
)
|
360 |
-
|
361 |
-
return grid
|
362 |
-
|
363 |
-
|
364 |
-
def main_page(group_name, grid_state):
|
365 |
-
"""
|
366 |
-
main_page
|
367 |
-
:param group_name:
|
368 |
-
:param grid_state:
|
369 |
-
:return:
|
370 |
-
"""
|
371 |
-
|
372 |
-
# Add theme color and grid styles
|
373 |
-
st.title("Retrieval Embedding Benchmark (RTEB)")
|
374 |
-
st.markdown("""
|
375 |
-
<style>
|
376 |
-
:root {
|
377 |
-
--theme-color: rgb(129, 150, 64);
|
378 |
-
--theme-color-light: rgba(129, 150, 64, 0.2);
|
379 |
-
}
|
380 |
-
|
381 |
-
/* AG Grid specific overrides */
|
382 |
-
.ag-theme-alpine {
|
383 |
-
--ag-selected-row-background-color: var(--theme-color-light) !important;
|
384 |
-
--ag-row-hover-color: var(--theme-color-light) !important;
|
385 |
-
--ag-selected-tab-color: var(--theme-color) !important;
|
386 |
-
--ag-range-selection-border-color: var(--theme-color) !important;
|
387 |
-
--ag-range-selection-background-color: var(--theme-color-light) !important;
|
388 |
-
}
|
389 |
-
|
390 |
-
.ag-row-hover {
|
391 |
-
background-color: var(--theme-color-light) !important;
|
392 |
-
}
|
393 |
-
|
394 |
-
.ag-row-selected {
|
395 |
-
background-color: var(--theme-color-light) !important;
|
396 |
-
}
|
397 |
-
|
398 |
-
.ag-row-focus {
|
399 |
-
background-color: var(--theme-color-light) !important;
|
400 |
-
}
|
401 |
-
|
402 |
-
.ag-cell-focus {
|
403 |
-
border-color: var(--theme-color) !important;
|
404 |
-
}
|
405 |
-
|
406 |
-
/* Keep existing styles */
|
407 |
-
.center-text {
|
408 |
-
text-align: center;
|
409 |
-
color: var(--theme-color);
|
410 |
-
}
|
411 |
-
.center-image {
|
412 |
-
display: block;
|
413 |
-
margin-left: auto;
|
414 |
-
margin-right: auto;
|
415 |
-
}
|
416 |
-
h2 {
|
417 |
-
color: var(--theme-color) !important;
|
418 |
-
}
|
419 |
-
.ag-header-cell {
|
420 |
-
background-color: var(--theme-color) !important;
|
421 |
-
color: white !important;
|
422 |
-
}
|
423 |
-
a {
|
424 |
-
color: var(--theme-color) !important;
|
425 |
-
}
|
426 |
-
a:hover {
|
427 |
-
color: rgba(129, 150, 64, 0.8) !important;
|
428 |
-
}
|
429 |
-
/* Download Button */
|
430 |
-
button[data-testid="stBaseButton-secondary"] {
|
431 |
-
float: right;
|
432 |
-
|
433 |
-
}
|
434 |
-
/* Toast On The Top*/
|
435 |
-
div[data-testid="stToastContainer"] {
|
436 |
-
position: fixed !important;
|
437 |
-
z-index: 2147483647 !important;
|
438 |
-
}
|
439 |
-
|
440 |
-
</style>
|
441 |
-
|
442 |
-
""", unsafe_allow_html=True)
|
443 |
-
|
444 |
-
# logo
|
445 |
-
# st.markdown('<img src="https://www.voyageai.com/logo.svg" class="center-image" width="200">', unsafe_allow_html=True)
|
446 |
-
title = f'<h2 class="center-text">{LEADERBOARD_ICON_MAP.get(group_name.capitalize(), "")} {group_name.capitalize()}</h2>'
|
447 |
-
if is_section(group_name):
|
448 |
-
title = f'<h2 class="center-text">{LEADERBOARD_ICON_MAP.get(group_name.capitalize() + " Leaderboard", "")} {group_name.capitalize() + " Leaderboard"}</h2>'
|
449 |
-
# title
|
450 |
-
st.markdown(title, unsafe_allow_html=True)
|
451 |
-
|
452 |
-
data_engine = st.session_state["data_engine"]
|
453 |
-
|
454 |
-
df = data_engine.jsons_to_df().copy()
|
455 |
-
|
456 |
-
csv = convert_df_to_csv(df)
|
457 |
-
file_name = f"{group_name.capitalize()} Leaderboard" if is_section(group_name) else group_name.capitalize()
|
458 |
-
st.download_button(
|
459 |
-
label="Download CSV",
|
460 |
-
data=csv,
|
461 |
-
file_name=f"{file_name}.csv",
|
462 |
-
mime="text/csv",
|
463 |
-
icon=":material/download:",
|
464 |
-
)
|
465 |
-
|
466 |
-
grid = table_area(group_name, grid_state, data_engine, df)
|
467 |
-
|
468 |
-
@st.dialog("URL")
|
469 |
-
def share_url():
|
470 |
-
state = grid.grid_state
|
471 |
-
if state:
|
472 |
-
share_link = f'{BASE_URL.replace("_", "-")}{group_name}/?grid_state={compress_msgpack(state)}' if not is_section(
|
473 |
-
group_name) else f'{BASE_URL.replace("_", "-")}?grid_state={compress_msgpack(state)}'
|
474 |
-
else:
|
475 |
-
share_link = f'{BASE_URL.replace("_", "-")}{group_name}'
|
476 |
-
st.write(share_link)
|
477 |
-
theme = st_theme()
|
478 |
-
if theme:
|
479 |
-
theme = theme.get("base")
|
480 |
-
else:
|
481 |
-
theme = "light"
|
482 |
-
st_copy_to_clipboard(share_link, before_copy_label='πPush to copy', after_copy_label='β
Text copied!',
|
483 |
-
theme=theme)
|
484 |
-
|
485 |
-
share_btn = st.button("Share this page", icon=":material/share:")
|
486 |
-
|
487 |
-
if share_btn:
|
488 |
-
share_url()
|
489 |
-
|
490 |
-
|
491 |
-
def render_page(group_name):
|
492 |
-
grid_state = st.session_state.get("grid_state", {})
|
493 |
-
st.session_state.sider_bar_hidden = True
|
494 |
-
st.session_state.table_only = True
|
495 |
-
get_column_state()
|
496 |
-
|
497 |
-
sidebar_css()
|
498 |
-
|
499 |
-
if st.session_state.table_only:
|
500 |
-
table_area(group_name, grid_state)
|
501 |
-
else:
|
502 |
-
main_page(group_name, grid_state)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/backend/json_util.py
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
import msgpack
|
2 |
-
import gzip
|
3 |
-
import base64
|
4 |
-
|
5 |
-
|
6 |
-
def compress_msgpack(data):
|
7 |
-
packed = msgpack.packb(data)
|
8 |
-
compressed = gzip.compress(packed)
|
9 |
-
return base64.urlsafe_b64encode(compressed).decode('utf-8')
|
10 |
-
|
11 |
-
|
12 |
-
def decompress_msgpack(compressed_str):
|
13 |
-
compressed = base64.urlsafe_b64decode(compressed_str)
|
14 |
-
unpacked = gzip.decompress(compressed)
|
15 |
-
return msgpack.unpackb(unpacked, raw=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/ui/__init__.py
DELETED
File without changes
|
app/ui/pages/__init__.py
DELETED
File without changes
|
app/ui/pages/data_page.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
from app.backend.data_page import render_page
|
2 |
-
|
3 |
-
render_page("$group_name$")
|
|
|
|
|
|
|
|
app/ui/pages_sections.toml
DELETED
@@ -1,54 +0,0 @@
|
|
1 |
-
|
2 |
-
[[pages]]
|
3 |
-
path = "app/ui/pages/text.py"
|
4 |
-
name = "Text Leaderboard"
|
5 |
-
icon = "π"
|
6 |
-
|
7 |
-
|
8 |
-
[[pages]]
|
9 |
-
path = "app/ui/pages/legal.py"
|
10 |
-
name = "Legal"
|
11 |
-
icon = "π"
|
12 |
-
|
13 |
-
|
14 |
-
[[pages]]
|
15 |
-
path = "app/ui/pages/english.py"
|
16 |
-
name = "English"
|
17 |
-
icon = "π¬π§"
|
18 |
-
|
19 |
-
|
20 |
-
[[pages]]
|
21 |
-
path = "app/ui/pages/code.py"
|
22 |
-
name = "Code"
|
23 |
-
icon = "π»"
|
24 |
-
|
25 |
-
|
26 |
-
[[pages]]
|
27 |
-
path = "app/ui/pages/healthcare.py"
|
28 |
-
name = "Healthcare"
|
29 |
-
icon = "π₯"
|
30 |
-
|
31 |
-
|
32 |
-
[[pages]]
|
33 |
-
path = "app/ui/pages/finance.py"
|
34 |
-
name = "Finance"
|
35 |
-
icon = "π°"
|
36 |
-
|
37 |
-
|
38 |
-
[[pages]]
|
39 |
-
path = "app/ui/pages/german.py"
|
40 |
-
name = "German"
|
41 |
-
icon = "π©πͺ"
|
42 |
-
|
43 |
-
|
44 |
-
[[pages]]
|
45 |
-
path = "app/ui/pages/french.py"
|
46 |
-
name = "French"
|
47 |
-
icon = "π«π·"
|
48 |
-
|
49 |
-
|
50 |
-
[[pages]]
|
51 |
-
path = "app/ui/pages/japanese.py"
|
52 |
-
name = "Japanese"
|
53 |
-
icon = ""
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
msgpack==1.1.0
|
5 |
-
zstandard==0.23.0
|
6 |
-
st-theme==1.2.3
|
|
|
1 |
+
altair
|
2 |
+
pandas
|
3 |
+
streamlit
|
|
|
|
|
|
src/streamlit_app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import altair as alt
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
"""
|
7 |
+
# Welcome to Streamlit!
|
8 |
+
|
9 |
+
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
|
10 |
+
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
11 |
+
forums](https://discuss.streamlit.io).
|
12 |
+
|
13 |
+
In the meantime, below is an example of what you can do with just a few lines of code:
|
14 |
+
"""
|
15 |
+
|
16 |
+
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
17 |
+
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
18 |
+
|
19 |
+
indices = np.linspace(0, 1, num_points)
|
20 |
+
theta = 2 * np.pi * num_turns * indices
|
21 |
+
radius = indices
|
22 |
+
|
23 |
+
x = radius * np.cos(theta)
|
24 |
+
y = radius * np.sin(theta)
|
25 |
+
|
26 |
+
df = pd.DataFrame({
|
27 |
+
"x": x,
|
28 |
+
"y": y,
|
29 |
+
"idx": indices,
|
30 |
+
"rand": np.random.randn(num_points),
|
31 |
+
})
|
32 |
+
|
33 |
+
st.altair_chart(alt.Chart(df, height=700, width=700)
|
34 |
+
.mark_point(filled=True)
|
35 |
+
.encode(
|
36 |
+
x=alt.X("x", axis=None),
|
37 |
+
y=alt.Y("y", axis=None),
|
38 |
+
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
39 |
+
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
40 |
+
))
|
utils/__init__.py
DELETED
File without changes
|
utils/cache_decorator.py
DELETED
@@ -1,54 +0,0 @@
|
|
1 |
-
import time
|
2 |
-
from functools import wraps
|
3 |
-
import pandas as pd
|
4 |
-
|
5 |
-
CACHE = {}
|
6 |
-
TTL = 3600
|
7 |
-
|
8 |
-
|
9 |
-
def cache_df_with_custom_key(cache_key: str):
|
10 |
-
def decorator(func):
|
11 |
-
@wraps(func)
|
12 |
-
def wrapper(*args, **kwargs):
|
13 |
-
if cache_key in CACHE and CACHE[cache_key].get("expiry") - time.time() < TTL:
|
14 |
-
return CACHE[cache_key]["data"]
|
15 |
-
|
16 |
-
result: pd.DataFrame = func(*args, **kwargs)
|
17 |
-
if result is not None and not result.empty:
|
18 |
-
d = {"expiry": time.time(), "data": result}
|
19 |
-
CACHE[cache_key] = d
|
20 |
-
return result
|
21 |
-
|
22 |
-
CACHE[cache_key]["expiry"] += TTL
|
23 |
-
return CACHE[cache_key]["data"]
|
24 |
-
|
25 |
-
return wrapper
|
26 |
-
|
27 |
-
return decorator
|
28 |
-
|
29 |
-
|
30 |
-
def cache_dict_with_custom_key(cache_key: str):
|
31 |
-
def decorator(func):
|
32 |
-
@wraps(func)
|
33 |
-
def wrapper(*args, **kwargs):
|
34 |
-
if cache_key in CACHE and time.time() - CACHE[cache_key].get("expiry") < TTL:
|
35 |
-
return CACHE[cache_key]["data"]
|
36 |
-
|
37 |
-
result: dict = func(*args, **kwargs)
|
38 |
-
if result:
|
39 |
-
d = {"expiry": time.time(), "data": result}
|
40 |
-
CACHE[cache_key] = d
|
41 |
-
return result
|
42 |
-
|
43 |
-
CACHE[cache_key]["expiry"] += TTL
|
44 |
-
return CACHE[cache_key]["data"]
|
45 |
-
|
46 |
-
return wrapper
|
47 |
-
|
48 |
-
return decorator
|
49 |
-
|
50 |
-
|
51 |
-
if __name__ == '__main__':
|
52 |
-
a = time.time()
|
53 |
-
time.sleep(5)
|
54 |
-
print(time.time() - a)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/http_utils.py
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
|
3 |
-
|
4 |
-
def get(url: str, params: str = None, verify: bool = False):
|
5 |
-
return requests.get(url, params, verify=verify)
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/st_copy_to_clipboard/__init__.py
DELETED
@@ -1,66 +0,0 @@
|
|
1 |
-
from pathlib import Path
|
2 |
-
from typing import Optional
|
3 |
-
|
4 |
-
import streamlit as st
|
5 |
-
import streamlit.components.v1 as components
|
6 |
-
|
7 |
-
# Tell streamlit that there is a component called streamlit_copy_to_clipboard,
|
8 |
-
# and that the code to display that component is in the "frontend" folder
|
9 |
-
frontend_dir = (Path(__file__).parent / "frontend").absolute()
|
10 |
-
_component_func = components.declare_component(
|
11 |
-
"streamlit_copy_to_clipboard", path=str(frontend_dir)
|
12 |
-
)
|
13 |
-
|
14 |
-
|
15 |
-
def st_copy_to_clipboard(
|
16 |
-
text: str,
|
17 |
-
before_copy_label: str = "π",
|
18 |
-
after_copy_label: str = "β
",
|
19 |
-
show_text: bool = False,
|
20 |
-
key: Optional[str] = None,
|
21 |
-
theme: str = 'light', # default theme is 'light'
|
22 |
-
|
23 |
-
):
|
24 |
-
"""
|
25 |
-
Streamlit component to copy text to clipboard.
|
26 |
-
|
27 |
-
Parameters
|
28 |
-
----------
|
29 |
-
text : str
|
30 |
-
The text to be copied to the clipboard.
|
31 |
-
before_copy_label : str
|
32 |
-
Label of the button before text is copied.
|
33 |
-
after_copy_label : str
|
34 |
-
Label of the button after text is copied.
|
35 |
-
show_text: bool
|
36 |
-
If True, show text right before the button and make it clickable as well
|
37 |
-
key : str or None
|
38 |
-
An optional key that uniquely identifies the component.
|
39 |
-
theme: str
|
40 |
-
Set the current theme for the button.
|
41 |
-
"""
|
42 |
-
component_value = _component_func(
|
43 |
-
key=key,
|
44 |
-
text=text,
|
45 |
-
before_copy_label=before_copy_label,
|
46 |
-
after_copy_label=after_copy_label,
|
47 |
-
show_text=show_text,
|
48 |
-
theme=theme,
|
49 |
-
)
|
50 |
-
|
51 |
-
return component_value
|
52 |
-
|
53 |
-
|
54 |
-
def main():
|
55 |
-
st.write("## Example")
|
56 |
-
text = st.text_input("Enter text to copy to clipboard", value="Hello World")
|
57 |
-
st_copy_to_clipboard(text)
|
58 |
-
st_copy_to_clipboard(text, before_copy_label='πPush to copy', after_copy_label='β
Text copied!')
|
59 |
-
st_copy_to_clipboard(text, before_copy_label='Push to copy', after_copy_label='Text copied!', show_text=True)
|
60 |
-
st_copy_to_clipboard(text, before_copy_label='Push to copy', after_copy_label='copied!', show_text=True, theme="dark")
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
if __name__ == "__main__":
|
66 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/st_copy_to_clipboard/frontend/index.html
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8" />
|
5 |
-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
6 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
-
<title>st-copy-to-clipboard</title>
|
8 |
-
<script src="./streamlit-component-lib.js"></script>
|
9 |
-
<script src="./main.js"></script>
|
10 |
-
<link rel="stylesheet" href="./style.css" />
|
11 |
-
</head>
|
12 |
-
|
13 |
-
<body>
|
14 |
-
<div id="root">
|
15 |
-
<button id="text-element" class="st-copy-to-clipboard-btn"></button>
|
16 |
-
<button id="copy-button" class="st-copy-to-clipboard-btn">π</button>
|
17 |
-
</div>
|
18 |
-
</body>
|
19 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/st_copy_to_clipboard/frontend/main.js
DELETED
@@ -1,61 +0,0 @@
|
|
1 |
-
// The `Streamlit` object exists because our html file includes
|
2 |
-
// `streamlit-component-lib.js`.
|
3 |
-
// If you get an error about "Streamlit" not being defined, that
|
4 |
-
// means you're missing that file.
|
5 |
-
|
6 |
-
function sendValue(value) {
|
7 |
-
Streamlit.setComponentValue(value);
|
8 |
-
}
|
9 |
-
|
10 |
-
/**
|
11 |
-
* The component's render function. This will be called immediately after
|
12 |
-
* the component is initially loaded, and then again every time the
|
13 |
-
* component gets new data from Python.
|
14 |
-
*/
|
15 |
-
function onRender(event) {
|
16 |
-
// Only run the render code the first time the component is loaded.
|
17 |
-
if (!window.rendered) {
|
18 |
-
const { text, before_copy_label, after_copy_label, show_text, theme } = event.detail.args;
|
19 |
-
|
20 |
-
const container = document.querySelector('#container');
|
21 |
-
const button = document.querySelector('#copy-button');
|
22 |
-
const textElement = document.querySelector('#text-element');
|
23 |
-
|
24 |
-
if (theme == 'dark') {
|
25 |
-
button.style.border = '1px solid rgba(250, 250, 250, 0.2)';
|
26 |
-
button.style.color = 'white';
|
27 |
-
}
|
28 |
-
|
29 |
-
button.textContent = before_copy_label; // Set initial label
|
30 |
-
|
31 |
-
// Show text if show_text is true
|
32 |
-
if (show_text) {
|
33 |
-
textElement.textContent = text;
|
34 |
-
textElement.style.display = 'inline';
|
35 |
-
} else {
|
36 |
-
textElement.style.display = 'none';
|
37 |
-
}
|
38 |
-
|
39 |
-
function copyToClipboard() {
|
40 |
-
navigator.clipboard.writeText(text);
|
41 |
-
|
42 |
-
button.textContent = after_copy_label; // Change label after copying
|
43 |
-
|
44 |
-
setTimeout(() => {
|
45 |
-
if (!button) return;
|
46 |
-
button.textContent = before_copy_label; // Revert to original label after 1 second
|
47 |
-
}, 1000);
|
48 |
-
}
|
49 |
-
button.addEventListener('click', copyToClipboard);
|
50 |
-
textElement.addEventListener('click', copyToClipboard);
|
51 |
-
|
52 |
-
window.rendered = true;
|
53 |
-
}
|
54 |
-
}
|
55 |
-
|
56 |
-
// Render the component whenever python send a "render event"
|
57 |
-
Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, onRender);
|
58 |
-
// Tell Streamlit that the component is ready to receive events
|
59 |
-
Streamlit.setComponentReady();
|
60 |
-
// Render with the correct height, if this is a fixed-height component
|
61 |
-
Streamlit.setFrameHeight(100);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/st_copy_to_clipboard/frontend/streamlit-component-lib.js
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
// Borrowed minimalistic Streamlit API from Thiago
|
2 |
-
// https://discuss.streamlit.io/t/code-snippet-create-components-without-any-frontend-tooling-no-react-babel-webpack-etc/13064
|
3 |
-
function sendMessageToStreamlitClient(type, data) {
|
4 |
-
console.log(type, data);
|
5 |
-
const outData = Object.assign(
|
6 |
-
{
|
7 |
-
isStreamlitMessage: true,
|
8 |
-
type: type,
|
9 |
-
},
|
10 |
-
data
|
11 |
-
);
|
12 |
-
window.parent.postMessage(outData, '*');
|
13 |
-
}
|
14 |
-
|
15 |
-
const Streamlit = {
|
16 |
-
setComponentReady: function () {
|
17 |
-
sendMessageToStreamlitClient('streamlit:componentReady', { apiVersion: 1 });
|
18 |
-
},
|
19 |
-
setFrameHeight: function (height) {
|
20 |
-
sendMessageToStreamlitClient('streamlit:setFrameHeight', { height: height });
|
21 |
-
},
|
22 |
-
setComponentValue: function (value) {
|
23 |
-
sendMessageToStreamlitClient('streamlit:setComponentValue', { value: value });
|
24 |
-
},
|
25 |
-
RENDER_EVENT: 'streamlit:render',
|
26 |
-
events: {
|
27 |
-
addEventListener: function (type, callback) {
|
28 |
-
window.addEventListener('message', function (event) {
|
29 |
-
if (event.data.type === type) {
|
30 |
-
event.detail = event.data;
|
31 |
-
callback(event);
|
32 |
-
}
|
33 |
-
});
|
34 |
-
},
|
35 |
-
},
|
36 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/st_copy_to_clipboard/frontend/style.css
DELETED
@@ -1,31 +0,0 @@
|
|
1 |
-
.st-copy-to-clipboard-btn {
|
2 |
-
display: inline-flex;
|
3 |
-
-moz-box-align: center;
|
4 |
-
align-items: center;
|
5 |
-
-moz-box-pack: center;
|
6 |
-
justify-content: center;
|
7 |
-
font-weight: 400;
|
8 |
-
padding: 0.25rem 0.75rem;
|
9 |
-
border-radius: 0.5rem;
|
10 |
-
min-height: 38.4px;
|
11 |
-
margin: 0px;
|
12 |
-
line-height: 1.6;
|
13 |
-
color: inherit;
|
14 |
-
width: auto;
|
15 |
-
user-select: none;
|
16 |
-
background-color: transparent; /* set bgcolor to transparent to adjust to any theme */
|
17 |
-
border: 1px solid rgba(49, 51, 63, 0.2);
|
18 |
-
cursor: pointer;
|
19 |
-
float: right;
|
20 |
-
}
|
21 |
-
|
22 |
-
.st-copy-to-clipboard-btn:hover {
|
23 |
-
border-color: rgb(255, 75, 75);
|
24 |
-
color: rgb(255, 75, 75);
|
25 |
-
}
|
26 |
-
|
27 |
-
.st-copy-to-clipboard-btn:active {
|
28 |
-
border-color: rgb(255, 75, 75);
|
29 |
-
background-color: rgb(255, 75, 75);
|
30 |
-
color: rgb(255, 255, 255);
|
31 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|