Spaces:
Sleeping
Sleeping
adding sorting
Browse files- __pycache__/about.cpython-310.pyc +0 -0
- app.py +88 -30
__pycache__/about.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/about.cpython-310.pyc and b/__pycache__/about.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -24,26 +24,33 @@ def get_leaderboard():
|
|
| 24 |
|
| 25 |
return full_df
|
| 26 |
|
| 27 |
-
def format_dataframe(df, show_percentage=False, selected_groups=None):
|
| 28 |
"""Format the dataframe with proper column names and optional percentages."""
|
| 29 |
if len(df) == 0:
|
| 30 |
return df
|
| 31 |
|
| 32 |
-
# Build column list based on
|
| 33 |
selected_cols = ['run_name']
|
| 34 |
-
if 'n_structures' in df.columns:
|
| 35 |
-
selected_cols.append('n_structures')
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Create a copy with selected columns
|
| 49 |
display_df = df[selected_cols].copy()
|
|
@@ -93,10 +100,25 @@ def apply_color_styling(display_df, original_cols):
|
|
| 93 |
# Apply the styling function
|
| 94 |
return display_df.style.apply(style_by_group, axis=None)
|
| 95 |
|
| 96 |
-
def update_leaderboard(show_percentage, selected_groups):
|
| 97 |
-
"""Update the leaderboard based on user selections.
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
return formatted_df
|
| 101 |
|
| 102 |
def show_output_box(message):
|
|
@@ -149,28 +171,49 @@ def gradio_interface() -> gr.Blocks:
|
|
| 149 |
|
| 150 |
# Display options
|
| 151 |
with gr.Row():
|
| 152 |
-
with gr.Column(scale=2):
|
| 153 |
-
selected_groups = gr.CheckboxGroup(
|
| 154 |
-
choices=list(METRIC_GROUPS.keys()),
|
| 155 |
-
value=list(METRIC_GROUPS.keys()),
|
| 156 |
-
label="Metric Families",
|
| 157 |
-
info="Select which metric groups to display"
|
| 158 |
-
)
|
| 159 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
show_percentage = gr.Checkbox(
|
| 161 |
value=True,
|
| 162 |
label="Show as Percentages",
|
| 163 |
info="Display count-based metrics as percentages of total structures"
|
| 164 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
# Metric legend with color coding
|
| 167 |
with gr.Accordion("Metric Groups Legend", open=False):
|
| 168 |
gr.HTML(generate_metric_legend_html())
|
| 169 |
|
| 170 |
try:
|
| 171 |
-
# Initial dataframe
|
| 172 |
initial_df = get_leaderboard()
|
| 173 |
-
|
|
|
|
|
|
|
| 174 |
|
| 175 |
leaderboard_table = gr.Dataframe(
|
| 176 |
label="GenBench Leaderboard",
|
|
@@ -181,15 +224,30 @@ def gradio_interface() -> gr.Blocks:
|
|
| 181 |
show_fullscreen_button=True
|
| 182 |
)
|
| 183 |
|
| 184 |
-
# Update dataframe when options change
|
| 185 |
show_percentage.change(
|
| 186 |
fn=update_leaderboard,
|
| 187 |
-
inputs=[show_percentage, selected_groups],
|
| 188 |
outputs=leaderboard_table
|
| 189 |
)
|
| 190 |
selected_groups.change(
|
| 191 |
fn=update_leaderboard,
|
| 192 |
-
inputs=[show_percentage, selected_groups],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
outputs=leaderboard_table
|
| 194 |
)
|
| 195 |
|
|
|
|
| 24 |
|
| 25 |
return full_df
|
| 26 |
|
| 27 |
+
def format_dataframe(df, show_percentage=False, selected_groups=None, compact_view=True):
|
| 28 |
"""Format the dataframe with proper column names and optional percentages."""
|
| 29 |
if len(df) == 0:
|
| 30 |
return df
|
| 31 |
|
| 32 |
+
# Build column list based on view mode
|
| 33 |
selected_cols = ['run_name']
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
if compact_view:
|
| 36 |
+
# Use predefined compact columns
|
| 37 |
+
from about import COMPACT_VIEW_COLUMNS
|
| 38 |
+
selected_cols = [col for col in COMPACT_VIEW_COLUMNS if col in df.columns]
|
| 39 |
+
else:
|
| 40 |
+
# Build from selected groups
|
| 41 |
+
if 'n_structures' in df.columns:
|
| 42 |
+
selected_cols.append('n_structures')
|
| 43 |
+
|
| 44 |
+
# If no groups selected, show all
|
| 45 |
+
if not selected_groups:
|
| 46 |
+
selected_groups = list(METRIC_GROUPS.keys())
|
| 47 |
+
|
| 48 |
+
# Add columns from selected groups
|
| 49 |
+
for group in selected_groups:
|
| 50 |
+
if group in METRIC_GROUPS:
|
| 51 |
+
for col in METRIC_GROUPS[group]:
|
| 52 |
+
if col in df.columns and col not in selected_cols:
|
| 53 |
+
selected_cols.append(col)
|
| 54 |
|
| 55 |
# Create a copy with selected columns
|
| 56 |
display_df = df[selected_cols].copy()
|
|
|
|
| 100 |
# Apply the styling function
|
| 101 |
return display_df.style.apply(style_by_group, axis=None)
|
| 102 |
|
| 103 |
+
def update_leaderboard(show_percentage, selected_groups, compact_view, cached_df, sort_by, sort_direction):
|
| 104 |
+
"""Update the leaderboard based on user selections.
|
| 105 |
+
|
| 106 |
+
Uses cached dataframe to avoid re-downloading data on every change.
|
| 107 |
+
"""
|
| 108 |
+
# Use cached dataframe instead of re-downloading
|
| 109 |
+
df_to_format = cached_df.copy()
|
| 110 |
+
|
| 111 |
+
# Convert display name back to raw column name for sorting
|
| 112 |
+
if sort_by and sort_by != "None":
|
| 113 |
+
# Create reverse mapping from display names to raw column names
|
| 114 |
+
display_to_raw = {v: k for k, v in COLUMN_DISPLAY_NAMES.items()}
|
| 115 |
+
raw_column_name = display_to_raw.get(sort_by, sort_by)
|
| 116 |
+
|
| 117 |
+
if raw_column_name in df_to_format.columns:
|
| 118 |
+
ascending = (sort_direction == "Ascending")
|
| 119 |
+
df_to_format = df_to_format.sort_values(by=raw_column_name, ascending=ascending)
|
| 120 |
+
|
| 121 |
+
formatted_df = format_dataframe(df_to_format, show_percentage, selected_groups, compact_view)
|
| 122 |
return formatted_df
|
| 123 |
|
| 124 |
def show_output_box(message):
|
|
|
|
| 171 |
|
| 172 |
# Display options
|
| 173 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
with gr.Column(scale=1):
|
| 175 |
+
compact_view = gr.Checkbox(
|
| 176 |
+
value=True,
|
| 177 |
+
label="Compact View",
|
| 178 |
+
info="Show only key metrics"
|
| 179 |
+
)
|
| 180 |
show_percentage = gr.Checkbox(
|
| 181 |
value=True,
|
| 182 |
label="Show as Percentages",
|
| 183 |
info="Display count-based metrics as percentages of total structures"
|
| 184 |
)
|
| 185 |
+
with gr.Column(scale=1):
|
| 186 |
+
# Create choices with display names, but values are the raw column names
|
| 187 |
+
sort_choices = ["None"] + [COLUMN_DISPLAY_NAMES.get(col, col) for col in COLUMN_DISPLAY_NAMES.keys()]
|
| 188 |
+
sort_by = gr.Dropdown(
|
| 189 |
+
choices=sort_choices,
|
| 190 |
+
value="None",
|
| 191 |
+
label="Sort By",
|
| 192 |
+
info="Select column to sort by"
|
| 193 |
+
)
|
| 194 |
+
sort_direction = gr.Radio(
|
| 195 |
+
choices=["Ascending", "Descending"],
|
| 196 |
+
value="Descending",
|
| 197 |
+
label="Sort Direction"
|
| 198 |
+
)
|
| 199 |
+
with gr.Column(scale=2):
|
| 200 |
+
selected_groups = gr.CheckboxGroup(
|
| 201 |
+
choices=list(METRIC_GROUPS.keys()),
|
| 202 |
+
value=list(METRIC_GROUPS.keys()),
|
| 203 |
+
label="Metric Families (only active when Compact View is off)",
|
| 204 |
+
info="Select which metric groups to display"
|
| 205 |
+
)
|
| 206 |
|
| 207 |
# Metric legend with color coding
|
| 208 |
with gr.Accordion("Metric Groups Legend", open=False):
|
| 209 |
gr.HTML(generate_metric_legend_html())
|
| 210 |
|
| 211 |
try:
|
| 212 |
+
# Initial dataframe - load once and cache
|
| 213 |
initial_df = get_leaderboard()
|
| 214 |
+
cached_df_state = gr.State(initial_df)
|
| 215 |
+
|
| 216 |
+
formatted_df = format_dataframe(initial_df, show_percentage=True, selected_groups=list(METRIC_GROUPS.keys()), compact_view=True)
|
| 217 |
|
| 218 |
leaderboard_table = gr.Dataframe(
|
| 219 |
label="GenBench Leaderboard",
|
|
|
|
| 224 |
show_fullscreen_button=True
|
| 225 |
)
|
| 226 |
|
| 227 |
+
# Update dataframe when options change (using cached data)
|
| 228 |
show_percentage.change(
|
| 229 |
fn=update_leaderboard,
|
| 230 |
+
inputs=[show_percentage, selected_groups, compact_view, cached_df_state, sort_by, sort_direction],
|
| 231 |
outputs=leaderboard_table
|
| 232 |
)
|
| 233 |
selected_groups.change(
|
| 234 |
fn=update_leaderboard,
|
| 235 |
+
inputs=[show_percentage, selected_groups, compact_view, cached_df_state, sort_by, sort_direction],
|
| 236 |
+
outputs=leaderboard_table
|
| 237 |
+
)
|
| 238 |
+
compact_view.change(
|
| 239 |
+
fn=update_leaderboard,
|
| 240 |
+
inputs=[show_percentage, selected_groups, compact_view, cached_df_state, sort_by, sort_direction],
|
| 241 |
+
outputs=leaderboard_table
|
| 242 |
+
)
|
| 243 |
+
sort_by.change(
|
| 244 |
+
fn=update_leaderboard,
|
| 245 |
+
inputs=[show_percentage, selected_groups, compact_view, cached_df_state, sort_by, sort_direction],
|
| 246 |
+
outputs=leaderboard_table
|
| 247 |
+
)
|
| 248 |
+
sort_direction.change(
|
| 249 |
+
fn=update_leaderboard,
|
| 250 |
+
inputs=[show_percentage, selected_groups, compact_view, cached_df_state, sort_by, sort_direction],
|
| 251 |
outputs=leaderboard_table
|
| 252 |
)
|
| 253 |
|