Jerrycool commited on
Commit
d96489f
·
verified ·
1 Parent(s): 9d8636c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -229
app.py CHANGED
@@ -8,6 +8,8 @@ Changes made in this version
8
  font size, family and alignment are now reliably applied.
9
  3. All new comments are in English for clarity.
10
  4. Adjusted font sizes for Radio button labels per user request.
 
 
11
  """
12
 
13
  import gradio as gr
@@ -25,7 +27,7 @@ try:
25
  EVALUATION_QUEUE_TEXT, # still referenced in commented‑out submit tab
26
  INTRODUCTION_TEXT,
27
  LLM_BENCHMARKS_TEXT,
28
- TITLE, # contains <h1 id="main-leaderboard-title">
29
  )
30
 
31
  try:
@@ -213,19 +215,19 @@ def restart_space():
213
  # Insert actual restart logic if needed.
214
 
215
  # ---------------------------------------------------------------------------
216
- # CSS: project CSS (custom_css) + enhanced overrides
217
  # ---------------------------------------------------------------------------
218
 
219
- # --- CLEAN introduction typography override (this replaces the buggy version) ---
220
  intro_css = """
221
  /* --------------------------------------------------
222
  INTRODUCTION BLOCK (font, size, alignment)
223
  -------------------------------------------------- */
224
  .introduction-wrapper, .introduction-section {
225
- font-family: Arial;
226
  font-size: 1.3rem !important; /* ≈22–23 px */
227
  line-height: 1.75;
228
- color: #344054;
229
  text-align: center;
230
  max-width: 1000px;
231
  margin: 0 auto 1rem auto;
@@ -233,24 +235,27 @@ intro_css = """
233
  .introduction-wrapper p, .introduction-section p {
234
  font-size: 1.3rem !important; /* ≈22–23 px */
235
  margin-bottom: 0.5rem;
 
236
  }
237
  @media (max-width: 768px) {
238
  .introduction-wrapper, .introduction-section {
239
- font-size: 1.3rem !important;
240
  }
241
  }
242
  """
243
 
244
  # --- Existing CSS (base layout, table, etc.) ---
 
 
245
  base_css = """
246
  /* Base & layout overrides (truncated for brevity) */
247
  body {
248
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
249
  Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
250
- font-size: 1.3em;
251
  line-height: 1.6;
252
- background-color: #f8f9fa;
253
- color: #343a40;
254
  }
255
 
256
  .gradio-container {
@@ -262,24 +267,26 @@ body {
262
  #main-leaderboard-title {
263
  font-size: 3.2em;
264
  font-weight: 700;
265
- color: #212529;
266
  text-align: center;
267
  margin-bottom: 1.5rem;
268
  padding-bottom: 0.5rem;
269
- border-bottom: 2px solid #dee2e6;
270
  }
271
 
272
- /* Leaderboard table (only key parts kept) */
273
  #leaderboard-table th {
274
- background-color: #e9ecef;
275
  font-size: 1.3em;
276
  font-weight: 500;
 
277
  }
278
  #leaderboard-table td {
279
  font-size: 1.1em;
 
280
  }
281
  #leaderboard-table .model-link {
282
- color: #0056b3;
283
  font-weight: 500;
284
  text-decoration: none;
285
  }
@@ -289,21 +296,14 @@ body {
289
 
290
  #leaderboard-table {
291
  border-radius: 0.75rem;
292
- overflow: hidden;
293
- border: 1px solid #dee2e6;
294
  }
295
 
296
  #leaderboard-table th,
297
  #leaderboard-table td {
298
- padding: 0.9rem 1.2rem;
299
- line-height: 1.4;
300
- }
301
-
302
- #intro-image img {
303
- max-width: 800px;
304
- height: auto;
305
- display: block;
306
- margin: 0 auto;
307
  }
308
  """
309
 
@@ -313,37 +313,37 @@ markdown_css = """
313
  =============================== */
314
  .markdown-text, .markdown-text p {
315
  font-family: Arial, Helvetica, sans-serif;
316
- font-size: 1.1rem;
317
- line-height: 1.75;
318
- color: #344054;
319
  margin-bottom: 0.9rem;
320
  }
321
 
322
-
323
  .markdown-text h1,
324
  .markdown-text h2,
325
  .markdown-text h3 {
326
- color: #212529;
327
  font-weight: 600;
328
  line-height: 1.3;
329
  margin: 1.4rem 0 0.8rem 0;
330
  }
331
- .markdown-text h1 { font-size: 1.7rem; } /* ≈32 px */
332
- .markdown-text h2 { font-size: 1.5rem; } /* ≈26 px */
333
- .markdown-text h3 { font-size: 1.3rem; } /* ≈23 px */
334
-
335
 
336
  .markdown-text ul,
337
  .markdown-text ol {
338
- padding-left: 1.6rem;
339
  margin-bottom: 1.1rem;
340
  }
341
 
342
-
343
  .markdown-text pre, .markdown-text code {
344
  font-family: "Source Code Pro", "Menlo", monospace;
345
- background-color: #f1f3f5;
 
346
  border-radius: 0.4rem;
 
347
  }
348
  .markdown-text pre {
349
  padding: 1rem 1.2rem;
@@ -354,11 +354,8 @@ markdown_css = """
354
  font-size: 0.95rem;
355
  }
