File size: 23,502 Bytes
13d0b34
d38e9d6
c9d0ebc
 
 
 
 
 
3879ed2
0f02e4d
69a850d
c9d0ebc
48fcbed
69a850d
 
 
3879ed2
 
dd90000
ab96702
69a850d
 
3879ed2
ab96702
6a11835
 
 
d38e9d6
7de5ac6
 
 
23da439
cb0c5af
c9d0ebc
 
7de5ac6
d38e9d6
cd19179
d38e9d6
7de5ac6
d38e9d6
3879ed2
6a11835
d38e9d6
 
 
48fcbed
d38e9d6
09f0b19
7de5ac6
d38e9d6
6286da1
1d983ea
6286da1
 
1d983ea
6286da1
d38e9d6
c9d0ebc
0f02e4d
 
 
 
 
 
 
 
d2058b2
 
6a11835
 
d2058b2
cb0c5af
6a11835
d2058b2
6a11835
d2058b2
 
dd90000
cb0c5af
d2058b2
 
3879ed2
c9d0ebc
 
 
 
71959f6
383d326
71959f6
 
 
 
 
 
 
 
 
 
 
d38e9d6
 
c9d0ebc
 
48fcbed
 
c9d0ebc
 
 
 
 
0f02e4d
 
48fcbed
 
0f02e4d
 
 
 
 
65e3518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f02e4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65e3518
 
 
 
 
 
 
 
 
 
3879ed2
8b9a76f
 
 
c9d0ebc
 
8b9a76f
 
d38e9d6
 
0f02e4d
 
 
 
 
 
 
 
 
 
1a40444
c9d0ebc
 
 
 
 
 
 
 
 
1a40444
 
 
 
 
cb0c5af
 
 
 
48fcbed
1a40444
48fcbed
c9d0ebc
cb0c5af
1a40444
48fcbed
 
d2058b2
48fcbed
 
 
d38e9d6
 
cb0c5af
8b9a76f
 
9c9d253
cb0c5af
 
8b9a76f
cb0c5af
 
9c9d253
3879ed2
1a40444
 
1d983ea
 
75e6a8b
6286da1
1d983ea
 
8e4895a
48fcbed
1d983ea
75e6a8b
1d983ea
 
69a850d
 
 
1d983ea
7de5ac6
 
8e4895a
 
1d983ea
 
 
7532dab
 
cb0c5af
7532dab
 
cb0c5af
 
7532dab
cb0c5af
 
7532dab
 
 
 
 
 
cb0c5af
 
c9d0ebc
 
 
 
 
 
d2a6015
 
0f02e4d
d2a6015
6a11835
 
d2a6015
 
 
 
48fcbed
d2a6015
 
3879ed2
c9d0ebc
3879ed2
d2a6015
3879ed2
0f02e4d
 
d38e9d6
3879ed2
d38e9d6
3879ed2
d2a6015
3879ed2
cb0c5af
 
d2058b2
75e6a8b
d2058b2
 
cb0c5af
 
75e6a8b
cb0c5af
 
7532dab
 
cb0c5af
 
7532dab
 
 
cb0c5af
d38e9d6
2513576
6d6d611
2513576
d38e9d6
3879ed2
7de5ac6
 
3879ed2
75e6a8b
3879ed2
7de5ac6
d38e9d6
7de5ac6
3879ed2
1d983ea
 
6a11835
 
 
3879ed2
 
d2a6015
3879ed2
 
cd19179
 
 
69a850d
 
 
d2a6015
d2058b2
cb0c5af
6a11835
 
 
 
d2a6015
3879ed2
 
0f02e4d
 
 
 
 
 
 
3879ed2
 
 
cb0c5af
6a11835
 
 
3879ed2
 
 
 
 
dd90000
 
 
 
 
 
 
 
3879ed2
d2058b2
b128212
 
dd90000
0f02e4d
 
 
 
 
 
 
 
c9d0ebc
7bfbc7e
 
d2058b2
c9d0ebc
d2058b2
c9d0ebc
d2058b2
 
 
 
 
c9d0ebc
d2058b2
 
48fcbed
c9d0ebc
 
d2058b2
 
 
c9d0ebc
 
1a40444
48fcbed
c9d0ebc
 
 
 
cb0c5af
c9d0ebc
1a40444
 
 
d38e9d6
48fcbed
65e3518
 
71959f6
65e3518
 
 
48fcbed
c9d0ebc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f02e4d
 
 
 
 
 
