Spaces:
Runtime error
Runtime error
Commit ·
e51c0a4
1
Parent(s): 4e0c92e
fix version error
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import html
|
| 2 |
import json
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -94,11 +95,6 @@ def init_leaderboard(dataframe):
|
|
| 94 |
bool_checkboxgroup_label="Hide models",
|
| 95 |
interactive=False,
|
| 96 |
)
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
demo = gr.Blocks(css=custom_css)
|
| 100 |
-
|
| 101 |
-
|
| 102 |
def create_score_df(json_path: Path, decimals: int):
|
| 103 |
data = json.loads(json_path.read_text(encoding="utf-8"))
|
| 104 |
|
|
@@ -136,6 +132,25 @@ def dataframe_height(df: pd.DataFrame):
|
|
| 136 |
return max(320, min(1200, height))
|
| 137 |
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
def create_raw_score_df():
|
| 140 |
raw_path = Path(__file__).resolve().parent / "src" / "raw_score.json"
|
| 141 |
return create_score_df(raw_path, decimals=2)
|
|
@@ -246,6 +261,40 @@ def create_weights_table_html():
|
|
| 246 |
return "".join(parts)
|
| 247 |
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
with demo:
|
| 250 |
gr.HTML(custom_js)
|
| 251 |
gr.HTML(TITLE)
|
|
@@ -255,38 +304,32 @@ with demo:
|
|
| 255 |
with gr.TabItem("Result", elem_id="result-tab", id=0):
|
| 256 |
with gr.Tabs(elem_classes="tab-buttons") as nested_tabs:
|
| 257 |
with gr.TabItem("Raw Score"):
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
gr.DataFrame(
|
| 261 |
-
raw_score_df,
|
| 262 |
wrap=True,
|
| 263 |
-
column_widths=
|
| 264 |
-
row_count=(len(
|
| 265 |
-
height=dataframe_height(
|
| 266 |
elem_id="raw-score-table",
|
| 267 |
)
|
| 268 |
with gr.TabItem("Weights"):
|
| 269 |
gr.HTML(create_weights_table_html(), elem_id="weights-table")
|
| 270 |
with gr.TabItem("Unweighted Z-score"):
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
gr.DataFrame(
|
| 274 |
-
unweighted_z_df,
|
| 275 |
wrap=True,
|
| 276 |
-
column_widths=
|
| 277 |
-
row_count=(len(
|
| 278 |
-
height=dataframe_height(
|
| 279 |
elem_id="unweighted-z-table",
|
| 280 |
)
|
| 281 |
with gr.TabItem("Weighted Z-score"):
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
gr.DataFrame(
|
| 285 |
-
weighted_z_df,
|
| 286 |
wrap=True,
|
| 287 |
-
column_widths=
|
| 288 |
-
row_count=(len(
|
| 289 |
-
height=dataframe_height(
|
| 290 |
elem_id="weighted-z-table",
|
| 291 |
)
|
| 292 |
|
|
|
|
| 1 |
import html
|
| 2 |
import json
|
| 3 |
+
import re
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 95 |
bool_checkboxgroup_label="Hide models",
|
| 96 |
interactive=False,
|
| 97 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
def create_score_df(json_path: Path, decimals: int):
|
| 99 |
data = json.loads(json_path.read_text(encoding="utf-8"))
|
| 100 |
|
|
|
|
| 132 |
return max(320, min(1200, height))
|
| 133 |
|
| 134 |
|
| 135 |
+
def create_gr_dataframe(value, **kwargs):
|
| 136 |
+
dataframe_ctor = getattr(gr, "DataFrame", None) or getattr(gr, "Dataframe")
|
| 137 |
+
remaining_kwargs = dict(kwargs)
|
| 138 |
+
|
| 139 |
+
for _ in range(20):
|
| 140 |
+
try:
|
| 141 |
+
return dataframe_ctor(value, **remaining_kwargs)
|
| 142 |
+
except TypeError as e:
|
| 143 |
+
match = re.search(r"unexpected keyword argument '([^']+)'", str(e))
|
| 144 |
+
if match is None:
|
| 145 |
+
raise
|
| 146 |
+
bad_key = match.group(1)
|
| 147 |
+
if bad_key not in remaining_kwargs:
|
| 148 |
+
raise
|
| 149 |
+
remaining_kwargs.pop(bad_key)
|
| 150 |
+
|
| 151 |
+
return dataframe_ctor(value, **remaining_kwargs)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
def create_raw_score_df():
|
| 155 |
raw_path = Path(__file__).resolve().parent / "src" / "raw_score.json"
|
| 156 |
return create_score_df(raw_path, decimals=2)
|
|
|
|
| 261 |
return "".join(parts)
|
| 262 |
|
| 263 |
|
| 264 |
+
RAW_SCORE_DF = create_raw_score_df()
|
| 265 |
+
UNWEIGHTED_Z_DF = create_unweighted_z_score_df()
|
| 266 |
+
WEIGHTED_Z_DF = create_weighted_z_score_df()
|
| 267 |
+
|
| 268 |
+
RAW_SCORE_COLUMN_WIDTHS = [40, 220] + [180] * (len(RAW_SCORE_DF.columns) - 2)
|
| 269 |
+
UNWEIGHTED_Z_COLUMN_WIDTHS = [40, 220] + [180] * (len(UNWEIGHTED_Z_DF.columns) - 2)
|
| 270 |
+
WEIGHTED_Z_COLUMN_WIDTHS = [40, 220] + [180] * (len(WEIGHTED_Z_DF.columns) - 2)
|
| 271 |
+
|
| 272 |
+
DATAFRAME_HEIGHT_CSS = f"""
|
| 273 |
+
#raw-score-table .table-wrap,
|
| 274 |
+
#raw-score-table .wrap,
|
| 275 |
+
#raw-score-table .wrap-inner {{
|
| 276 |
+
max-height: {dataframe_height(RAW_SCORE_DF)}px;
|
| 277 |
+
overflow-y: auto;
|
| 278 |
+
}}
|
| 279 |
+
|
| 280 |
+
#unweighted-z-table .table-wrap,
|
| 281 |
+
#unweighted-z-table .wrap,
|
| 282 |
+
#unweighted-z-table .wrap-inner {{
|
| 283 |
+
max-height: {dataframe_height(UNWEIGHTED_Z_DF)}px;
|
| 284 |
+
overflow-y: auto;
|
| 285 |
+
}}
|
| 286 |
+
|
| 287 |
+
#weighted-z-table .table-wrap,
|
| 288 |
+
#weighted-z-table .wrap,
|
| 289 |
+
#weighted-z-table .wrap-inner {{
|
| 290 |
+
max-height: {dataframe_height(WEIGHTED_Z_DF)}px;
|
| 291 |
+
overflow-y: auto;
|
| 292 |
+
}}
|
| 293 |
+
"""
|
| 294 |
+
|
| 295 |
+
demo = gr.Blocks(css=custom_css + DATAFRAME_HEIGHT_CSS)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
with demo:
|
| 299 |
gr.HTML(custom_js)
|
| 300 |
gr.HTML(TITLE)
|
|
|
|
| 304 |
with gr.TabItem("Result", elem_id="result-tab", id=0):
|
| 305 |
with gr.Tabs(elem_classes="tab-buttons") as nested_tabs:
|
| 306 |
with gr.TabItem("Raw Score"):
|
| 307 |
+
create_gr_dataframe(
|
| 308 |
+
RAW_SCORE_DF,
|
|
|
|
|
|
|
| 309 |
wrap=True,
|
| 310 |
+
column_widths=RAW_SCORE_COLUMN_WIDTHS,
|
| 311 |
+
row_count=(len(RAW_SCORE_DF), "fixed"),
|
| 312 |
+
height=dataframe_height(RAW_SCORE_DF),
|
| 313 |
elem_id="raw-score-table",
|
| 314 |
)
|
| 315 |
with gr.TabItem("Weights"):
|
| 316 |
gr.HTML(create_weights_table_html(), elem_id="weights-table")
|
| 317 |
with gr.TabItem("Unweighted Z-score"):
|
| 318 |
+
create_gr_dataframe(
|
| 319 |
+
UNWEIGHTED_Z_DF,
|
|
|
|
|
|
|
| 320 |
wrap=True,
|
| 321 |
+
column_widths=UNWEIGHTED_Z_COLUMN_WIDTHS,
|
| 322 |
+
row_count=(len(UNWEIGHTED_Z_DF), "fixed"),
|
| 323 |
+
height=dataframe_height(UNWEIGHTED_Z_DF),
|
| 324 |
elem_id="unweighted-z-table",
|
| 325 |
)
|
| 326 |
with gr.TabItem("Weighted Z-score"):
|
| 327 |
+
create_gr_dataframe(
|
| 328 |
+
WEIGHTED_Z_DF,
|
|
|
|
|
|
|
| 329 |
wrap=True,
|
| 330 |
+
column_widths=WEIGHTED_Z_COLUMN_WIDTHS,
|
| 331 |
+
row_count=(len(WEIGHTED_Z_DF), "fixed"),
|
| 332 |
+
height=dataframe_height(WEIGHTED_Z_DF),
|
| 333 |
elem_id="weighted-z-table",
|
| 334 |
)
|
| 335 |
|