356
 
357
-
358
  @media (max-width: 768px) {
359
- .markdown-text, .markdown-text p {
360
- font-size: 1.1rem; /* ≈18 px */
361
- }
362
  .markdown-text h1 { font-size: 1.6rem; }
363
  .markdown-text h2 { font-size: 1.4rem; }
364
  .markdown-text h3 { font-size: 1.25rem; }
@@ -368,18 +365,18 @@ markdown_css = """
368
  tab_css = """
369
  /* Tabs ▸ target ALL tab buttons using the actual structure */
370
  .tabs .tab-container > button {
371
- /* Add your desired styles here */
372
- font-size: 1.6rem !important; /* Example: Adjust size */
373
- font-weight: 500; /* Example: Adjust weight */
374
- font-style: normal; /* Example: Set style */
375
- color: #333; /* Example: Set color */
376
- /* Add any other font/format properties */
377
  }
378
 
379
  /* Optional: Style for the selected tab button if needed */
380
  .tabs .tab-container > button.selected {
381
- font-weight: 700; /* Example: Make selected tab bold */
382
- color: #0056b3; /* Example: Different color for selected */
 
383
  }
384
  """
385
 
@@ -388,211 +385,65 @@ radio_css = """
388
  /* --- Radio Button Styling --- */
389
 
390
  /* Style for the main label ("Select Category:") */
391
- .gradio-radio > label span { /* This targets the "Select Category:" part */
392
- font-size: 1.6rem !important; /* <<< INCREASED from 1.2rem */
393
  font-weight: 600;
394
- color: #2a6099;
395
  padding-bottom: 10px;
396
  display: inline-block;
397
  }
398
 
399
  /* Style for the individual option labels (Overall, MLE-Lite, etc.) */
400
- .gradio-radio .wrap > label > span { /* <--- Targets the individual option text */
401
- font-size: 1.0rem !important; /* <<< DECREASED from 1.2rem */
402
  font-family: Verdana, Geneva, sans-serif;
403
- color: #444;
404
  font-weight: normal;
405
  font-style: normal;
406
  padding-left: 6px;
407
  }
408
 
409
- /* Optional: Style for the selected option's text */
410
- .gradio-radio .wrap > label.selected > span { /* <--- Style for selected option */
411
- font-weight: normal;
412
- color: #87CEEB;
 
413
  }
414
-
415
- /* Optional: Style the container for options if needed */
416
- /* .gradio-radio .wrap { } */ /* Previously suggested .gr-form, but .wrap is correct */
417
-
418
  """
419
 
420
  citation_css = """
421
  /* Accordion Header Text ("📙 Citation") */
422
  .gradio-accordion button.label-wrap > span.svelte-1w6vloh {
423
- font-size: 1.4rem !important; /* Adjust size */
424
- font-weight: 600; /* Adjust weight */
425
- color: #8B4513; /* Adjust color (SaddleBrown example) */
426
- font-family: Georgia, serif; /* Adjust font */
427
  }
428
 
429
  /* Citation Textbox Label ("Copy the following snippet...") */
430
  #citation-button span.svelte-1gfkn6j {
431
- font-size: 0.95rem !important; /* Adjust size */
432
- color: #666; /* Adjust color */
433
- font-style: normal; /* Adjust style (e.g., italic) */
434
- display: block; /* Make it a block to add margin */
435
- margin-bottom: 5px; /* Add space below label */
436
- }
437
-
438
- /* Citation Textbox Content (The actual text) */
439
- #citation-button textarea {
440
- font-size: 1.0rem !important; /* Adjust size */
441
- font-family: monospace; /* Adjust font (monospace often used for citations) */
442
- color: #222; /* Adjust text color */
443
- line-height: 1.6; /* Adjust line spacing */
444
- background-color: #fdfdfd; /* Adjust background color */
445
- border: 1px solid #ccc; /* Adjust border */
446
- }
447
- """
448
-
449
- about_image_css = """
450
- /* --- CSS for the Image container in the About Tab --- */
451
- #about-image {
452
- background-color: transparent !important;
453
- padding: 0 !important;
454
- border: none !important;
455
- }
456
-
457
- /* --- CSS for the Image tag itself in the About Tab --- */
458
- #about-image img { /* Target the actual <img> tag */
459
- display: block;
460
- max-width: 1000px;
461
- width: 90%;
462
- height: auto;
463
- margin: 0rem auto 0rem auto; /* Adjusted margin slightly */
464
- border-radius: 8px;
465
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
466
- }
467
-
468
- /* Optional: Different styles for smaller screens */
469
- @media (max-width: 768px) {
470
- #about-image img {
471
- max-width: 100%;
472
- width: 95%;
473
- margin-top: 1.5rem;
474
- }
475
- }
476
- """
477
-
478
-
479
- intro_image_css = """
480
- /* --- CSS for the Image container in the About Tab --- */
481
- #intro-image {
482
- background-color: transparent !important;
483
- padding: 0 !important;
484
- border: none !important;
485
- }
486
-
487
- /* --- CSS for the Image tag itself in the About Tab --- */
488
- #intro-image img { /* Target the actual <img> tag */
489
  display: block;