c9d0ebc
 
 
 
 
6a11835
 
 
 
 
 
 
 
 
c9d0ebc
 
 
 
 
 
 
 
 
 
 
 
 
6a11835
c9d0ebc
 
 
 
 
 
 
 
 
 
 
0f02e4d
c9d0ebc
 
 
 
 
 
0f02e4d
 
 
 
c9d0ebc
 
 
 
 
 
 
 
0f02e4d
 
 
 
 
 
d2a6015
6a11835
 
0f02e4d
6a11835
 
 
 
 
 
 
 
 
c9d0ebc
d38e9d6
0f02e4d
 
 
 
 
 
 
cb0c5af
 
 
c9d0ebc
cb0c5af
d38e9d6
 
 
 
c9d0ebc
 
 
 
 
 
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
"""Gradio front-end for the PRIMO public benchmark.

A left rail navigates six pages: Boards (a grid of every board), Board (one
leaderboard at a time), Tasks ("what is actually being tested?"), Submit ("how
do I enter?"), Contribute ("what is missing, and how do I add it?"), Method
("can I trust this?"). Every page is addressable -- ``?board=<slug>`` opens a
board and ``?tab=contribute`` opens a tab -- which is what the rail links and the
open cards use. The tab strip is hidden in CSS; the rail is the navigation.

Choose one modality and upload its embedding file (rows keyed by ``dataset_id``
+ ``sample_id``); a fixed task probe scores each task (a dataset may carry
several hidden targets). Results roll up into boards -- the whole modality, one
therapeutic area, one task family -- and each board ranks the models that
covered every task our baseline scored, one column per category in its native
metric (AUROC, Pearson, or centered Spearman), plus a ``Mean`` of those columns
that orders the rows and is labelled as the cross-metric average it is.

Disclosure policy -- what the public pages may show:
  per task   disease, tissue, area, modality, what is predicted, class names, n, metric
  aggregated the public archives the cohorts sit in, and their licences
  never      study accessions, dataset_id -> cohort, hub keys, per-sample labels,
             pairing identifiers or post-treatment responses
Naming the accession behind ``d002`` would put every label one GEO download
away, so ``sources`` is collapsed to its archive (NCBI GEO / EMBL-EBI
ArrayExpress) and ``citation`` is never rendered at all. Submitters can publish
an optional institution, paper link and an author-submission check; legacy private
usernames remain hidden.

Failures are surfaced by who owns them: a bad file tells the submitter exactly
what to fix; an evaluator-side failure says "our side, please retry" and logs
the traceback rather than blaming the submission.

A page load is ONE fetch: ``_init`` pulls the registry, the boards and the
persisted results once and threads that state into every page, rather than each
page fetching for itself.
"""

import json
import os
import traceback
from datetime import datetime, timezone
from pathlib import Path
from uuid import uuid4

import gradio as gr
import pandas as pd
from boards import Board, build_boards, by_slug
from evaluator import (
    EMBEDDING,
    EvaluatorError,
    SubmissionError,
    _norm_id,
    fetch_manifest,
    fetch_tasks_registry,
    manifest_ids,
    score_all,
    scoreable_tasks,
)
from leaderboard import RESERVED_COLUMNS, source_repositories
from render import (
    evaluation_confirmation,
    evaluation_status,
    rail_html,
    render_board,
    render_boards,
    render_tasks,
)
from results import (
    BASELINE_TAG,
    INSTITUTION,
    IS_AUTHOR_SUBMISSION,
    IS_BASELINE,
    OWNER,
    PAPER_LINK,
    RESULT_COLUMNS,
    SUBMISSION_ID,
    append_results,
    append_submission,
    archive_submission,
    owner_of,
    read_results,
)

HERE = Path(__file__).parent
PAGES_DIR = HERE / "pages"
CSS_PATH = str(HERE / "primo.css")
ALLOWED_PATHS = [str(HERE / "assets"), str(HERE / "fonts")]
SOCIAL_PREVIEW_URL = (
    "https://huggingface.co/spaces/PRIMOmics/primo-eval/resolve/main/"
    "assets/primo-social-preview.png"
)
PAGE_HEAD = f"""
<meta property="og:title" content="PRIMO Benchmark" />
<meta property="og:description" content="A blind benchmark for omics foundation models." />
<meta property="og:image" content="{SOCIAL_PREVIEW_URL}" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="PRIMO Benchmark" />
<meta name="twitter:description" content="A blind benchmark for omics foundation models." />
<meta name="twitter:image" content="{SOCIAL_PREVIEW_URL}" />
"""

