DontPlanToEnd
commited on
Commit
β’
7d3a3f0
1
Parent(s):
c2d384b
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
-
import json
|
5 |
from functools import partial
|
6 |
|
7 |
custom_css = """
|
@@ -36,72 +35,8 @@ custom_css = """
|
|
36 |
.default-underline {
|
37 |
text-decoration: underline !important;
|
38 |
}
|
39 |
-
.customrangeslider {
|
40 |
-
display: flex;
|
41 |
-
flex-direction: column;
|
42 |
-
width: 100%;
|
43 |
-
}
|
44 |
-
.customrangeslider input[type="range"] {
|
45 |
-
-webkit-appearance: none;
|
46 |
-
width: 100%;
|
47 |
-
height: 10px;
|
48 |
-
border-radius: 5px;
|
49 |
-
background: #d3d3d3;
|
50 |
-
outline: none;
|
51 |
-
opacity: 0.7;
|
52 |
-
transition: opacity .2s;
|
53 |
-
}
|
54 |
-
.customrangeslider input[type="range"]::-webkit-slider-thumb {
|
55 |
-
-webkit-appearance: none;
|
56 |
-
appearance: none;
|
57 |
-
width: 20px;
|
58 |
-
height: 20px;
|
59 |
-
border-radius: 50%;
|
60 |
-
background: #4CAF50;
|
61 |
-
cursor: pointer;
|
62 |
-
}
|
63 |
-
.customrangeslider input[type="range"]::-moz-range-thumb {
|
64 |
-
width: 20px;
|
65 |
-
height: 20px;
|
66 |
-
border-radius: 50%;
|
67 |
-
background: #4CAF50;
|
68 |
-
cursor: pointer;
|
69 |
-
}
|
70 |
"""
|
71 |
|
72 |
-
class CustomRangeSlider(gr.components.Component):
|
73 |
-
def __init__(self, minimum, maximum, value, step, label):
|
74 |
-
super().__init__(self)
|
75 |
-
self.minimum = minimum
|
76 |
-
self.maximum = maximum
|
77 |
-
self.value = value
|
78 |
-
self.step = step
|
79 |
-
self.label = label
|
80 |
-
|
81 |
-
def get_template_context(self):
|
82 |
-
return {
|
83 |
-
"min": self.minimum,
|
84 |
-
"max": self.maximum,
|
85 |
-
"value": self.value,
|
86 |
-
"step": self.step,
|
87 |
-
"label": self.label,
|
88 |
-
}
|
89 |
-
|
90 |
-
@classmethod
|
91 |
-
def get_component_instance(cls, props):
|
92 |
-
return cls(**props)
|
93 |
-
|
94 |
-
def preprocess(self, x):
|
95 |
-
return json.loads(x)
|
96 |
-
|
97 |
-
def postprocess(self, y):
|
98 |
-
return json.dumps(y)
|
99 |
-
|
100 |
-
def get_block_name(self):
|
101 |
-
return "customrangeslider"
|
102 |
-
|
103 |
-
gr.components.Component.register_component("customrangeslider")(CustomRangeSlider)
|
104 |
-
|
105 |
# Define the columns for the different leaderboards
|
106 |
UGI_COLS = ['#P', 'Model', 'UGI π', 'W/10 π', 'Unruly', 'Internet', 'Stats', 'Writing', 'PolContro']
|
107 |
WRITING_STYLE_COLS = ['#P', 'Model', 'Reg+MyScore π', 'Reg+Int π', 'MyScore π', 'ASSSβ¬οΈ', 'SMOGβ¬οΈ', 'Yuleβ¬οΈ']
|
@@ -128,7 +63,7 @@ def load_leaderboard_data(csv_file_path):
|
|
128 |
return pd.DataFrame(columns=UGI_COLS + WRITING_STYLE_COLS + ANIME_RATING_COLS)
|
129 |
|
130 |
# Update the leaderboard table based on the search query and parameter range filters
|
131 |
-
def update_table(df: pd.DataFrame, query: str, param_ranges: list, columns: list,
|
132 |
filtered_df = df.copy()
|
133 |
if param_ranges:
|
134 |
param_mask = pd.Series(False, index=filtered_df.index)
|
@@ -156,7 +91,7 @@ def update_table(df: pd.DataFrame, query: str, param_ranges: list, columns: list
|
|
156 |
|
157 |
# Apply W/10 filtering
|
158 |
if 'W/10 π' in filtered_df.columns:
|
159 |
-
filtered_df = filtered_df[(filtered_df['W/10 π'] >=
|
160 |
|
161 |
return filtered_df[columns]
|
162 |
|
@@ -191,7 +126,8 @@ with GraInter:
|
|
191 |
elem_id="filter-columns-size",
|
192 |
)
|
193 |
with gr.Row():
|
194 |
-
|
|
|
195 |
|
196 |
# Load the initial leaderboard data
|
197 |
leaderboard_df = load_leaderboard_data("ugi-leaderboard-data.csv")
|
@@ -311,36 +247,42 @@ with GraInter:
|
|
311 |
**NA:** When models either reply with one number for every anime, give ratings not between 1 and 10, or don't give every anime in the list a rating.
|
312 |
""")
|
313 |
|
314 |
-
def update_all_tables(query, param_ranges,
|
315 |
-
ugi_table = update_table(leaderboard_df, query, param_ranges, UGI_COLS,
|
316 |
|
317 |
ws_df = leaderboard_df.sort_values(by='Reg+MyScore π', ascending=False)
|
318 |
-
ws_table = update_table(ws_df, query, param_ranges, WRITING_STYLE_COLS,
|
319 |
|
320 |
arp_df = leaderboard_df.sort_values(by='Score π', ascending=False)
|
321 |
arp_df_na = arp_df[arp_df[['Dif', 'Cor']].isna().any(axis=1)]
|
322 |
arp_df = arp_df[~arp_df[['Dif', 'Cor']].isna().any(axis=1)]
|
323 |
|
324 |
-
arp_table = update_table(arp_df, query, param_ranges, ANIME_RATING_COLS,
|
325 |
-
arp_na_table = update_table(arp_df_na, query, param_ranges, ANIME_RATING_COLS,
|
326 |
|
327 |
return ugi_table, ws_table, arp_table, arp_na_table
|
328 |
|
329 |
search_bar.change(
|
330 |
fn=update_all_tables,
|
331 |
-
inputs=[search_bar, filter_columns_size,
|
332 |
outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
|
333 |
)
|
334 |
|
335 |
filter_columns_size.change(
|
336 |
fn=update_all_tables,
|
337 |
-
inputs=[search_bar, filter_columns_size,
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
|
339 |
)
|
340 |
|
341 |
-
|
342 |
fn=update_all_tables,
|
343 |
-
inputs=[search_bar, filter_columns_size,
|
344 |
outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
|
345 |
)
|
346 |
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
|
|
4 |
from functools import partial
|
5 |
|
6 |
custom_css = """
|
|
|
35 |
.default-underline {
|
36 |
text-decoration: underline !important;
|
37 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
"""
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# Define the columns for the different leaderboards
|
41 |
UGI_COLS = ['#P', 'Model', 'UGI π', 'W/10 π', 'Unruly', 'Internet', 'Stats', 'Writing', 'PolContro']
|
42 |
WRITING_STYLE_COLS = ['#P', 'Model', 'Reg+MyScore π', 'Reg+Int π', 'MyScore π', 'ASSSβ¬οΈ', 'SMOGβ¬οΈ', 'Yuleβ¬οΈ']
|
|
|
63 |
return pd.DataFrame(columns=UGI_COLS + WRITING_STYLE_COLS + ANIME_RATING_COLS)
|
64 |
|
65 |
# Update the leaderboard table based on the search query and parameter range filters
|
66 |
+
def update_table(df: pd.DataFrame, query: str, param_ranges: list, columns: list, w10_min: float, w10_max: float) -> pd.DataFrame:
|
67 |
filtered_df = df.copy()
|
68 |
if param_ranges:
|
69 |
param_mask = pd.Series(False, index=filtered_df.index)
|
|
|
91 |
|
92 |
# Apply W/10 filtering
|
93 |
if 'W/10 π' in filtered_df.columns:
|
94 |
+
filtered_df = filtered_df[(filtered_df['W/10 π'] >= w10_min) & (filtered_df['W/10 π'] <= w10_max)]
|
95 |
|
96 |
return filtered_df[columns]
|
97 |
|
|
|
126 |
elem_id="filter-columns-size",
|
127 |
)
|
128 |
with gr.Row():
|
129 |
+
w10_min = gr.Slider(minimum=0, maximum=10, value=0, step=0.1, label="Min W/10")
|
130 |
+
w10_max = gr.Slider(minimum=0, maximum=10, value=10, step=0.1, label="Max W/10")
|
131 |
|
132 |
# Load the initial leaderboard data
|
133 |
leaderboard_df = load_leaderboard_data("ugi-leaderboard-data.csv")
|
|
|
247 |
**NA:** When models either reply with one number for every anime, give ratings not between 1 and 10, or don't give every anime in the list a rating.
|
248 |
""")
|
249 |
|
250 |
+
def update_all_tables(query, param_ranges, w10_min, w10_max):
|
251 |
+
ugi_table = update_table(leaderboard_df, query, param_ranges, UGI_COLS, w10_min, w10_max)
|
252 |
|
253 |
ws_df = leaderboard_df.sort_values(by='Reg+MyScore π', ascending=False)
|
254 |
+
ws_table = update_table(ws_df, query, param_ranges, WRITING_STYLE_COLS, w10_min, w10_max)
|
255 |
|
256 |
arp_df = leaderboard_df.sort_values(by='Score π', ascending=False)
|
257 |
arp_df_na = arp_df[arp_df[['Dif', 'Cor']].isna().any(axis=1)]
|
258 |
arp_df = arp_df[~arp_df[['Dif', 'Cor']].isna().any(axis=1)]
|
259 |
|
260 |
+
arp_table = update_table(arp_df, query, param_ranges, ANIME_RATING_COLS, w10_min, w10_max)
|
261 |
+
arp_na_table = update_table(arp_df_na, query, param_ranges, ANIME_RATING_COLS, w10_min, w10_max).fillna('NA')
|
262 |
|
263 |
return ugi_table, ws_table, arp_table, arp_na_table
|
264 |
|
265 |
search_bar.change(
|
266 |
fn=update_all_tables,
|
267 |
+
inputs=[search_bar, filter_columns_size, w10_min, w10_max],
|
268 |
outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
|
269 |
)
|
270 |
|
271 |
filter_columns_size.change(
|
272 |
fn=update_all_tables,
|
273 |
+
inputs=[search_bar, filter_columns_size, w10_min, w10_max],
|
274 |
+
outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
|
275 |
+
)
|
276 |
+
|
277 |
+
w10_min.change(
|
278 |
+
fn=update_all_tables,
|
279 |
+
inputs=[search_bar, filter_columns_size, w10_min, w10_max],
|
280 |
outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
|
281 |
)
|
282 |
|
283 |
+
w10_max.change(
|
284 |
fn=update_all_tables,
|
285 |
+
inputs=[search_bar, filter_columns_size, w10_min, w10_max],
|
286 |
outputs=[leaderboard_table_ugi, leaderboard_table_ws, leaderboard_table_arp, leaderboard_table_arp_na]
|
287 |
)
|
288 |
|