import gradio as gr from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns import pandas as pd import logging from apscheduler.schedulers.background import BackgroundScheduler from src.envs import API, REPO_ID, TOKEN from utils import get_data, submit, refresh def restart_space(): refresh() API.restart_space(repo_id=REPO_ID) dimensions = ['Audience', 'Keyword', 'Format', 'Language', 'Length', 'Source'] display_columns = [ "Rank", "Model", "WISE", "SICR", "nDCG@10(Original)", "nDCG@10(Instructed)", "nDCG@10(Reversely Instructed)", "MRR@1(Original)", "MRR@1(Instructed)", "MRR@1(Reversely Instructed)" ] data_type = ["number", "markdown", "number", "number", "number", "number", "number", "number", "number", "number"] css = """ table > thead { white-space: normal } table { --cell-width-1: 250px } table > tbody > tr > td:nth-child(2) > div { overflow-x: auto } .filter-checkbox-group { max-width: max-content; } .fixed-height-table { height: 100px; overflow-y: scroll; } """ # create Gradio interface with gr.Blocks() as demo: gr.Markdown("# 🤗 InfoSearch Benchmark Leaderboard") with gr.Tabs() as tabs: with gr.TabItem("🏅 InfoSearch Benchmark"): for dimension in dimensions: with gr.Tab(dimension): data = get_data(f"{dimension}") gr.Dataframe(data, headers=display_columns, datatype=data_type, interactive=False, elem_classes=["fixed-height-table"]) with gr.TabItem("🚀 Submit here!"): gr.Markdown("✉️✨ Submit your model here.") file_upload = gr.File(label="Upload your JSON file") submit_button = gr.Button("Submit") submission_result = gr.Markdown() submit_button.click(submit, file_upload, submission_result) logging.basicConfig() logging.getLogger('apscheduler').setLevel(logging.DEBUG) scheduler = BackgroundScheduler() scheduler.add_job(restart_space, "interval", seconds=3600) scheduler.start() demo.queue(default_concurrency_limit=40).launch()