TOKEN = os.environ.get("HF_TOKEN")
TAB_IDS = ("boards", "board", "tasks", "submit", "contribute", "method")
FOOT_TABS = frozenset({"tasks", "submit", "contribute", "method"})

THEME = gr.themes.Base(
    font=["Funnel Sans", "sans-serif"], font_mono=["DM Mono", "monospace"]
)

SUBMIT_HEAD = (
    '<div class="pm-head"><div><h1>Submit a model</h1>'
    "<p>One model, one modality. Partial coverage is fine within that modality. "
    "You are ranked on every board you cover in full.</p></div></div>"
)

MODALITY_CHOICES = [
    ("Bulk RNAseq", "bulk-rna"),
    ("Single-cell RNAseq", "single-cell-rna"),
]

TABLE_SORT_JS = """
() => {
  if (window.pmTableSortBound) return;
  window.pmTableSortBound = true;

  const value = (cell) => {
    const text = cell.textContent.trim();
    if (!text || text.toLowerCase() === "n/a") return { missing: true, text };
    const number = Number(text.replaceAll(",", ""));
    return Number.isFinite(number) ? { missing: false, number, text } : { missing: false, text };
  };

  const sort = (header) => {
    const table = header.closest("table.pm-table");
    const body = table?.tBodies[0];
    if (!body) return;
    const index = Number(header.dataset.sortIndex);
    const direction = header.dataset.sortDirection === "asc" ? -1 : 1;
    const rows = Array.from(body.rows);

    rows.sort((left, right) => {
      const a = value(left.cells[index]);
      const b = value(right.cells[index]);
      if (a.missing || b.missing) return a.missing === b.missing ? 0 : a.missing ? 1 : -1;
      if (a.number !== undefined && b.number !== undefined) return direction * (a.number - b.number);
      return direction * a.text.localeCompare(b.text, undefined, { numeric: true });
    });
    rows.forEach((row) => body.append(row));
    table.querySelectorAll("th.pm-sort").forEach((cell) => {
      cell.dataset.sortDirection = "";
      cell.setAttribute("aria-sort", "none");
    });
    header.dataset.sortDirection = direction === 1 ? "asc" : "desc";
    header.setAttribute("aria-sort", direction === 1 ? "ascending" : "descending");
  };

  document.addEventListener("click", (event) => {
    const header = event.target.closest("th.pm-sort");
    if (header) sort(header);
  });
  document.addEventListener("click", (event) => {
    const evaluateButton = event.target.closest(
      "#pm-evaluate button, button#pm-evaluate"
    );
    if (!evaluateButton) return;
    if (evaluateButton.dataset.confirmed === "true") {
      delete evaluateButton.dataset.confirmed;
      return;
    }

    event.preventDefault();
    event.stopImmediatePropagation();
    const dialog = document.querySelector("#pm-evaluation-confirmation");
    if (!dialog) return;
    dialog.returnValue = "";
    dialog.addEventListener("close", () => {
      if (dialog.returnValue !== "confirm") return;
      evaluateButton.dataset.confirmed = "true";
      evaluateButton.click();
    }, { once: true });
    dialog.showModal();
  }, true);
  document.addEventListener("keydown", (event) => {
    if (event.key !== "Enter" && event.key !== " ") return;
    const header = event.target.closest("th.pm-sort");
    if (!header) return;
    event.preventDefault();
    sort(header);
  });
}
"""


def _page_text(name: str) -> str:
    """One ``pages/<tab>.md`` per prose tab, named after the tab it fills.

    Editing the site's words never means touching Python. The data pages (Boards,
    Board, Tasks) are generated markup instead.
    """
    return (PAGES_DIR / f"{name}.md").read_text()


def _download_help(modality: str | None) -> str:
    """Show the quickstart command for the selected modality."""
    if not modality:
        return "Select a modality to get its download command."
    return (
        f"```bash\npython quickstart.py --modality {modality} "
        "--out submission.parquet\n```"
    )