490
- max-width: 800px;
491
- width: 90%;
492
- height: auto;
493
- margin: 0rem auto 0rem auto; /* Adjusted margin slightly */
494
- border-radius: 8px;
495
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
496
  }
497
 
498
- /* Optional: Different styles for smaller screens */
499
- @media (max-width: 768px) {
500
- #intro-image img {
501
- max-width: 100%;
502
- width: 95%;
503
- margin-top: 1.5rem;
504
- }
 
 
 
 
505
  }
506
  """
507
- final_css = f"{custom_css}\n{base_css}\n{intro_css}\n{markdown_css}\n{tab_css}\n{radio_css}\n{citation_css}\n{about_image_css}\n{intro_image_css}"
508
 
509
- # ---------------------------------------------------------------------------
510
- # Build the Gradio UI
511
- # ---------------------------------------------------------------------------
512
-
513
- demo = gr.Blocks(css=final_css, theme=gr.themes.Soft())
514
-
515
- with demo:
516
- # NEW ⭐: image immediately below the introduction
517
- with gr.Row():
518
- gr.Image(
519
- value="icon_long.jpg",
520
- show_label=False,
521
- elem_id="intro-image",
522
- )
523
- # Title
524
- gr.HTML(TITLE)
525
-
526
- # Introduction (Markdown wrapped so CSS can target .introduction-wrapper)
527
- with gr.Row():
528
- gr.Markdown(INTRODUCTION_TEXT, elem_classes="introduction-wrapper")
529
-
530
- with gr.Tabs(elem_classes="tab-buttons"):
531
- # ------------------ Leaderboard tab ------------------
532
- with gr.TabItem("🏅 MLE-Dojo Benchmark", id=0):
533
- with gr.Column():
534
- # --- This is the title you mentioned. "虚拟" is not present here. ---
535
- # gr.Markdown("## Model Elo Rankings by Category", elem_classes="markdown-text")
536
-
537
- category_selector = gr.Radio(
538
- choices=CATEGORIES,
539
- label="Select Category:", # The label whose size is increased via CSS
540
- value=DEFAULT_CATEGORY,
541
- interactive=True,
542
- elem_classes="gradio-radio", # Class used for CSS targeting
543
- )
544
-
545
- leaderboard_df_component = gr.Dataframe(
546
- value=update_leaderboard(DEFAULT_CATEGORY),
547
- headers=["Rank", "Model", "Organizer", "License", "Elo Score"],
548
- datatype=["number", "html", "str", "str", "number"],
549
- interactive=False,
550
- row_count=(len(master_df), "fixed"),
551
- col_count=(5, "fixed"),
552
- wrap=True,
553
- elem_id="leaderboard-table",
554
- )
555
-
556
- category_selector.change(update_leaderboard, category_selector, leaderboard_df_component)
557
-
558
- # ------------------ About tab ------------------
559
- with gr.TabItem("📝 About", id=1):
560
- # NEW: wrap in a full-width column
561
- with gr.Column():
562
- gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
563
-
564
- # NEW ⭐: image immediately below the introduction
565
- with gr.Row():
566
- gr.Image(
567
- value="overview.jpg",
568
- show_label=False,
569
- elem_id="about-image",
570
- )
571
-
572
- # Citation accordion (bottom of page)
573
- with gr.Accordion("📙 Citation", open=False, elem_classes="gradio-accordion"):
574
- gr.Textbox(
575
- value=CITATION_BUTTON_TEXT,
576
- label=CITATION_BUTTON_LABEL,
577
- lines=8,
578
- elem_id="citation-button",
579
- show_copy_button=True,
580
- )
581
-
582
- # ---------------------------------------------------------------------------
583
- # Scheduler (optional) & launch
584
- # ---------------------------------------------------------------------------
585
- if __name__ == "__main__":
586
- try:
587
- if callable(restart_space) and REPO_ID != "your/space-id":
588
- scheduler = BackgroundScheduler()
589
- scheduler.add_job(restart_space, "interval", seconds=1800)
590
- scheduler.start()
591
- print("Scheduler started for space restart.")
592
- else:
593
- print("Space restart scheduler not started (no REPO_ID or restart function).")
594
- except Exception as exc:
595
- print(f"Scheduler init failed: {exc}")
596
-
597
- print("Launching Gradio app…")
598
- demo.launch()
 
8
  font size, family and alignment are now reliably applied.
9
  3. All new comments are in English for clarity.
10
  4. Adjusted font sizes for Radio button labels per user request.
11
+ 5. **Added dark mode support** using `@media (prefers-color-scheme: dark)`
12
+ to override conflicting styles and ensure readability in dark themes.
13
  """
