iwonachristop's picture
Update citations
f715ec8
import gradio as gr
from apscheduler.schedulers.background import BackgroundScheduler
from src.css_html_js import custom_css
from src.envs import API, REPO_ID
from src.process_leaderboard_data import Leaderboard
CITATION_TEXT = open(f"pages/citation.bib", "r").read()
def restart_space():
API.restart_space(repo_id=REPO_ID)
app = gr.Blocks(css=custom_css)
with app:
# Init class Leaderboard
leaderboard = Leaderboard()
# Custom CSS styling for tab-item components
app.css = """
.tab-item {
font-size: 10px;
padding: 10px 20px;
}
"""
# Title and Description of the Leaderboard
gr.HTML(open("pages/description.html", "r").read())
# LEADERBOARD
with gr.Tabs(elem_classes="tab-buttons") as tabs:
with gr.TabItem("πŸ… Leaderboard", elem_id="Leaderboard", id=0, elem_classes="tab-item"):
# OVERALL
with gr.TabItem("Overall", elem_id="Overall", id=1, elem_classes="tab-item"):
gr.Markdown(open("pages/overall.md", "r").read())
# Create and display leaderboard table
leaderboard_dataframe = leaderboard.create_leaderboard_data('All', 'wavlm', 'emotion')
leaderboard_table = gr.DataFrame(leaderboard_dataframe,
datatype= ["markdown" if col == "Model" else "str" for col in leaderboard_dataframe.columns],
interactive=False,
)
# EMOTIONS
with gr.TabItem("Emotions", elem_id="Emotions", id=2, elem_classes="tab-item"):
gr.Markdown(open("pages/emotions.md", "r").read())
# UI for selecting dataset and emotion options
with gr.Row():
with gr.Column():
dataset = gr.Radio(
choices = leaderboard.get_emotional_dataset_list(),
value = None,
label = "Dataset",
)
with gr.Column(min_width=750):
emotion = gr.Radio(
choices = leaderboard.get_emotion_list(),
value = "Anger",
label = "Emotion",
)
# Create and display leaderboard table
leaderboard_dataframe = leaderboard.create_leaderboard_data(emotion.value, 'wavlm', 'emotion')
leaderboard_table = gr.DataFrame(leaderboard_dataframe,
datatype= ["markdown" if col == "Model" else "str" for col in leaderboard_dataframe.columns],
interactive=False,
)
# Update leaderboard table based on user selection changes in emotion or dataset options.
dataset.change(leaderboard.update_leaderboard_data_in_emotion_section,
[dataset, gr.State('dataset'), leaderboard_table],
[emotion, leaderboard_table]
)
emotion.change(leaderboard.update_leaderboard_data_in_emotion_section,
[emotion, gr.State('emotion'), leaderboard_table],
[dataset, leaderboard_table]
)
# FEATURES
with gr.TabItem("Features", elem_id="Features", id=3, elem_classes="tab-item"):
gr.Markdown(open("pages/features.md", "r").read())
# UI for selecting dataset, emotion, and feature options
with gr.Row():
with gr.Column():
dataset = gr.Radio(
choices = leaderboard.get_emotional_dataset_list(),
value = None,
elem_id = "dataset_features",
label = "Dataset",
)
with gr.Column(min_width=750):
emotion = gr.Radio(
choices = leaderboard.get_emotion_list(),
value = "All",
elem_id = "emotion_features",
label = "Emotion",
)
with gr.Row():
hidden_columns = ['model', 'dataset', 'emotion', 'wavlm', "Unnamed: 0"]
feature = gr.Radio(
choices = [kol for kol in list(leaderboard.get_models_performance_dataframe_column()) if kol not in hidden_columns],
value = "pitch",
label = "Feature",
)
# Create and display leaderboard table
leaderboard_dataframe = leaderboard.create_leaderboard_data(emotion.value, feature.value, 'emotion')
leaderboard_table = gr.DataFrame(leaderboard_dataframe,
datatype= ["markdown" if col == "Model" else "str" for col in leaderboard_dataframe.columns],
interactive=False,
)
# Update leaderboard table based on user selection changes in emotion, dataset, or feature options.
emotion.change(leaderboard.update_leaderboard_data_in_feature_section,
[emotion, feature, gr.State('emotion'), leaderboard_table],
[dataset, leaderboard_table]
)
dataset.change(leaderboard.update_leaderboard_data_in_feature_section,
[dataset, feature, gr.State('dataset'), leaderboard_table],
[emotion, leaderboard_table]
)
feature.change(leaderboard.update_leaderboard_data_by_feature,
[emotion, dataset, feature],
[leaderboard_table]
)
# ABOUT
with gr.TabItem("πŸ“ About", elem_id="About", id=4):
gr.Markdown(open("pages/about.md", "r").read())
# SUBMIT HERE
with gr.TabItem("πŸš€ Submit here! ", elem_id="Submit", id=5):
gr.Markdown(open("pages/submit.md", "r").read())
with gr.Column():
with gr.Accordion("πŸ“™ Citation", open=False):
citation_button = gr.Textbox(
label="",
value=CITATION_TEXT,
lines=66,
elem_id="citation-button",
show_copy_button=True,
)
scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=1800)
scheduler.start()
app.queue(default_concurrency_limit=40).launch()