def _registry_by_id() -> dict[str, dict]:
    """Scoreable tasks keyed by task_id (dataset present in the public manifest).

    ``PRIMO_FIXTURE=1`` swaps the token-gated fetch for the test registry, so the
    app runs offline for local smoke-testing.
    """
    if os.environ.get("PRIMO_FIXTURE"):
        from conftest import REGISTRY

        return {task_id: dict(task) for task_id, task in REGISTRY.items()}
    datasets = manifest_ids(fetch_manifest(TOKEN))
    registry = scoreable_tasks(fetch_tasks_registry(TOKEN), datasets)
    return {_norm_id(task["task_id"]): task for task in registry}


PageState = tuple[dict[str, dict], list[Board], pd.DataFrame]


def _page_state() -> PageState:
    """Registry, boards and persisted results -- one fetch per render.

    A failed fetch yields empty structures so the page renders a "come back
    later" state instead of a stack trace. Every page is built from one of these,
    threaded through rather than refetched, so a page load is one round trip.
    """
    try:
        by_id = _registry_by_id()
        return by_id, build_boards(by_id), read_results(TOKEN)
    except Exception:  # noqa: BLE001
        traceback.print_exc()
        return {}, [], pd.DataFrame(columns=RESULT_COLUMNS)


def _about_text(by_id: dict[str, dict]) -> str:
    """Methodology + the archives the cohorts live in, never their accessions.

    The placeholder is substituted, not ``.format``-ed: a page of prose is free
    to contain a brace, and a stray one must not blow up the tab. An unreachable
    registry leaves ``by_id`` empty and the sentence falls back to a generic one.
    """
    repositories = source_repositories(list(by_id.values()))
    return _page_text("about").replace(
        "{repositories}", " and ".join(repositories) or "public archives"
    )


def _summary(result: dict, model_name: str) -> str:
    lines = [
        f"**{model_name}**: covered {result['n_datasets_scored']}/"
        f"{result['n_datasets_total']} datasets",
        "",
    ]
    for category, stats in sorted(result["categories"].items()):
        lines.append(f"- **{category}** ({stats['metric']}) = {stats['mean']:.3f}")
    if result["full_coverage"]:
        lines.append("\n✅ **full coverage.** You are ranked on every board.")
    else:
        lines.append(
            "\n⚠️ **partial coverage.** You are ranked on the boards whose scored "
            "tasks you covered in full, and your scores always appear in each "
            "board's **per-task** table."
        )
        if result["missing"]:
            lines.append(f"- missing from file: {result['missing']}")
        if result["incomplete"]:
            lines.append(f"- could not score: {result['incomplete']}")
    return "\n".join(lines)


def _results_frame() -> pd.DataFrame:
    """Every published row, or an empty frame if the fetch fails.

    A Hugging Face hiccup must not block a submission, so an empty frame leaves
    the name free rather than raising: fail-open on the ownership check.
    """
    try:
        return read_results(TOKEN)
    except Exception:  # noqa: BLE001
        traceback.print_exc()
        return pd.DataFrame(columns=RESULT_COLUMNS)


def _claimed_by(df: pd.DataFrame, model: str) -> str:
    """Who already owns this model name, or ``""``."""
    return owner_of(df, model)


def _rendered_board(slug: str | None) -> str:
    """The Board page for ``slug`` -- re-rendered after a submission saves."""
    by_id, boards, df = _page_state()
    return render_board(by_slug(boards, slug), df, by_id)


