Spaces:
Running
Running
Add show_all_labels parameter and checkbox handler to update_display functions
#19
by juan-all-hands - opened
- ui_components.py +23 -43
ui_components.py
CHANGED
|
@@ -705,7 +705,7 @@ def create_leaderboard_display(
|
|
| 705 |
primary_runtime_col = f"{category_name} Runtime"
|
| 706 |
|
| 707 |
# Function to create cost/performance scatter plot from data
|
| 708 |
-
def create_cost_scatter_plot(df_data, mark_by=MARK_BY_DEFAULT
|
| 709 |
return _plot_scatter_plotly(
|
| 710 |
data=df_data,
|
| 711 |
x=primary_cost_col if primary_cost_col in df_data.columns else None,
|
|
@@ -713,12 +713,11 @@ def create_leaderboard_display(
|
|
| 713 |
agent_col="SDK Version",
|
| 714 |
name=category_name,
|
| 715 |
plot_type='cost',
|
| 716 |
-
mark_by=mark_by
|
| 717 |
-
show_all_labels=show_all_labels
|
| 718 |
)
|
| 719 |
|
| 720 |
# Function to create runtime/performance scatter plot from data
|
| 721 |
-
def create_runtime_scatter_plot(df_data, mark_by=MARK_BY_DEFAULT
|
| 722 |
return _plot_scatter_plotly(
|
| 723 |
data=df_data,
|
| 724 |
x=primary_runtime_col if primary_runtime_col in df_data.columns else None,
|
|
@@ -726,8 +725,7 @@ def create_leaderboard_display(
|
|
| 726 |
agent_col="SDK Version",
|
| 727 |
name=category_name,
|
| 728 |
plot_type='runtime',
|
| 729 |
-
mark_by=mark_by
|
| 730 |
-
show_all_labels=show_all_labels
|
| 731 |
)
|
| 732 |
|
| 733 |
# Create initial cost scatter plots for all filter combinations
|
|
@@ -774,7 +772,7 @@ def create_leaderboard_display(
|
|
| 774 |
|
| 775 |
# Add toggle checkboxes and dropdown ABOVE the plot
|
| 776 |
with gr.Row():
|
| 777 |
-
with gr.Column(scale=3):
|
| 778 |
if has_complete_entries:
|
| 779 |
show_incomplete_checkbox = gr.Checkbox(
|
| 780 |
label=f"Show incomplete entries ({num_incomplete} entries with fewer than 5 categories)",
|
|
@@ -794,13 +792,6 @@ def create_leaderboard_display(
|
|
| 794 |
)
|
| 795 |
else:
|
| 796 |
show_open_only_checkbox = None
|
| 797 |
-
|
| 798 |
-
# Add checkbox for showing all labels on scatter plot
|
| 799 |
-
show_all_labels_checkbox = gr.Checkbox(
|
| 800 |
-
label="Show all labels on scatter plots",
|
| 801 |
-
value=False,
|
| 802 |
-
elem_id="show-all-labels-toggle"
|
| 803 |
-
)
|
| 804 |
|
| 805 |
with gr.Column(scale=1):
|
| 806 |
mark_by_dropdown = gr.Dropdown(
|
|
@@ -853,7 +844,7 @@ def create_leaderboard_display(
|
|
| 853 |
df_to_show = df_display_all if show_incomplete else df_display_complete
|
| 854 |
view_df = df_view_full if show_incomplete else df_view_complete
|
| 855 |
|
| 856 |
-
# Regenerate plots with current mark_by
|
| 857 |
cost_plot = create_cost_scatter_plot(view_df, mark_by, show_all_labels)
|
| 858 |
runtime_plot = create_runtime_scatter_plot(view_df, mark_by, show_all_labels)
|
| 859 |
return df_to_show, cost_plot, runtime_plot
|
|
@@ -884,11 +875,6 @@ def create_leaderboard_display(
|
|
| 884 |
inputs=filter_inputs,
|
| 885 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 886 |
)
|
| 887 |
-
show_all_labels_checkbox.change(
|
| 888 |
-
fn=update_display,
|
| 889 |
-
inputs=filter_inputs,
|
| 890 |
-
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 891 |
-
)
|
| 892 |
else:
|
| 893 |
dataframe_component = gr.DataFrame(
|
| 894 |
headers=df_headers,
|
|
@@ -933,18 +919,13 @@ def create_leaderboard_display(
|
|
| 933 |
inputs=filter_inputs_no_complete,
|
| 934 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 935 |
)
|
| 936 |
-
show_all_labels_checkbox.change(
|
| 937 |
-
fn=update_display_no_complete,
|
| 938 |
-
inputs=filter_inputs_no_complete,
|
| 939 |
-
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 940 |
-
)
|
| 941 |
|
| 942 |
legend_markdown = create_legend_markdown(category_name)
|
| 943 |
gr.HTML(value=legend_markdown, elem_id="legend-markdown")
|
| 944 |
|
| 945 |
# Add a timer to periodically check for data updates and refresh the UI
|
| 946 |
# This runs every 60 seconds to check if new data is available
|
| 947 |
-
def check_and_refresh_data(show_incomplete, show_open_only=False, mark_by=MARK_BY_DEFAULT
|
| 948 |
"""Check if data has been refreshed and return updated data if so."""
|
| 949 |
current_version = get_data_version()
|
| 950 |
if current_version > initial_data_version:
|
|
@@ -974,16 +955,16 @@ def create_leaderboard_display(
|
|
| 974 |
new_df_display_open = prepare_df_for_display(new_df_view_open)
|
| 975 |
new_df_display_complete_open = prepare_df_for_display(new_df_view_complete_open)
|
| 976 |
|
| 977 |
-
# Create new scatter plots for all combinations (with current mark_by
|
| 978 |
-
new_cost_scatter_complete = create_cost_scatter_plot(new_df_view_complete, mark_by
|
| 979 |
-
new_cost_scatter_all = create_cost_scatter_plot(new_df_view_full, mark_by
|
| 980 |
-
new_cost_scatter_open = create_cost_scatter_plot(new_df_view_open, mark_by
|
| 981 |
-
new_cost_scatter_complete_open = create_cost_scatter_plot(new_df_view_complete_open, mark_by
|
| 982 |
|
| 983 |
-
new_runtime_scatter_complete = create_runtime_scatter_plot(new_df_view_complete, mark_by
|
| 984 |
-
new_runtime_scatter_all = create_runtime_scatter_plot(new_df_view_full, mark_by
|
| 985 |
-
new_runtime_scatter_open = create_runtime_scatter_plot(new_df_view_open, mark_by
|
| 986 |
-
new_runtime_scatter_complete_open = create_runtime_scatter_plot(new_df_view_complete_open, mark_by
|
| 987 |
|
| 988 |
# Return the appropriate data based on checkbox states
|
| 989 |
if show_open_only:
|
|
@@ -1018,7 +999,6 @@ def create_leaderboard_display(
|
|
| 1018 |
if show_open_only_checkbox is not None:
|
| 1019 |
timer_inputs.append(show_open_only_checkbox)
|
| 1020 |
timer_inputs.append(mark_by_dropdown) # Always include mark_by
|
| 1021 |
-
timer_inputs.append(show_all_labels_checkbox)
|
| 1022 |
refresh_timer.tick(
|
| 1023 |
fn=check_and_refresh_data,
|
| 1024 |
inputs=timer_inputs,
|
|
@@ -1026,7 +1006,7 @@ def create_leaderboard_display(
|
|
| 1026 |
)
|
| 1027 |
else:
|
| 1028 |
# If no incomplete checkbox, always show all data (but still filter by open if needed)
|
| 1029 |
-
def check_and_refresh_all(show_open_only=False, mark_by=MARK_BY_DEFAULT
|
| 1030 |
current_version = get_data_version()
|
| 1031 |
if current_version > initial_data_version:
|
| 1032 |
print(f"[REFRESH] Data version changed, reloading...")
|
|
@@ -1039,8 +1019,8 @@ def create_leaderboard_display(
|
|
| 1039 |
new_df_view_full = new_df_view_full[new_df_view_full['Openness'].str.lower() == 'open'].copy()
|
| 1040 |
|
| 1041 |
new_df_display_all = prepare_df_for_display(new_df_view_full)
|
| 1042 |
-
new_cost_scatter_all = create_cost_scatter_plot(new_df_view_full, mark_by
|
| 1043 |
-
new_runtime_scatter_all = create_runtime_scatter_plot(new_df_view_full, mark_by
|
| 1044 |
return new_df_display_all, new_cost_scatter_all, new_runtime_scatter_all
|
| 1045 |
|
| 1046 |
if show_open_only:
|
|
@@ -1050,15 +1030,15 @@ def create_leaderboard_display(
|
|
| 1050 |
if show_open_only_checkbox is not None:
|
| 1051 |
refresh_timer.tick(
|
| 1052 |
fn=check_and_refresh_all,
|
| 1053 |
-
inputs=[show_open_only_checkbox, mark_by_dropdown
|
| 1054 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 1055 |
)
|
| 1056 |
else:
|
| 1057 |
-
def check_and_refresh_simple(mark_by=MARK_BY_DEFAULT
|
| 1058 |
-
return check_and_refresh_all(False, mark_by
|
| 1059 |
refresh_timer.tick(
|
| 1060 |
fn=check_and_refresh_simple,
|
| 1061 |
-
inputs=[mark_by_dropdown
|
| 1062 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 1063 |
)
|
| 1064 |
|
|
|
|
| 705 |
primary_runtime_col = f"{category_name} Runtime"
|
| 706 |
|
| 707 |
# Function to create cost/performance scatter plot from data
|
| 708 |
+
def create_cost_scatter_plot(df_data, mark_by=MARK_BY_DEFAULT):
|
| 709 |
return _plot_scatter_plotly(
|
| 710 |
data=df_data,
|
| 711 |
x=primary_cost_col if primary_cost_col in df_data.columns else None,
|
|
|
|
| 713 |
agent_col="SDK Version",
|
| 714 |
name=category_name,
|
| 715 |
plot_type='cost',
|
| 716 |
+
mark_by=mark_by
|
|
|
|
| 717 |
)
|
| 718 |
|
| 719 |
# Function to create runtime/performance scatter plot from data
|
| 720 |
+
def create_runtime_scatter_plot(df_data, mark_by=MARK_BY_DEFAULT):
|
| 721 |
return _plot_scatter_plotly(
|
| 722 |
data=df_data,
|
| 723 |
x=primary_runtime_col if primary_runtime_col in df_data.columns else None,
|
|
|
|
| 725 |
agent_col="SDK Version",
|
| 726 |
name=category_name,
|
| 727 |
plot_type='runtime',
|
| 728 |
+
mark_by=mark_by
|
|
|
|
| 729 |
)
|
| 730 |
|
| 731 |
# Create initial cost scatter plots for all filter combinations
|
|
|
|
| 772 |
|
| 773 |
# Add toggle checkboxes and dropdown ABOVE the plot
|
| 774 |
with gr.Row():
|
| 775 |
+
with gr.Column(scale=3, elem_classes=["oh-leaderboard-filter-col"]):
|
| 776 |
if has_complete_entries:
|
| 777 |
show_incomplete_checkbox = gr.Checkbox(
|
| 778 |
label=f"Show incomplete entries ({num_incomplete} entries with fewer than 5 categories)",
|
|
|
|
| 792 |
)
|
| 793 |
else:
|
| 794 |
show_open_only_checkbox = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 795 |
|
| 796 |
with gr.Column(scale=1):
|
| 797 |
mark_by_dropdown = gr.Dropdown(
|
|
|
|
| 844 |
df_to_show = df_display_all if show_incomplete else df_display_complete
|
| 845 |
view_df = df_view_full if show_incomplete else df_view_complete
|
| 846 |
|
| 847 |
+
# Regenerate plots with current mark_by setting
|
| 848 |
cost_plot = create_cost_scatter_plot(view_df, mark_by, show_all_labels)
|
| 849 |
runtime_plot = create_runtime_scatter_plot(view_df, mark_by, show_all_labels)
|
| 850 |
return df_to_show, cost_plot, runtime_plot
|
|
|
|
| 875 |
inputs=filter_inputs,
|
| 876 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 877 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
else:
|
| 879 |
dataframe_component = gr.DataFrame(
|
| 880 |
headers=df_headers,
|
|
|
|
| 919 |
inputs=filter_inputs_no_complete,
|
| 920 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 921 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
|
| 923 |
legend_markdown = create_legend_markdown(category_name)
|
| 924 |
gr.HTML(value=legend_markdown, elem_id="legend-markdown")
|
| 925 |
|
| 926 |
# Add a timer to periodically check for data updates and refresh the UI
|
| 927 |
# This runs every 60 seconds to check if new data is available
|
| 928 |
+
def check_and_refresh_data(show_incomplete, show_open_only=False, mark_by=MARK_BY_DEFAULT):
|
| 929 |
"""Check if data has been refreshed and return updated data if so."""
|
| 930 |
current_version = get_data_version()
|
| 931 |
if current_version > initial_data_version:
|
|
|
|
| 955 |
new_df_display_open = prepare_df_for_display(new_df_view_open)
|
| 956 |
new_df_display_complete_open = prepare_df_for_display(new_df_view_complete_open)
|
| 957 |
|
| 958 |
+
# Create new scatter plots for all combinations (with current mark_by)
|
| 959 |
+
new_cost_scatter_complete = create_cost_scatter_plot(new_df_view_complete, mark_by) if len(new_df_display_complete) > 0 else go.Figure()
|
| 960 |
+
new_cost_scatter_all = create_cost_scatter_plot(new_df_view_full, mark_by)
|
| 961 |
+
new_cost_scatter_open = create_cost_scatter_plot(new_df_view_open, mark_by) if len(new_df_view_open) > 0 else go.Figure()
|
| 962 |
+
new_cost_scatter_complete_open = create_cost_scatter_plot(new_df_view_complete_open, mark_by) if len(new_df_view_complete_open) > 0 else go.Figure()
|
| 963 |
|
| 964 |
+
new_runtime_scatter_complete = create_runtime_scatter_plot(new_df_view_complete, mark_by) if len(new_df_display_complete) > 0 else go.Figure()
|
| 965 |
+
new_runtime_scatter_all = create_runtime_scatter_plot(new_df_view_full, mark_by)
|
| 966 |
+
new_runtime_scatter_open = create_runtime_scatter_plot(new_df_view_open, mark_by) if len(new_df_view_open) > 0 else go.Figure()
|
| 967 |
+
new_runtime_scatter_complete_open = create_runtime_scatter_plot(new_df_view_complete_open, mark_by) if len(new_df_view_complete_open) > 0 else go.Figure()
|
| 968 |
|
| 969 |
# Return the appropriate data based on checkbox states
|
| 970 |
if show_open_only:
|
|
|
|
| 999 |
if show_open_only_checkbox is not None:
|
| 1000 |
timer_inputs.append(show_open_only_checkbox)
|
| 1001 |
timer_inputs.append(mark_by_dropdown) # Always include mark_by
|
|
|
|
| 1002 |
refresh_timer.tick(
|
| 1003 |
fn=check_and_refresh_data,
|
| 1004 |
inputs=timer_inputs,
|
|
|
|
| 1006 |
)
|
| 1007 |
else:
|
| 1008 |
# If no incomplete checkbox, always show all data (but still filter by open if needed)
|
| 1009 |
+
def check_and_refresh_all(show_open_only=False, mark_by=MARK_BY_DEFAULT):
|
| 1010 |
current_version = get_data_version()
|
| 1011 |
if current_version > initial_data_version:
|
| 1012 |
print(f"[REFRESH] Data version changed, reloading...")
|
|
|
|
| 1019 |
new_df_view_full = new_df_view_full[new_df_view_full['Openness'].str.lower() == 'open'].copy()
|
| 1020 |
|
| 1021 |
new_df_display_all = prepare_df_for_display(new_df_view_full)
|
| 1022 |
+
new_cost_scatter_all = create_cost_scatter_plot(new_df_view_full, mark_by)
|
| 1023 |
+
new_runtime_scatter_all = create_runtime_scatter_plot(new_df_view_full, mark_by)
|
| 1024 |
return new_df_display_all, new_cost_scatter_all, new_runtime_scatter_all
|
| 1025 |
|
| 1026 |
if show_open_only:
|
|
|
|
| 1030 |
if show_open_only_checkbox is not None:
|
| 1031 |
refresh_timer.tick(
|
| 1032 |
fn=check_and_refresh_all,
|
| 1033 |
+
inputs=[show_open_only_checkbox, mark_by_dropdown],
|
| 1034 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 1035 |
)
|
| 1036 |
else:
|
| 1037 |
+
def check_and_refresh_simple(mark_by=MARK_BY_DEFAULT):
|
| 1038 |
+
return check_and_refresh_all(False, mark_by)
|
| 1039 |
refresh_timer.tick(
|
| 1040 |
fn=check_and_refresh_simple,
|
| 1041 |
+
inputs=[mark_by_dropdown],
|
| 1042 |
outputs=[dataframe_component, cost_plot_component, runtime_plot_component]
|
| 1043 |
)
|
| 1044 |
|