CoolFace
Apppublic

poojagoyal3072/DABstep

sourceHugging Facecc-by-4.0updated 1y agoView on Hugging Face
0likes
app.py136 linesDownload Raw Back to root
1import os2import gradio as gr3 4from apscheduler.schedulers.background import BackgroundScheduler5from dabstep_benchmark.content import TITLE, INTRODUCTION_TEXT, SUBMISSION_TEXT, CITATION_BUTTON_TEXT, CITATION_BUTTON_LABEL, VALIDATION_GUIDELINES6from dabstep_benchmark.leaderboard import *7 8 9def restart_space():10    HF_API.restart_space(repo_id=HF_LEADERBOARD)11    12 13def download_leaderboard(type):14    verified_lb, unverified_lb = generate_leaderboard_df()15    if type == "verified":16        df_to_download = verified_lb17    if type == "unverified":18        df_to_download = unverified_lb19 20    path = f"data/{type}_leaderboard.csv"21    if os.path.exists(path):22        os.remove(path)23    df_to_download.to_csv(path, index=False)24    return path25 26 27if __name__ == "__main__":28    os.makedirs("data/task_scores", exist_ok=True)29    refresh(only_leaderboard=False)30 31    demo = gr.Blocks()32    with demo:33        gr.Markdown(TITLE)34        gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")35        36        # Generate initial leaderboard data37        validated_lb, unvalidated_lb = generate_leaderboard_df()38 39        with gr.Tab("Validated"):40            verified_table = gr.Dataframe(41                value=validated_lb,42                datatype=["markdown", "str", "str", "str", "markdown", "str", "str", "str"],43                interactive=False,44                column_widths=["20%"],45                wrap=True,46            )47            verified_download = gr.DownloadButton(48                label="Download Leaderboard",49                elem_id="download-verified-lb",50            )51        52        with gr.Tab("Unvalidated"):53            unverified_table = gr.Dataframe(54                value=unvalidated_lb,55                datatype=["markdown", "str", "str", "str", "markdown", "str", "str", "str"],56                interactive=False,57                column_widths=["20%"],58                wrap=True,59            )60            unverified_download = gr.DownloadButton(61                label="Download Leaderboard",62                elem_id="download-unverified-lb",63            )64        # create a Gradio event listener that runs when the page is loaded to populate the dataframe65        demo.load(generate_leaderboard_df, inputs=None, outputs=[verified_table, unverified_table])66 67        verified_download.click(68            download_leaderboard,69            inputs=[gr.Textbox(value="verified", visible=False)],70            outputs=[verified_download]71        )72        unverified_download.click(73            download_leaderboard,74            inputs=[gr.Textbox(value="unverified", visible=False)],75            outputs=[unverified_download]76        )77 78        refresh_button = gr.Button("Refresh")79        refresh_button.click(80            refresh,81            inputs=[82                gr.Checkbox(value=True, visible=False)83            ],84            outputs=[85                verified_table, unverified_table86            ],87        )88        gr.Markdown(VALIDATION_GUIDELINES, elem_classes="markdown-text")89                    90        with gr.Row():91            with gr.Accordion("๐Ÿ“™ Citation", open=False):92                citation_button = gr.Textbox(93                    value=CITATION_BUTTON_TEXT,94                    label=CITATION_BUTTON_LABEL,95                    lines=len(CITATION_BUTTON_TEXT.split("\n")),96                    elem_id="citation-button",97                )  # .style(show_copy_button=True)98 99        with gr.Accordion("Submit new agent answers for evaluation"):100            with gr.Row():101                gr.Markdown(SUBMISSION_TEXT, elem_classes="markdown-text")102            with gr.Row():103                with gr.Column():104                    split = gr.Radio(["all"], value="all", label="Split", visible=False)105                    agent_name_textbox = gr.Textbox(label="Agent name")106                    model_family_textbox = gr.Textbox(label="Model family")107                    system_prompt_textbox = gr.Textbox(label="System prompt example")108                    repo_url_textbox = gr.Textbox(label="Repo URL with agent code")109                with gr.Column():110                    organisation = gr.Textbox(label="Organisation")111                    mail = gr.Textbox(112                        label="Contact email (will be stored privately, & used if there is an issue with your submission)")113                    file_output = gr.File()114 115            with gr.Row():116                gr.LoginButton()117                submit_button = gr.Button("Submit answers")118            submission_result = gr.Markdown()119            submit_button.click(120                process_submission,121                [122                    split,123                    agent_name_textbox,124                    model_family_textbox,125                    repo_url_textbox,126                    file_output,127                    organisation,128                    mail129                ],130                submission_result,131            )132 133    scheduler = BackgroundScheduler()134    scheduler.add_job(restart_space, "interval", seconds=3600*24)135    scheduler.start()136    demo.launch(debug=True)