def evaluate(
    submission_path: str,
    modality: str | None,
    model_name: str,
    institution: str,
    is_author_submission: bool,
    email: str,
    paper_link: str,
    hf_model_link: str,
    notes: str,
    slug: str | None,
    profile: gr.OAuthProfile | None,
):
    def _refuse(message: str):
        return message, _rendered_board(slug)

    if profile is None:
        return _refuse("Please sign in with Hugging Face to submit.")
    if not modality:
        return _refuse("Please select a modality.")
    if not submission_path:
        return _refuse("Please upload a submission file.")
    if not model_name or not model_name.strip():
        return _refuse("Please enter a model name.")
    if not email or not email.strip():
        return _refuse("Please enter a contact email.")
    model = model_name.strip()
    if BASELINE_TAG in model.lower():
        return _refuse(
            f"`{BASELINE_TAG}` is reserved for our reference submissions. Please "
            "pick another model name."
        )
    if model in RESERVED_COLUMNS:
        return _refuse(
            f"`{model}` is a column of the per-task table. Please pick another "
            "model name."
        )
    published = _results_frame()
    claimed = _claimed_by(published, model)
    if claimed and claimed != profile.username:
        return _refuse(
            f"The model name `{model}` is already submitted by another HF account. "
            "Resubmission of the same model is allowed only from the same HF account. "
            "Please pick another name."
        )
    try:
        result = score_all(
            submission_path, TOKEN, modality=modality, representation=EMBEDDING
        )
    except SubmissionError as error:
        return _refuse(f"❌ {error}")
    except EvaluatorError as error:
        traceback.print_exc()
        return _refuse(
            "⚠️ We couldn't evaluate your submission. This is on our side, not your "
            f"file. Please try again in a moment.\n\n`{error}`"
        )
    except Exception as error:  # noqa: BLE001
        traceback.print_exc()
        return _refuse(f"⚠️ Unexpected evaluation error (our side): {error}")

    summary = _summary(result, model)
    now = datetime.now(timezone.utc)
    submitted_at = now.strftime("%Y-%m-%d %H:%M:%S.%f")
    submission_id = f"{now.strftime('%Y%m%dT%H%M%S.%fZ')}-{uuid4().hex}"
    rows = [
        {
            "model_name": model,
            "task_id": task.task_id,
            "score": round(float(task.score), 4),
            "repeat_scores": json.dumps(
                [round(value, 4) for value in task.repeat_scores]
            ),
            "diagnostics": json.dumps(
                {key: round(value, 4) for key, value in task.diagnostics.items()}
            ),
            "submitted_at": submitted_at,
            IS_BASELINE: False,
            OWNER: profile.username,
            INSTITUTION: (institution or "").strip(),
            IS_AUTHOR_SUBMISSION: bool(is_author_submission),
            PAPER_LINK: (paper_link or "").strip(),
            SUBMISSION_ID: submission_id,
        }
        for task in result["per_task"]
    ]
    if not rows:
        summary += (
            "\n\n⚠️ No valid scores were produced, so the model was not added to "
            "any board."
        )
        return summary, _rendered_board(slug)

    meta = {
        "model_name": model,
        "submitted_at": submitted_at,
        OWNER: profile.username,
        INSTITUTION: (institution or "").strip(),
        IS_AUTHOR_SUBMISSION: bool(is_author_submission),
        SUBMISSION_ID: submission_id,
        "email": email.strip(),
        "paper_link": (paper_link or "").strip(),
        "hf_model_link": (hf_model_link or "").strip(),
        "notes": (notes or "").strip(),
    }
    try:
        archive_submission(
            submission_path, model, submission_id, modality, submitted_at, TOKEN
        )
    except Exception as error:  # noqa: BLE001
        traceback.print_exc()
        summary += f"\n\n⚠️ scored, but the embedding archive was not saved: {error}"
        return summary, _rendered_board(slug)
    try:
        append_results(rows, TOKEN)
    except Exception as error:  # noqa: BLE001
        traceback.print_exc()
        summary += f"\n\n⚠️ archived, but the leaderboard was not saved: {error}"
        return summary, _rendered_board(slug)

    summary += f"\n\n✅ **{model} is now shown on the relevant boards.**"
    try:
        append_submission(meta, TOKEN)
    except Exception as error:  # noqa: BLE001
        traceback.print_exc()
        summary += f"\n\n⚠️ Contact metadata was not saved: {error}"
    return summary, _rendered_board(slug)


def _landing_tab(params: dict, has_board: bool) -> str:
    """Which page a visitor lands on: ``?tab=`` wins, then ``?board=``, else Boards.

    An unknown ``?tab=`` falls through to Boards rather than selecting nothing,
    which would render the Space with every panel collapsed.
    """
    tab = params.get("tab")
    if tab in TAB_IDS:
        return tab
    return "board" if has_board else "boards"


def _init(request: gr.Request):
    """Render every page from one fetch, landing where the query params ask."""
    by_id, boards, df = _page_state()
    params = dict(request.query_params) if request else {}
    board = by_slug(boards, params.get("board"))
    selected = _landing_tab(params, bool(params.get("board") and board))
    active_slug = board.slug if selected == "board" and board else None
    active_tab = selected if selected in FOOT_TABS else None
    return (
        gr.Tabs(selected=selected),
        rail_html(boards, active_slug, active_tab),
        board.slug if board else None,
        render_boards(boards, df, by_id),
        render_tasks(by_id),
        _about_text(by_id),
        render_board(board, df, by_id),
    )


