File size: 2,825 Bytes
17ae829
 
1538407
17ae829
1538407
 
5c6e7ab
1538407
 
 
 
 
 
 
17ae829
 
 
1538407
17ae829
 
1538407
17ae829
 
1538407
 
 
17ae829
 
 
1538407
 
 
b826bd5
1538407
 
 
 
 
 
 
 
 
 
 
 
 
 
5c6e7ab
 
 
1538407
 
 
 
 
0611e44
 
 
1538407
 
17ae829
 
1538407
 
 
b826bd5
1538407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17ae829
1538407
17ae829
1538407
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
import gradio as gr
import pandas as pd
import os
from apscheduler.schedulers.background import BackgroundScheduler
from huggingface_hub import HfApi
from uploads import add_new_eval
from utils import LEADERBOARD_PATH, CORPORA, load_data, DEFAULT_COLUMNS, DEFAULT_COLUMN_LABELS


CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results."


api = HfApi()
TOKEN = os.environ.get("TOKEN", None)


def restart_space():
    api.restart_space(repo_id=LEADERBOARD_PATH, token=TOKEN)


demo = gr.Blocks()


with demo:
    with open("asset/p1.md", 'r') as f:
        gr.Markdown(f.read())

    with gr.Row():
        with gr.Accordion("πŸ“™ Citation", open=False):
            with open("asset/citation_button_text.txt", 'r') as f:
                citation_button = gr.Textbox(
                    value=f.read(),
                    label="Copy the following snippet to cite these results:",
                    elem_id="citation-button",
                    show_copy_button=True,
                )

    with gr.Tabs():
        with gr.TabItem("Leaderboard"):
            with gr.Row():
                corpus_dropdown = gr.Dropdown(
                    choices=CORPORA,
                    label="πŸ”„ Select corpus",
                    value=CORPORA[0],
                )

            leaderboard_table = gr.components.Dataframe(
                value=load_data(CORPORA[0]).rename(columns={
                    k: v for k, v in zip(DEFAULT_COLUMNS, DEFAULT_COLUMN_LABELS)
                }),
                interactive=True,
                visible=True,
            )

            corpus_dropdown.change(
                load_data.rename(columns={
                    k: v for k, v in zip(DEFAULT_COLUMNS, DEFAULT_COLUMN_LABELS)
                }),
                inputs=[corpus_dropdown],
                outputs=leaderboard_table
            )

    with gr.Accordion("Submit a new model for evaluation"):
        with gr.Row():
            with gr.Column():
                corpus_radio = gr.Radio(['news', 'books'], value="llama", label="Corpus")
                organization_textbox = gr.Textbox(label="Organization")
                mail_textbox = gr.Textbox(label="Contact email")
            with gr.Column():
                file_output = gr.File()

        submit_button = gr.Button("Submit Eval")
        submission_result = gr.Markdown()
        submit_button.click(
            add_new_eval,
            [
                corpus_radio,
                organization_textbox,
                mail_textbox,
                file_output
            ],
            submission_result,
        )

    with open(f"asset/p2.md", 'r') as f:
        gr.Markdown(f.read())

scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=3600)
scheduler.start()
demo.launch(debug=True)