14
 
15
  import gradio as gr
 
27
  EVALUATION_QUEUE_TEXT, # still referenced in commented‑out submit tab
28
  INTRODUCTION_TEXT,
29
  LLM_BENCHMARKS_TEXT,
30
+ TITLE, # contains <h1 id="main-leaderboard-title">
31
  )
32
 
33
  try:
 
215
  # Insert actual restart logic if needed.
216
 
217
  # ---------------------------------------------------------------------------
218
+ # CSS: project CSS (custom_css) + enhanced overrides + DARK MODE SUPPORT
219
  # ---------------------------------------------------------------------------
220
 
221
+ # --- CLEAN introduction typography override ---
222
  intro_css = """
223
  /* --------------------------------------------------
224
  INTRODUCTION BLOCK (font, size, alignment)
225
  -------------------------------------------------- */
226
  .introduction-wrapper, .introduction-section {
227
+ font-family: Arial, sans-serif; /* Added sans-serif fallback */
228
  font-size: 1.3rem !important; /* ≈22–23 px */
229
  line-height: 1.75;
230
+ /* color: #344054; */ /* Rely on theme for base text color */
231
  text-align: center;
232
  max-width: 1000px;
233
  margin: 0 auto 1rem auto;
 
235
  .introduction-wrapper p, .introduction-section p {
236
  font-size: 1.3rem !important; /* ≈22–23 px */
237
  margin-bottom: 0.5rem;
238
+ /* color: inherit; */ /* Inherit color from parent/theme */
239
  }
240
  @media (max-width: 768px) {
241
  .introduction-wrapper, .introduction-section {
242
+ font-size: 1.3rem !important; /* Maintain size on mobile */
243
  }
244
  }
245
  """
