Remove the error when the DataFrame is empty
Browse files- app.py +19 -30
- app_local.py +7 -3
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
|
3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
4 |
from huggingface_hub import snapshot_download
|
|
|
5 |
|
6 |
from src.about import (
|
7 |
CITATION_BUTTON_LABEL,
|
@@ -56,36 +57,24 @@ LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS,
|
|
56 |
pending_eval_queue_df,
|
57 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
58 |
|
59 |
-
def init_leaderboard(
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
),
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
AutoEvalColumn.params.name,
|
78 |
-
type="slider",
|
79 |
-
min=0.01,
|
80 |
-
max=150,
|
81 |
-
label="Select the number of parameters (B)",
|
82 |
-
),
|
83 |
-
ColumnFilter(
|
84 |
-
AutoEvalColumn.still_on_hub.name, type="boolean", label="Deleted/incomplete", default=True
|
85 |
-
),
|
86 |
-
],
|
87 |
-
bool_checkboxgroup_label="Hide models",
|
88 |
-
interactive=False,
|
89 |
)
|
90 |
|
91 |
|
|
|
2 |
from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
|
3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
4 |
from huggingface_hub import snapshot_download
|
5 |
+
import pandas as pd
|
6 |
|
7 |
from src.about import (
|
8 |
CITATION_BUTTON_LABEL,
|
|
|
57 |
pending_eval_queue_df,
|
58 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
59 |
|
60 |
+
def init_leaderboard(df):
|
61 |
+
"""Initialize the leaderboard with the given DataFrame."""
|
62 |
+
if df is None or df.empty:
|
63 |
+
# Create an empty DataFrame with the required columns
|
64 |
+
df = pd.DataFrame(columns=COLS)
|
65 |
+
print("Creating empty leaderboard - no evaluations completed yet")
|
66 |
+
|
67 |
+
# Create the leaderboard
|
68 |
+
return gr.Dataframe(
|
69 |
+
headers=COLS,
|
70 |
+
datatype=["str"] * len(COLS),
|
71 |
+
row_count=10,
|
72 |
+
col_count=(len(COLS), "fixed"),
|
73 |
+
value=df,
|
74 |
+
wrap=True,
|
75 |
+
column_widths=[50] + [None] * (len(COLS) - 1),
|
76 |
+
max_rows=50,
|
77 |
+
type="pandas",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
)
|
79 |
|
80 |
|
app_local.py
CHANGED
@@ -42,9 +42,7 @@ print("\nGetting evaluation queue DataFrames...")
|
|
42 |
|
43 |
def init_leaderboard(dataframe):
|
44 |
print(f"Initializing leaderboard with DataFrame shape: {dataframe.shape}")
|
45 |
-
|
46 |
-
raise ValueError("Leaderboard DataFrame is empty or None.")
|
47 |
-
|
48 |
# Get all fields from AutoEvalColumn
|
49 |
auto_eval_fields = fields(AutoEvalColumn)
|
50 |
print(f"AutoEvalColumn fields: {[f.name for f in auto_eval_fields]}")
|
@@ -53,6 +51,12 @@ def init_leaderboard(dataframe):
|
|
53 |
field_mapping = {f.name: f for f in auto_eval_fields}
|
54 |
print(f"Field mapping: {field_mapping}")
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
# Verify all required columns are present
|
57 |
for col in dataframe.columns:
|
58 |
if col not in field_mapping:
|
|
|
42 |
|
43 |
def init_leaderboard(dataframe):
|
44 |
print(f"Initializing leaderboard with DataFrame shape: {dataframe.shape}")
|
45 |
+
|
|
|
|
|
46 |
# Get all fields from AutoEvalColumn
|
47 |
auto_eval_fields = fields(AutoEvalColumn)
|
48 |
print(f"AutoEvalColumn fields: {[f.name for f in auto_eval_fields]}")
|
|
|
51 |
field_mapping = {f.name: f for f in auto_eval_fields}
|
52 |
print(f"Field mapping: {field_mapping}")
|
53 |
|
54 |
+
if dataframe is None or len(dataframe) == 0:
|
55 |
+
# Create an empty DataFrame with the correct columns
|
56 |
+
import pandas as pd
|
57 |
+
dataframe = pd.DataFrame(columns=[f.name for f in auto_eval_fields])
|
58 |
+
print("Created empty DataFrame with correct columns")
|
59 |
+
|
60 |
# Verify all required columns are present
|
61 |
for col in dataframe.columns:
|
62 |
if col not in field_mapping:
|