Spaces:
Sleeping
Sleeping
import gradio as gr | |
from apscheduler.schedulers.background import BackgroundScheduler | |
from src.static.env import API, REPO_ID, HF_TOKEN | |
from src.static.about import TITLE, INTRO, ABOUT, DOCUMENTATION | |
from src.leaderboards.get_from_hub import get_leaderboard_info | |
from src.static.tag_info import * | |
from src.static.display import make_clickable | |
def restart_space(): | |
API.restart_space(repo_id=REPO_ID, token=HF_TOKEN) | |
LEADERBOARDS_TO_INFO, INFO_TO_LEADERBOARDS = get_leaderboard_info() | |
def update_leaderboards(show_all, modality_tags, submission_tags, test_set_tags, evaluation_tags, language_tags): | |
spaces_of_interest = [] | |
if show_all: | |
spaces_of_interest = INFO_TO_LEADERBOARDS["all"] | |
else: | |
for tag in modality_tags: | |
spaces_of_interest.extend(INFO_TO_LEADERBOARDS["modality"][tag.lower()]) | |
for tag in submission_tags: | |
spaces_of_interest.extend(INFO_TO_LEADERBOARDS["submission"][tag.lower()]) | |
for tag in test_set_tags: | |
spaces_of_interest.extend(INFO_TO_LEADERBOARDS["test"][tag.lower()]) | |
for tag in evaluation_tags: | |
spaces_of_interest.extend(INFO_TO_LEADERBOARDS["modality"][tag.lower()]) | |
for tag in language_tags: | |
spaces_of_interest.extend(INFO_TO_LEADERBOARDS["language"][tag.lower()]) | |
return "- " + "\n - ".join([ | |
make_clickable(space) + | |
f"*Tags: {', '.join(LEADERBOARDS_TO_INFO[space]) if len(LEADERBOARDS_TO_INFO[space]) > 0 else 'None. Please fill the tags!'}*" | |
for space in spaces_of_interest | |
]) | |
demo = gr.Blocks() | |
with demo: | |
gr.Markdown(TITLE) | |
gr.Markdown(INTRO, elem_classes="markdown-text") | |
with gr.Tabs(elem_classes="tab-buttons") as tabs: | |
with gr.TabItem("Search"): | |
gr.Markdown("Let's look for leaderboards relevant for you! Select the categories of your choice") | |
with gr.Row(): | |
with gr.Column(): | |
show_all = gr.Checkbox( | |
value=False, | |
label="Show all leaderboards" | |
) | |
modality_tags = gr.CheckboxGroup( | |
choices=[tag.name for tag in Modality], | |
value=[], | |
label="Modality of choice" | |
) | |
submission_tags = gr.CheckboxGroup( | |
choices=[tag.name for tag in SubmissionType], | |
value=[], | |
label="Submission type" | |
) | |
test_set_tags = gr.CheckboxGroup( | |
choices=[tag.name for tag in TestSetStatus], | |
value=[], | |
label="Test set status" | |
) | |
with gr.Column(): | |
evaluation_tags = gr.CheckboxGroup( | |
choices=[tag.name for tag in EvaluationCategory], | |
value=[], | |
label="Specific evaluation categories" | |
) | |
language_tags = gr.CheckboxGroup( | |
choices=[tag.capitalize() for tag in sorted(list(INFO_TO_LEADERBOARDS["language"].keys()))], | |
value=[], | |
label="Specific languages" | |
) | |
with gr.Row(): | |
leaderboards = gr.Markdown( | |
value="", | |
) | |
for selector in [modality_tags, submission_tags, test_set_tags, evaluation_tags, language_tags]: | |
selector.change( | |
lambda _: False, | |
outputs=show_all | |
) | |
for selector in [show_all, modality_tags, submission_tags, test_set_tags, evaluation_tags, language_tags]: | |
selector.change( | |
update_leaderboards, | |
[show_all, modality_tags, submission_tags, test_set_tags, evaluation_tags, language_tags], | |
leaderboards, | |
queue=True, | |
) | |
with gr.TabItem("About"): | |
gr.Markdown(ABOUT, elem_classes="markdown-text") | |
with gr.TabItem("Documentation"): | |
gr.Markdown(DOCUMENTATION, elem_classes="markdown-text") | |
scheduler = BackgroundScheduler() | |
scheduler.add_job(restart_space, "interval", seconds=10800) # restarted every 3h | |
scheduler.start() | |
demo.queue(default_concurrency_limit=40).launch() |