246
 
247
  # --- Existing CSS (base layout, table, etc.) ---
248
+ # Removed hardcoded light background/text colors where possible
249
+ # Kept structural styles and specific element styling
250
  base_css = """
251
  /* Base & layout overrides (truncated for brevity) */
252
  body {
253
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
254
  Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
255
+ font-size: 1.3em; /* Slightly increased base size */
256
  line-height: 1.6;
257
+ /* background-color: #f8f9fa; REMOVED - Rely on theme */
258
+ /* color: #343a40; REMOVED - Rely on theme */
259
  }
260
 
261
  .gradio-container {
 
267
  #main-leaderboard-title {
268
  font-size: 3.2em;
269
  font-weight: 700;
270
+ /* color: #212529; REMOVED - Rely on theme */
271
  text-align: center;
272
  margin-bottom: 1.5rem;
273
  padding-bottom: 0.5rem;
274
+ border-bottom: 2px solid var(--border-color-primary); /* Use Gradio variable */
275
  }
276
 
277
+ /* Leaderboard table */
278
  #leaderboard-table th {
279
+ /* background-color: #e9ecef; REMOVED - Rely on theme header bg */
280
  font-size: 1.3em;
281
  font-weight: 500;
282
+ /* color: var(--table-header-text-color, inherit); */ /* Use theme variable or inherit */
283
  }
284
  #leaderboard-table td {
285
  font-size: 1.1em;
286
+ /* color: var(--table-body-text-color, inherit); */ /* Use theme variable or inherit */
287
  }
288
  #leaderboard-table .model-link {
289
+ color: var(--link-text-color, #0056b3); /* Use theme link color or fallback */
290
  font-weight: 500;
291
  text-decoration: none;
292
  }
 
296
 
297
  #leaderboard-table {
298
  border-radius: 0.75rem;
299
+ overflow: hidden;
300
+ border: 1px solid var(--border-color-primary); /* Use Gradio variable */
301
  }
302
 
303
  #leaderboard-table th,
304
  #leaderboard-table td {
305
+ padding: 0.9rem 1.2rem;
306
+ line-height: 1.4;
 
 
 
 
 
 
 
307
  }
308
  """
309
 
 
313
  =============================== */
314
  .markdown-text, .markdown-text p {
315
  font-family: Arial, Helvetica, sans-serif;
316
+ font-size: 1.1rem;
317
+ line-height: 1.75;
318
+ /* color: #344054; REMOVED - Rely on theme */
319
  margin-bottom: 0.9rem;
320
  }
321
 
 
322
  .markdown-text h1,
323
  .markdown-text h2,
324
  .markdown-text h3 {
325
+ /* color: #212529; REMOVED - Rely on theme */
326
  font-weight: 600;
327
  line-height: 1.3;
328
  margin: 1.4rem 0 0.8rem 0;
329
  }
330
+ .markdown-text h1 { font-size: 1.7rem; }
331
+ .markdown-text h2 { font-size: 1.5rem; }
332
+ .markdown-text h3 { font-size: 1.3rem; }
 
333
 
334
  .markdown-text ul,
335
  .markdown-text ol {
336
+ padding-left: 1.6rem;
337
  margin-bottom: 1.1rem;
338
  }
339
 
340
+ /* Code blocks - light mode */
341
  .markdown-text pre, .markdown-text code {
342
  font-family: "Source Code Pro", "Menlo", monospace;
343
+ background-color: #f1f3f5; /* Light background for light mode */
344
+ color: #333; /* Dark text for light mode */
345
  border-radius: 0.4rem;
346
+ border: 1px solid #dee2e6; /* Light border */
347
  }
