File size: 2,734 Bytes
c7a8a09
881357e
60c1c5f
c7a8a09
30b8f34
c7a8a09
6d68931
96c29e4
881357e
 
30b8f34
6d68931
30b8f34
 
881357e
 
c7a8a09
 
881357e
 
c7a8a09
 
881357e
60c1c5f
30b8f34
60c1c5f
ab4ccfc
30b8f34
 
ab4ccfc
 
60c1c5f
 
c7a8a09
ab4ccfc
30b8f34
 
ab4ccfc
 
60c1c5f
 
efa5772
 
ab4ccfc
60c1c5f
 
 
 
 
30b8f34
60c1c5f
c7a8a09
30b8f34
 
c7a8a09
60c1c5f
 
c7a8a09
efa5772
 
 
 
 
 
60c1c5f
 
 
 
ab4ccfc
30b8f34
ab4ccfc
60c1c5f
ab4ccfc
ea9bdf0
ab4ccfc
30b8f34
ab4ccfc
ea9bdf0
ab4ccfc
 
60c1c5f
ab4ccfc
c7a8a09
30b8f34
 
 
60c1c5f
 
c7a8a09
30b8f34
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
import gradio as gr

from src.about import Tasks
from src.display.formatting import styled_error, styled_message
from src.display.i18n import t
from src.leaderboard.store import save_submission
from src.leaderboard.sync import sync_results_from_hub
from src.populate import get_all_leaderboard_outputs, get_empty_leaderboard_notice_update


def _submission_outputs():
    sync_results_from_hub()
    outputs = get_all_leaderboard_outputs()
    return (*outputs, get_empty_leaderboard_notice_update(outputs[0]))


def _keep_form():
    return gr.skip(), gr.skip(), gr.skip()


def _reset_form():
    return "", "", None


def add_zip_submission(submission_zip, model: str, team: str):
    if submission_zip is None:
        return (
            styled_error(t("submit_error_no_zip")),
            *_submission_outputs(),
            *_keep_form(),
        )

    zip_path = submission_zip if isinstance(submission_zip, str) else submission_zip.name
    if not zip_path:
        return (
            styled_error(t("submit_error_read_zip")),
            *_submission_outputs(),
            *_keep_form(),
        )

    try:
        from src.submission.process_zip import process_submission_zip

        payload, _parsed_results, missing_files, missing_benchmarks = process_submission_zip(
            zip_path=zip_path,
            model_name=model,
            team=team,
        )
    except ValueError as exc:
        return (styled_error(str(exc)), *_submission_outputs(), *_keep_form())
    except Exception:
        return (
            styled_error(t("submit_error_process")),
            *_submission_outputs(),
            *_keep_form(),
        )

    resolved_model = payload["model"]
    _saved_payload, upload_error = save_submission(
        resolved_model,
        team,
        payload["results"],
        zip_path=zip_path,
    )

    warning = ""
    if missing_files:
        warning = (
            "<br><br><span style='color: orange;'>"
            + t("warn_missing_files").format(items=", ".join(missing_files))
            + "</span>"
        )
    if missing_benchmarks:
        warning += (
            "<br><br><span style='color: orange;'>"
            + t("warn_missing_benchmarks").format(items=", ".join(missing_benchmarks))
            + "</span>"
        )
    if upload_error:
        warning += f"<br><br><span style='color: orange;'>Warning: {upload_error}</span>"

    benchmarks = ", ".join(task.value.col_name for task in Tasks)
    message = styled_message(
        f"{t('submit_success')}"
        f"<br>{t('submit_model')}: <b>{resolved_model}</b>"
        f"<br>{t('submit_benchmarks')}: {benchmarks}"
        f"{warning}"
    )

    return (message, *_submission_outputs(), *_reset_form())