Spaces:
Running
Running
Kang Suhyun
commited on
Commit
•
740b104
1
Parent(s):
60e8d65
[#81] Add "Any" option to tranlation leaderboard filter (#82)
Browse filesThis change adds an "Any" option to the translation leaderboard filter.
Screenshot: https://screen.yanolja.in/vFl5CYnMuRYGgXlF.png
- leaderboard.py +20 -9
leaderboard.py
CHANGED
@@ -24,6 +24,8 @@ SUPPORTED_TRANSLATION_LANGUAGES = [
|
|
24 |
language.name.capitalize() for language in lingua.Language.all()
|
25 |
]
|
26 |
|
|
|
|
|
27 |
|
28 |
class LeaderboardTab(enum.Enum):
|
29 |
SUMMARIZATION = "Summarization"
|
@@ -68,11 +70,11 @@ def get_docs(tab: str,
|
|
68 |
if tab == LeaderboardTab.TRANSLATION:
|
69 |
collection = db.collection("arena-translations").order_by("timestamp")
|
70 |
|
71 |
-
if source_lang:
|
72 |
collection = collection.where(filter=base_query.FieldFilter(
|
73 |
"source_language", "==", source_lang.lower()))
|
74 |
|
75 |
-
if target_lang:
|
76 |
collection = collection.where(filter=base_query.FieldFilter(
|
77 |
"target_language", "==", target_lang.lower()))
|
78 |
|
@@ -109,9 +111,9 @@ LEADERBOARD_UPDATE_INTERVAL = 600 # 10 minutes
|
|
109 |
LEADERBOARD_INFO = "The leaderboard is updated every 10 minutes."
|
110 |
|
111 |
DEFAULT_FILTER_OPTIONS = {
|
112 |
-
"summary_language":
|
113 |
-
"source_language":
|
114 |
-
"target_language":
|
115 |
}
|
116 |
|
117 |
|
@@ -124,7 +126,7 @@ def update_filtered_leaderboard(tab, summary_lang: str, source_lang: str,
|
|
124 |
def build_leaderboard():
|
125 |
with gr.Tabs():
|
126 |
with gr.Tab(LeaderboardTab.SUMMARIZATION.value):
|
127 |
-
with gr.Accordion("Filter", open=False):
|
128 |
with gr.Row():
|
129 |
languages = [
|
130 |
language.name.capitalize() for language in lingua.Language.all()
|
@@ -161,15 +163,15 @@ def build_leaderboard():
|
|
161 |
gr.Markdown(LEADERBOARD_INFO)
|
162 |
|
163 |
with gr.Tab(LeaderboardTab.TRANSLATION.value):
|
164 |
-
with gr.Accordion("Filter", open=False):
|
165 |
with gr.Row():
|
166 |
source_language = gr.Dropdown(
|
167 |
-
choices=SUPPORTED_TRANSLATION_LANGUAGES,
|
168 |
label="Source language",
|
169 |
value=DEFAULT_FILTER_OPTIONS["source_language"],
|
170 |
interactive=True)
|
171 |
target_language = gr.Dropdown(
|
172 |
-
choices=SUPPORTED_TRANSLATION_LANGUAGES,
|
173 |
label="Target language",
|
174 |
value=DEFAULT_FILTER_OPTIONS["target_language"],
|
175 |
interactive=True)
|
@@ -199,6 +201,15 @@ def build_leaderboard():
|
|
199 |
],
|
200 |
outputs=filtered_translation)
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
gr.Dataframe(headers=["Rank", "Model", "Elo rating"],
|
203 |
datatype=["number", "str", "number"],
|
204 |
value=lambda: load_elo_ratings(LeaderboardTab.TRANSLATION),
|
|
|
24 |
language.name.capitalize() for language in lingua.Language.all()
|
25 |
]
|
26 |
|
27 |
+
ANY_LANGUAGE = "Any"
|
28 |
+
|
29 |
|
30 |
class LeaderboardTab(enum.Enum):
|
31 |
SUMMARIZATION = "Summarization"
|
|
|
70 |
if tab == LeaderboardTab.TRANSLATION:
|
71 |
collection = db.collection("arena-translations").order_by("timestamp")
|
72 |
|
73 |
+
if source_lang and (not source_lang == ANY_LANGUAGE):
|
74 |
collection = collection.where(filter=base_query.FieldFilter(
|
75 |
"source_language", "==", source_lang.lower()))
|
76 |
|
77 |
+
if target_lang and (not target_lang == ANY_LANGUAGE):
|
78 |
collection = collection.where(filter=base_query.FieldFilter(
|
79 |
"target_language", "==", target_lang.lower()))
|
80 |
|
|
|
111 |
LEADERBOARD_INFO = "The leaderboard is updated every 10 minutes."
|
112 |
|
113 |
DEFAULT_FILTER_OPTIONS = {
|
114 |
+
"summary_language": lingua.Language.ENGLISH.name.capitalize(),
|
115 |
+
"source_language": ANY_LANGUAGE,
|
116 |
+
"target_language": lingua.Language.ENGLISH.name.capitalize()
|
117 |
}
|
118 |
|
119 |
|
|
|
126 |
def build_leaderboard():
|
127 |
with gr.Tabs():
|
128 |
with gr.Tab(LeaderboardTab.SUMMARIZATION.value):
|
129 |
+
with gr.Accordion("Filter", open=False) as summarization_filter:
|
130 |
with gr.Row():
|
131 |
languages = [
|
132 |
language.name.capitalize() for language in lingua.Language.all()
|
|
|
163 |
gr.Markdown(LEADERBOARD_INFO)
|
164 |
|
165 |
with gr.Tab(LeaderboardTab.TRANSLATION.value):
|
166 |
+
with gr.Accordion("Filter", open=False) as translation_filter:
|
167 |
with gr.Row():
|
168 |
source_language = gr.Dropdown(
|
169 |
+
choices=SUPPORTED_TRANSLATION_LANGUAGES + [ANY_LANGUAGE],
|
170 |
label="Source language",
|
171 |
value=DEFAULT_FILTER_OPTIONS["source_language"],
|
172 |
interactive=True)
|
173 |
target_language = gr.Dropdown(
|
174 |
+
choices=SUPPORTED_TRANSLATION_LANGUAGES + [ANY_LANGUAGE],
|
175 |
label="Target language",
|
176 |
value=DEFAULT_FILTER_OPTIONS["target_language"],
|
177 |
interactive=True)
|
|
|
201 |
],
|
202 |
outputs=filtered_translation)
|
203 |
|
204 |
+
# When filter options are changed, the accordion keeps closed.
|
205 |
+
# To avoid this, we open the accordion when the filter options are changed.
|
206 |
+
summary_language.change(fn=lambda: gr.Accordion(open=True),
|
207 |
+
outputs=summarization_filter)
|
208 |
+
source_language.change(fn=lambda: gr.Accordion(open=True),
|
209 |
+
outputs=translation_filter)
|
210 |
+
target_language.change(fn=lambda: gr.Accordion(open=True),
|
211 |
+
outputs=translation_filter)
|
212 |
+
|
213 |
gr.Dataframe(headers=["Rank", "Model", "Elo rating"],
|
214 |
datatype=["number", "str", "number"],
|
215 |
value=lambda: load_elo_ratings(LeaderboardTab.TRANSLATION),
|