348
  .markdown-text pre {
349
  padding: 1rem 1.2rem;
 
354
  font-size: 0.95rem;
355
  }
356
 
 
357
  @media (max-width: 768px) {
358
+ .markdown-text, .markdown-text p { font-size: 1.1rem; }
 
 
359
  .markdown-text h1 { font-size: 1.6rem; }
360
  .markdown-text h2 { font-size: 1.4rem; }
361
  .markdown-text h3 { font-size: 1.25rem; }
 
365
  tab_css = """
366
  /* Tabs ▸ target ALL tab buttons using the actual structure */
367
  .tabs .tab-container > button {
368
+ font-size: 1.6rem !important;
369
+ font-weight: 500;
370
+ font-style: normal;
371
+ /* color: #333; REMOVED - Rely on theme */
372
+ /* Using theme variables where possible might be better, but direct styling is okay */
 
373
  }
374
 
375
  /* Optional: Style for the selected tab button if needed */
376
  .tabs .tab-container > button.selected {
377
+ font-weight: 700;
378
+ /* color: #0056b3; */ /* Use theme's primary color if possible */
379
+ color: var(--primary-500, #0056b3); /* Example using a common theme variable name */
380
  }
381
  """
382
 
 
385
  /* --- Radio Button Styling --- */
386
 
387
  /* Style for the main label ("Select Category:") */
388
+ .gradio-radio > label span { /* Targets the main label text */
389
+ font-size: 1.6rem !important;
390
  font-weight: 600;
391
+ color: var(--primary-500, #2a6099); /* Use theme primary or fallback */
392
  padding-bottom: 10px;
393
  display: inline-block;
394
  }
395
 
396
  /* Style for the individual option labels (Overall, MLE-Lite, etc.) */
397
+ .gradio-radio .wrap > label > span { /* Targets the individual option text */
398
+ font-size: 1.0rem !important;
399
  font-family: Verdana, Geneva, sans-serif;
400
+ /* color: #444; REMOVED - Rely on theme for base option color */
401
  font-weight: normal;
402
  font-style: normal;
403
  padding-left: 6px;
404
  }
405
 
406
+ /* Style for the selected option's text */
407
+ .gradio-radio .wrap > label.selected > span { /* Style for selected option */
408
+ font-weight: bold; /* Make selected bold for emphasis */
409
+ color: var(--primary-500, #0056b3); /* Use theme's primary color */
410
+ /* color: #87CEEB; Original light blue - might lack contrast in light mode */
411
  }
 
 
 
 
412
  """
413
 
414
  citation_css = """
415
  /* Accordion Header Text ("📙 Citation") */
416
  .gradio-accordion button.label-wrap > span.svelte-1w6vloh {
417
+ font-size: 1.4rem !important;
418
+ font-weight: 400;
419
+ color: var(--neutral-800, #8B4513); /* Use theme neutral or fallback brown */
420
+ font-family: Georgia, serif;
421
  }
422
 
423
  /* Citation Textbox Label ("Copy the following snippet...") */
424
  #citation-button span.svelte-1gfkn6j {
425
+ font-size: 0.95rem !important;
426
+ /* color: #666; REMOVED - Rely on theme secondary text color */
427
+ color: var(--neutral-500, #666);
428
+ font-style: normal;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  display: block;
430
+ margin-bottom: 5px;
 
 
 
 
 
431
  }
432
 
433
+ /* Citation Textbox Content (The actual text) - Light mode */
434
+ #citation-button textarea {
435
+ font-size: 1.0rem !important;
436
+ font-family: monospace;
437
+ /* color: #222; REMOVED - Rely on theme */
438
+ line-height: 1.6;
439
+ /* background-color: #fdfdfd; REMOVED - Rely on theme input bg */
440
+ /* border: 1px solid #ccc; REMOVED - Rely on theme border */
441
+ border: 1px solid var(--border-color-accent);
442
+ background-color: var(--input-background-fill);
443
+ color: var(--input-text-color);
444
  }
445
  """
 
446
 
447
+ # Combined Image CSS (Intro + About) - Adjusted shadow
448
+ image_css = """
449
+ /* --- CSS for Image