Spaces:
Sleeping
Sleeping
File size: 16,466 Bytes
b58ae17 4c4fdb7 b58ae17 4c4fdb7 86247ff d4a4522 86247ff 89530b0 4c4fdb7 86247ff 4c4fdb7 b13359f 86247ff b13359f 4c4fdb7 b13359f 4c4fdb7 b13359f 4c4fdb7 f01c027 c3fcfb0 86247ff 4c4fdb7 b13359f 4c4fdb7 b13359f 4c4fdb7 86247ff 4c4fdb7 86247ff 4c4fdb7 86247ff 4c4fdb7 b13359f 4c4fdb7 7a458ad 4c4fdb7 7a458ad 3c11018 4c4fdb7 b13359f 4c4fdb7 b13359f 4c4fdb7 b13359f 4c4fdb7 b13359f 4c4fdb7 7a458ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
import gradio as gr
import pandas as pd
from math import isnan
ROWS = [
{"Team_name":"Nguyen Quang Thao","vi-law-nli":0.5816,"vi-law-qa":0.8217,"vilaw-syllo":0.38,"Avg":0.5944333333},
{"Team_name":"NHK","vi-law-nli":0.9333,"vi-law-qa":0.8683,"vilaw-syllo":0.3275,"Avg":0.7097},
{"Team_name":"Innovation-LLM","vi-law-nli":0.9567,"vi-law-qa":0.8367,"vilaw-syllo":0.541666667,"Avg":0.7783555556},
{"Team_name":"Bosch@AI Team","vi-law-nli":0.97,"vi-law-qa":0.9267,"vilaw-syllo":0.535833333,"Avg":0.8108444444},
{"Team_name":"URAx","vi-law-nli":0.945,"vi-law-qa":0.8333,"vilaw-syllo":0.576666667,"Avg":0.7849888889},
{"Team_name":"Abe","vi-law-nli":0.82,"vi-law-qa":0.84,"vilaw-syllo":0.2875,"Avg":0.6491666667},
{"Team_name":"PSLV-Warrior","vi-law-nli":0.8517,"vi-law-qa":0.7483,"vilaw-syllo":0.525,"Avg":0.7083333333},
{"Team_name":"MinLegal","vi-law-nli":0.98,"vi-law-qa":0.8733,"vilaw-syllo":0.530833333,"Avg":0.7947111111},
{"Team_name":"NLPhi","vi-law-nli":0.6517,"vi-law-qa":0.815,"vilaw-syllo":0.479166667,"Avg":0.6486222222},
{"Team_name":"LICTU","vi-law-nli":0.8467,"vi-law-qa":0.8067,"vilaw-syllo":0.5375,"Avg":0.7303},
]
BASE_DF = pd.DataFrame(ROWS)
NUM_COLS = ["vi-law-nli", "vi-law-qa", "vilaw-syllo", "Avg"]
def _prep_df(df: pd.DataFrame) -> pd.DataFrame:
out = df.copy()
for c in NUM_COLS:
out[c] = pd.to_numeric(out[c], errors="coerce").astype(float).round(6)
out = out.sort_values("Avg", ascending=False, kind="mergesort").reset_index(drop=True)
out.insert(0, "Rank", range(1, len(out)+1))
return out
def _bar_html(v: float) -> str:
if v is None or (isinstance(v, float) and isnan(v)):
return "-"
pct = max(0.0, min(1.0, float(v))) * 100
return f"<div class='cell'><div class='bar' style='width:{pct:.2f}%'></div><span class='val'>{v:.4f}</span></div>"
def _render_table(df: pd.DataFrame) -> str:
cols = ["Rank","Team_name"]+NUM_COLS
header = "".join([f"<th>{c}</th>" for c in cols])
rows_html = []
for _, row in df.iterrows():
tds = [
f"<td class='rank'>{int(row['Rank'])}</td>",
f"<td class='team'>{row['Team_name']}</td>",
f"<td>{_bar_html(row['vi-law-nli'])}</td>",
f"<td>{_bar_html(row['vi-law-qa'])}</td>",
f"<td>{_bar_html(row['vilaw-syllo'])}</td>",
f"<td>{_bar_html(row['Avg'])}</td>",
]
rows_html.append(f"<tr>{''.join(tds)}</tr>")
return f"<table class='lb-table'><thead><tr>{header}</tr></thead><tbody>{''.join(rows_html)}</tbody></table>"
def _filter_and_sort(search: str, quick: str):
df = BASE_DF.copy()
if search:
terms = [t.strip() for t in search.split(";") if t.strip()]
for t in terms:
df = df[df["Team_name"].str.contains(t, case=False, na=False)]
if quick == "Top 3":
df = df.sort_values("Avg", ascending=False).head(3)
elif quick == "Top 5":
df = df.sort_values("Avg", ascending=False).head(5)
else:
df = df.sort_values("Avg", ascending=False)
return _prep_df(df)
def _controller(search, quick):
df = _filter_and_sort(search, quick)
return _render_table(df), df
CUSTOM_CSS = """
:root {
--bg: #ffffff; --panel:#f8f9fa; --text:#000000; --muted:#6c757d; --bar:#28a745; --bar-bg:#e9ecef;
}
/* Global Gradio container styling */
.gradio-container {
background: var(--bg) !important;
color: var(--text) !important;
}
/* Main background */
.main {
background: var(--bg) !important;
}
/* Panel backgrounds */
.panel {
background: var(--panel) !important;
}
/* Text elements */
h1, h2, h3, h4, h5, h6, p, span, div {
color: var(--text) !important;
}
/* Form elements */
input, textarea, select {
background: #ffffff !important;
color: var(--text) !important;
border: 1px solid #ced4da !important;
}
/* Labels */
label {
color: var(--text) !important;
font-weight: 500 !important;
}
/* Radio buttons */
.radio-group {
background: var(--panel) !important;
}
.radio-group label {
color: var(--text) !important;
}
/* Buttons */
button {
background: var(--bar) !important;
color: white !important;
border: none !important;
}
button:hover {
background: #218838 !important;
}
/* Table styling */
.lb-table {
width: 100%;
border-collapse: collapse;
background: var(--bg) !important;
}
.lb-table thead th {
background: var(--panel) !important;
padding: 10px;
text-align: left;
color: var(--text) !important;
border-bottom: 2px solid #dee2e6 !important;
}
.lb-table tbody td {
padding: 10px;
border-bottom: 1px solid #dee2e6;
color: var(--text) !important;
}
.lb-table td.rank {
width: 60px;
font-weight: 700;
color: var(--text) !important;
}
.lb-table td.team {
min-width: 200px;
color: var(--text) !important;
}
/* Progress bars */
.cell {
position: relative;
height: 20px;
background: var(--bar-bg);
border-radius: 6px;
}
.cell .bar {
position: absolute;
left: 0;
top: 0;
bottom: 0;
background: var(--bar);
}
.cell .val {
position: absolute;
right: 8px;
top: 0;
bottom: 0;
display: flex;
align-items: center;
color: var(--text) !important;
font-weight: 500 !important;
}
/* Gradio specific overrides */
.gradio-input, .gradio-output {
background: var(--bg) !important;
color: var(--text) !important;
}
.gradio-input input, .gradio-input textarea {
background: #ffffff !important;
color: var(--text) !important;
border: 1px solid #ced4da !important;
}
.gradio-input label {
color: var(--text) !important;
}
.gradio-radio {
background: var(--panel) !important;
}
.gradio-radio label {
color: var(--text) !important;
}
/* Search bar specific styling */
.gradio-input-container {
background: var(--bg) !important;
}
.gradio-input-container label {
color: var(--text) !important;
background: var(--bg) !important;
}
/* Target the search input specifically */
.gradio-input input[type="text"] {
background: #ffffff !important;
color: var(--text) !important;
border: 1px solid #ced4da !important;
}
/* Override any dark backgrounds on input containers */
.gradio-input > div {
background: var(--bg) !important;
}
/* Ensure labels are black text on white background */
.gradio-input label, .gradio-input-container label {
color: var(--text) !important;
background: var(--bg) !important;
}
/* Override any panel backgrounds that might be dark */
.gradio-input .panel, .gradio-input .gradio-panel {
background: var(--bg) !important;
}
/* Force all input-related elements to have light backgrounds */
.gradio-input, .gradio-input *, .gradio-input-container, .gradio-input-container * {
background: var(--bg) !important;
}
/* Override any dark backgrounds on the entire row containing search and filter */
.gradio-row {
background: var(--bg) !important;
}
.gradio-row * {
background: var(--bg) !important;
}
/* Specific targeting for search and filter containers */
.gradio-input[data-testid="textbox"], .gradio-input[data-testid="radio"] {
background: var(--bg) !important;
}
.gradio-input[data-testid="textbox"] label, .gradio-input[data-testid="radio"] label {
color: var(--text) !important;
background: var(--bg) !important;
}
/* Override any remaining dark backgrounds */
.gradio-input, .gradio-input-container, .gradio-input-container > div {
background: var(--bg) !important;
}
/* Ensure the search input field itself is white */
input[type="text"], input[placeholder*="Tìm team"] {
background: #ffffff !important;
color: var(--text) !important;
border: 1px solid #ced4da !important;
}
/* Aggressive override for the dark panel container */
.gradio-input, .gradio-input-container, .gradio-input-container > div,
.gradio-input > div, .gradio-input > div > div {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Force all elements in the search row to have white backgrounds */
.gradio-row, .gradio-row > div, .gradio-row > div > div,
.gradio-row .gradio-input, .gradio-row .gradio-input-container {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Override any remaining dark backgrounds with maximum specificity */
.gradio-input, .gradio-input *, .gradio-input-container, .gradio-input-container *,
.gradio-input > div, .gradio-input > div *, .gradio-input-container > div, .gradio-input-container > div * {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Target the specific search and filter components */
.gradio-input[data-testid="textbox"], .gradio-input[data-testid="radio"],
.gradio-input[data-testid="textbox"] *, .gradio-input[data-testid="radio"] * {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Override any CSS variables that might be setting dark backgrounds */
.gradio-input, .gradio-input-container {
--background: var(--bg) !important;
--background-color: var(--bg) !important;
--panel-background: var(--bg) !important;
--panel-background-color: var(--bg) !important;
}
/* Target the dark panel wrapper specifically */
.gradio-panel, .gradio-panel *, .gradio-container .gradio-panel,
.gradio-container .gradio-panel *, .gradio-input .gradio-panel,
.gradio-input .gradio-panel * {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Override any remaining dark backgrounds with !important */
.gradio-input, .gradio-input-container, .gradio-input-container > div,
.gradio-input > div, .gradio-input > div > div,
.gradio-input > div > div > div, .gradio-input > div > div > div > div {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Force the entire search row to be white */
.gradio-row, .gradio-row *, .gradio-row > div, .gradio-row > div *,
.gradio-row > div > div, .gradio-row > div > div * {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Maximum specificity override for any dark backgrounds */
.gradio-input, .gradio-input-container, .gradio-input-container > div,
.gradio-input > div, .gradio-input > div *, .gradio-input-container > div,
.gradio-input-container > div *, .gradio-input > div > div, .gradio-input > div > div *,
.gradio-input > div > div > div, .gradio-input > div > div > div * {
background: var(--bg) !important;
background-color: var(--bg) !important;
}
/* Download button */
.gradio-button {
background: var(--bar) !important;
color: white !important;
border: none !important;
padding: 8px 16px !important;
border-radius: 6px !important;
}
.gradio-button:hover {
background: #218838 !important;
}
"""
with gr.Blocks(theme=gr.themes.Soft(), css=CUSTOM_CSS) as demo:
gr.Markdown("# 🏆 LegalSLM Leaderboard")
with gr.Row():
search = gr.Textbox(placeholder="Tìm team...", label="Search")
quick = gr.Radio(choices=["All","Top 3","Top 5"], value="All", label="Quick Filter")
html_table = gr.HTML(value=_render_table(_prep_df(BASE_DF)))
csv_state = gr.State(_prep_df(BASE_DF))
download = gr.DownloadButton("⬇️ Tải CSV")
def _download(df):
path = "/tmp/leaderboard.csv"
df.to_csv(path,index=False)
return path
download.click(_download, inputs=[csv_state], outputs=download)
for comp in [search, quick]:
comp.change(_controller, [search, quick], [html_table, csv_state])
if __name__ == "__main__":
demo.launch()
# ########################################################____V1_____############################
# # app.py
# import gradio as gr
# import pandas as pd
# from math import isnan
# ROWS = [
# {"Team_name":"Nguyen Quang Thao","vi-law-nli":0.5816,"vi-law-qa":0.8217,"vilaw-syllo":0.38,"Avg":0.5944333333},
# {"Team_name":"NHK","vi-law-nli":0.9333,"vi-law-qa":0.8683,"vilaw-syllo":0.3275,"Avg":0.7097},
# {"Team_name":"Innovation-LLM","vi-law-nli":0.9567,"vi-law-qa":0.8367,"vilaw-syllo":0.541666667,"Avg":0.7783555556},
# {"Team_name":"Bosch@AI Team","vi-law-nli":0.97,"vi-law-qa":0.9267,"vilaw-syllo":0.535833333,"Avg":0.8108444444},
# {"Team_name":"URAx","vi-law-nli":0.945,"vi-law-qa":0.8333,"vilaw-syllo":0.576666667,"Avg":0.7849888889},
# {"Team_name":"Abe","vi-law-nli":0.82,"vi-law-qa":0.84,"vilaw-syllo":0.2875,"Avg":0.6491666667},
# {"Team_name":"PSLV-Warrior","vi-law-nli":0.565,"vi-law-qa":0.0333,"vilaw-syllo":0.525,"Avg":0.3744333333},
# {"Team_name":"MinLegal","vi-law-nli":0.98,"vi-law-qa":0.8733,"vilaw-syllo":0.530833333,"Avg":0.7947111111},
# {"Team_name":"NLPhi","vi-law-nli":0.6517,"vi-law-qa":0.815,"vilaw-syllo":0.479166667,"Avg":0.6486222222},
# {"Team_name":"LICTU","vi-law-nli":0.8467,"vi-law-qa":0.8067,"vilaw-syllo":0.5375,"Avg":0.7303},
# ]
# BASE_DF = pd.DataFrame(ROWS)
# NUM_COLS = ["vi-law-nli", "vi-law-qa", "vilaw-syllo", "Avg"]
# def _prep_df(df: pd.DataFrame) -> pd.DataFrame:
# out = df.copy()
# for c in NUM_COLS:
# out[c] = pd.to_numeric(out[c], errors="coerce").astype(float).round(6)
# out = out.sort_values("Avg", ascending=False, kind="mergesort").reset_index(drop=True)
# out.insert(0, "Rank", range(1, len(out)+1))
# return out
# def _bar_html(v: float) -> str:
# if v is None or (isinstance(v, float) and isnan(v)):
# return "-"
# pct = max(0.0, min(1.0, float(v))) * 100
# return f"<div class='cell'><div class='bar' style='width:{pct:.2f}%'></div><span class='val'>{v:.4f}</span></div>"
# def _render_table(df: pd.DataFrame) -> str:
# cols = ["Rank","Team_name"]+NUM_COLS
# header = "".join([f"<th>{c}</th>" for c in cols])
# rows_html = []
# for _, row in df.iterrows():
# tds = [
# f"<td class='rank'>{int(row['Rank'])}</td>",
# f"<td class='team'>{row['Team_name']}</td>",
# f"<td>{_bar_html(row['vi-law-nli'])}</td>",
# f"<td>{_bar_html(row['vi-law-qa'])}</td>",
# f"<td>{_bar_html(row['vilaw-syllo'])}</td>",
# f"<td>{_bar_html(row['Avg'])}</td>",
# ]
# rows_html.append(f"<tr>{''.join(tds)}</tr>")
# return f"<table class='lb-table'><thead><tr>{header}</tr></thead><tbody>{''.join(rows_html)}</tbody></table>"
# def _filter_and_sort(search: str, quick: str):
# df = BASE_DF.copy()
# if search:
# terms = [t.strip() for t in search.split(";") if t.strip()]
# for t in terms:
# df = df[df["Team_name"].str.contains(t, case=False, na=False)]
# if quick == "Top 3":
# df = df.sort_values("Avg", ascending=False).head(3)
# elif quick == "Top 5":
# df = df.sort_values("Avg", ascending=False).head(5)
# else:
# df = df.sort_values("Avg", ascending=False)
# return _prep_df(df)
# def _controller(search, quick):
# df = _filter_and_sort(search, quick)
# return _render_table(df), df
# CUSTOM_CSS = """
# :root {
# --bg: #0e1116; --panel:#12161f; --text:#e6e6e6; --muted:#9aa3b2; --bar:#2ea043; --bar-bg:#1f2a36;
# }
# .gradio-container {background: var(--bg)!important; color: var(--text);}
# .lb-table { width:100%; border-collapse: collapse; }
# .lb-table thead th { background: var(--panel); padding: 10px; text-align:left; }
# .lb-table tbody td { padding: 10px; border-bottom: 1px solid #1d2430; }
# .lb-table td.rank { width:60px; font-weight:700; }
# .lb-table td.team { min-width:200px; }
# .cell { position:relative; height:20px; background: var(--bar-bg); border-radius:6px; }
# .cell .bar { position:absolute; left:0; top:0; bottom:0; background: var(--bar);}
# .cell .val { position:absolute; right:8px; top:0; bottom:0; display:flex; align-items:center; }
# """
# with gr.Blocks(css=CUSTOM_CSS) as demo:
# gr.Markdown("# 🏆 LegalSLM Leaderboard")
# with gr.Row():
# search = gr.Textbox(placeholder="Tìm team...", label="Search")
# quick = gr.Radio(choices=["All","Top 3","Top 5"], value="All", label="Quick Filter")
# html_table = gr.HTML(value=_render_table(_prep_df(BASE_DF)))
# csv_state = gr.State(_prep_df(BASE_DF))
# download = gr.DownloadButton("⬇️ Tải CSV")
# def _download(df):
# path = "/tmp/leaderboard.csv"
# df.to_csv(path,index=False)
# return path
# download.click(_download, inputs=[csv_state], outputs=download)
# for comp in [search, quick]:
# comp.change(_controller, [search, quick], [html_table, csv_state])
# if __name__ == "__main__":
# demo.launch()
|