Jerrycool commited on
Commit
7c5eced
·
verified ·
1 Parent(s): d96489f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +205 -1
app.py CHANGED
@@ -446,4 +446,208 @@ citation_css = """
446
 
447
  # Combined Image CSS (Intro + About) - Adjusted shadow
448
  image_css = """
449
- /* --- CSS for Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
 
447
  # Combined Image CSS (Intro + About) - Adjusted shadow
448
  image_css = """
449
+ /* --- CSS for Image containers (Intro/About) --- */
450
+ #intro-image, #about-image {
451
+ background-color: transparent !important;
452
+ padding: 0 !important;
453
+ border: none !important;
454
+ box-shadow: none !important; /* Remove container shadow if any */
455
+ }
456
+
457
+ /* --- CSS for Image tags themselves (Intro/About) --- */
458
+ #intro-image img, #about-image img { /* Target the actual <img> tag */
459
+ display: block;
460
+ height: auto;
461
+ margin: 0rem auto 1rem auto; /* Center and add bottom margin */
462
+ border-radius: 8px;
463
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Default shadow for light mode */
464
+ }
465
+ #intro-image img {
466
+ max-width: 800px;
467
+ width: 90%;
468
+ }
469
+ #about-image img {
470
+ max-width: 1000px;
471
+ width: 90%;
472
+ }
473
+
474
+
475
+ /* Optional: Different styles for smaller screens */
476
+ @media (max-width: 768px) {
477
+ #intro-image img, #about-image img {
478
+ max-width: 100%;
479
+ width: 95%;
480
+ margin-top: 1.5rem;
481
+ }
482
+ }
483
+ """
484
+
485
+ # --- ⭐ NEW: Dark Mode Overrides ⭐ ---
486
+ dark_mode_css = """
487
+ @media (prefers-color-scheme: dark) {
488
+ body {
489
+ /* Ensure theme handles dark bg/text */
490
+ }
491
+
492
+ #main-leaderboard-title {
493
+ /* color: var(--body-text-color); */ /* Ensure title color matches theme */
494
+ border-bottom-color: var(--border-color-primary); /* Ensure border matches theme */
495
+ }
496
+
497
+ /* Make links slightly brighter if needed */
498
+ #leaderboard-table .model-link {
499
+ /* color: var(--link-text-color-dark, #58a6ff); */ /* Optional: specific dark link color */
500
+ }
501
+
502
+ #leaderboard-table {
503
+ border-color: var(--border-color-primary); /* Ensure border matches theme */
504
+ }
505
+
506
+ /* Ensure table header/cell text contrasts with dark theme background */
507
+ #leaderboard-table th {
508
+ /* color: var(--table-header-text-color); */
509
+ }
510
+ #leaderboard-table td {
511
+ /* color: var(--table-body-text-color); */
512
+ }
513
+
514
+
515
+ /* Dark mode for Markdown Code blocks */
516
+ .markdown-text pre, .markdown-text code {
517
+ background-color: #2d333b; /* Dark background */
518
+ color: #c9d1d9; /* Light text */
519
+ border: 1px solid #444c56; /* Darker border */
520
+ }
521
+
522
+ /* Dark mode for Radio Button selected option */
523
+ .gradio-radio .wrap > label.selected > span {
524
+ color: var(--primary-300, #add8e6); /* Lighter blue for dark background */
525
+ font-weight: bold;
526
+ }
527
+
528
+ /* Dark mode for Citation Textbox */
529
+ #citation-button textarea {
530
+ /* background-color: #22272e; */ /* Darker input bg */
531
+ /* color: #adbac7; */ /* Lighter input text */
532
+ /* border-color: #444c56; */ /* Darker border */
533
+ background-color: var(--input-background-fill); /* Rely on theme dark vars */
534
+ color: var(--input-text-color);
535
+ border: 1px solid var(--border-color-accent);
536
+ }
537
+ /* Ensure Citation Accordion Header text is visible */
538
+ .gradio-accordion button.label-wrap > span.svelte-1w6vloh {
539
+ /* color: var(--neutral-300, #D2B48C); */ /* Lighter brown/tan */
540
+ }
541
+ /* Ensure Citation Textbox Label is visible */
542
+ #citation-button span.svelte-1gfkn6j {
543
+ /* color: var(--neutral-400, #999); */ /* Lighter grey */
544
+ }
545
+
546
+
547
+ /* Dark mode for Image shadows */
548
+ #intro-image img, #about-image img {
549
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); /* Darker shadow for dark mode */
550
+ /* Or use a light shadow: */
551
+ /* box-shadow: 0 4px 8px rgba(255, 255, 255, 0.1); */
552
+ }
553
+ }
554
+ """
555
+
556
+
557
+ # Combine all CSS parts
558
+ final_css = f"{custom_css}\n{base_css}\n{intro_css}\n{markdown_css}\n{tab_css}\n{radio_css}\n{citation_css}\n{image_css}\n{dark_mode_css}"
559
+
560
+ # ---------------------------------------------------------------------------
561
+ # Build the Gradio UI
562
+ # ---------------------------------------------------------------------------
563
+
564
+ # Use a theme that supports dark mode well, like Soft or Default
565
+ demo = gr.Blocks(css=final_css, theme=gr.themes.Soft()) # Soft theme is generally good
566
+
567
+ with demo:
568
+ # NEW ⭐: image immediately below the title (Moved from below intro for better flow)
569
+ with gr.Row():
570
+ gr.Image(
571
+ value="icon_long.jpg",
572
+ show_label=False,
573
+ elem_id="intro-image", # Keep ID for CSS targeting
574
+ # container=False # Optional: removes Gradio's container styling if needed
575
+ )
576
+ # Title
577
+ gr.HTML(TITLE)
578
+
579
+ # Introduction (Markdown wrapped so CSS can target .introduction-wrapper)
580
+ with gr.Row():
581
+ gr.Markdown(INTRODUCTION_TEXT, elem_classes="introduction-wrapper")
582
+
583
+
584
+ with gr.Tabs(elem_classes="tab-buttons"):
585
+ # ------------------ Leaderboard tab ------------------
586
+ with gr.TabItem("🏅 MLE-Dojo Benchmark", id=0):
587
+ with gr.Column():
588
+ # gr.Markdown("## Model Elo Rankings by Category", elem_classes="markdown-text") # Optional sub-header
589
+
590
+ category_selector = gr.Radio(
591
+ choices=CATEGORIES,
592
+ label="Select Category:", # The label whose size is increased via CSS
593
+ value=DEFAULT_CATEGORY,
594
+ interactive=True,
595
+ elem_classes="gradio-radio", # Class used for CSS targeting
596
+ )
597
+
598
+ leaderboard_df_component = gr.Dataframe(
599
+ value=update_leaderboard(DEFAULT_CATEGORY),
600
+ headers=["Rank", "Model", "Organizer", "License", "Elo Score"],
601
+ datatype=["number", "html", "str", "str", "number"],
602
+ interactive=False,
603
+ row_count=(len(master_df), "fixed"),
604
+ col_count=(5, "fixed"),
605
+ wrap=True,
606
+ elem_id="leaderboard-table",
607
+ )
608
+
609
+ category_selector.change(update_leaderboard, category_selector, leaderboard_df_component)
610
+
611
+ # ------------------ About tab ------------------
612
+ with gr.TabItem("📝 About", id=1):
613
+ # NEW: wrap in a full-width column
614
+ with gr.Column():
615
+ gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
616
+
617
+ # NEW ⭐: image immediately below the text in the About tab
618
+ with gr.Row():
619
+ gr.Image(
620
+ value="overview.jpg",
621
+ show_label=False,
622
+ elem_id="about-image", # Keep ID for CSS targeting
623
+ # container=False # Optional: removes Gradio's container styling
624
+ )
625
+
626
+ # Citation accordion (bottom of page)
627
+ with gr.Accordion("📙 Citation", open=False, elem_classes="gradio-accordion"):
628
+ gr.Textbox(
629
+ value=CITATION_BUTTON_TEXT,
630
+ label=CITATION_BUTTON_LABEL,
631
+ lines=8,
632
+ elem_id="citation-button",
633
+ show_copy_button=True,
634
+ )
635
+
636
+ # ---------------------------------------------------------------------------
637
+ # Scheduler (optional) & launch
638
+ # ---------------------------------------------------------------------------
639
+ if __name__ == "__main__":
640
+ try:
641
+ if callable(restart_space) and REPO_ID != "your/space-id":
642
+ scheduler = BackgroundScheduler()
643
+ # Schedule restart every 30 minutes (1800 seconds)
644
+ scheduler.add_job(restart_space, "interval", seconds=1800)
645
+ scheduler.start()
646
+ print("Scheduler started for space restart.")
647
+ else:
648
+ print("Space restart scheduler not started (no REPO_ID or restart function).")
649
+ except Exception as exc:
650
+ print(f"Scheduler init failed: {exc}")
651
+
652
+ print("Launching Gradio app…")
653
+ demo.launch()