DuongTrongChi commited on
Commit
7a458ad
·
verified ·
1 Parent(s): 86247ff

Update app.py

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