def build_demo() -> gr.Blocks:
    with gr.Blocks(
        title="PRIMO Benchmark",
        theme=THEME,
        head=PAGE_HEAD,
        css_paths=[CSS_PATH],
        js=TABLE_SORT_JS,
        fill_width=True,
    ) as demo:
        active_board = gr.State(None)
        with gr.Row(elem_id="pm-shell"):
            with gr.Column(elem_id="pm-rail"):
                rail = gr.HTML()
            with gr.Column(elem_id="pm-main"):
                with gr.Tabs(elem_id="pm-pages") as pages:
                    with gr.Tab("Boards", id="boards"):
                        boards_html = gr.HTML()
                    with gr.Tab("Board", id="board"):
                        board_html = gr.HTML()
                    with gr.Tab("Tasks", id="tasks"):
                        tasks_html = gr.HTML()
                    with gr.Tab("Submit", id="submit"):
                        gr.HTML(SUBMIT_HEAD)
                        with gr.Column(elem_classes=["pm-body"]):
                            with gr.Row():
                                with gr.Column(scale=3):
                                    gr.Markdown(_page_text("submit"))
                                with gr.Column(scale=2, elem_id="pm-form"):
                                    gr.LoginButton()
                                    modality_in = gr.Radio(
                                        MODALITY_CHOICES,
                                        label="Modality",
                                        info="One model submission covers one modality.",
                                    )
                                    download_md = gr.Markdown(_download_help(None))
                                    model_tb = gr.Textbox(
                                        label="Model name",
                                        placeholder="e.g. eva-rna-v1",
                                        info="Shown on the leaderboard.",
                                    )
                                    institution_tb = gr.Textbox(
                                        label="Institution (optional)",
                                        placeholder="e.g. Scienta",
                                        info="Shown on the leaderboard.",
                                    )
                                    author_submission_cb = gr.Checkbox(
                                        label="Submitted by the model's authors",
                                        info="Adds an Authors check next to the model name.",
                                    )
                                    email_tb = gr.Textbox(
                                        label="Email address",
                                        placeholder="you@lab.org",
                                        info="Contact for this submission, kept private.",
                                    )
                                    notes_tb = gr.Textbox(
                                        label="Training data / notes (optional)",
                                        placeholder="e.g. pretrained on atlas X",
                                        info="About the model or its training data.",
                                    )
                                    paper_tb = gr.Textbox(
                                        label="Paper link (optional)",
                                        placeholder="https://arxiv.org/abs/...",
                                        info="Links the model name on the leaderboard.",
                                    )
                                    hf_tb = gr.Textbox(
                                        label="Hugging Face model link (optional)",
                                        placeholder="https://huggingface.co/...",
                                    )
                                    file_in = gr.File(
                                        label="Submission (.csv / .tsv / .parquet / .npz)",
                                        type="filepath",
                                    )
                                    run_btn = gr.Button(
                                        "Evaluate",
                                        elem_id="pm-evaluate",
                                        elem_classes=[
                                            "pm-btn",
                                            "pm-btn--primary",
                                            "pm-btn--block",
                                        ],
                                    )
                                    status_html = gr.HTML(
                                        evaluation_status(), visible=False
                                    )
                                    gr.HTML(evaluation_confirmation())
                            result_md = gr.Markdown()
                    with gr.Tab("Contribute", id="contribute"):
                        with gr.Column(elem_classes=["pm-body", "pm-prose"]):
                            gr.Markdown(_page_text("contribute"))
                    with gr.Tab("Method", id="method"):
                        with gr.Column(elem_classes=["pm-body", "pm-prose"]):
                            about_md = gr.Markdown()

        evaluation_event = run_btn.click(
            lambda: gr.update(visible=True),
            None,
            status_html,
            show_progress="hidden",
        ).then(
            evaluate,
            [
                file_in,
                modality_in,
                model_tb,
                institution_tb,
                author_submission_cb,
                email_tb,
                paper_tb,
                hf_tb,
                notes_tb,
                active_board,
            ],
            [result_md, board_html],
        )
        evaluation_event.then(
            lambda: gr.update(visible=False),
            None,
            status_html,
            show_progress="hidden",
        )
        modality_in.change(_download_help, modality_in, download_md)
        demo.load(
            _init,
            None,
            [pages, rail, active_board, boards_html, tasks_html, about_md, board_html],
        )
    return demo


if __name__ == "__main__":
    build_demo().launch(
        server_name="0.0.0.0",
        server_port=7860,
        ssr_mode=False,
        allowed_paths=ALLOWED_PATHS,
    )