Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 5,799 Bytes
db7f350 |
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
import os
from email.utils import parseaddr
import gradio as gr
import pandas as pd
from datasets import load_dataset
from apscheduler.schedulers.background import BackgroundScheduler
from huggingface_hub import HfApi
# InfoStrings
from content import *
BALM_TOKEN = os.environ.get("BALM_TOKEN", None)
owner="clefourrier" # change to balm once possible
api = HfApi()
eval_results = {}
eval_dataframe = {}
for level in range(1, 4):
eval_results[level] = load_dataset(f"{owner}/BALM_ResultsDev{level}", token=BALM_TOKEN, split="dev")
eval_dataframe[level] = pd.DataFrame(eval_results[level].remove_column("mail"))
def restart_space():
api.restart_space(repo_id=f"{owner}/BALM_Leaderboard", token=BALM_TOKEN)
COLS = ["Model", "Organisation", "Reported accuracy ⬆️"]
TYPES = ["str", "str", "number",]
def add_new_eval(
level_of_dev: str,
model: str,
score: float,
organisation: str,
mail: str,
):
level = int(level_of_dev.split(" ")[-1])
# Very basic email parsing
_, parsed_mail = parseaddr(mail)
if not "@" in parsed_mail:
valid_mail = "Please provide a valid email adress."
return f"<p style='color: orange; font-size: 20px; text-align: center;'>{valid_mail}</p>"
print("Adding new eval")
# Check if the combination model/org already exists and prints a warning message if yes
if model.lower() in set(eval_results[level]["model"]) and organisation.lower() in set(eval_results[level]["organisation"]):
duplicate_request_message = "This model has been already submitted."
return f"<p style='color: orange; font-size: 20px; text-align: center;'>{duplicate_request_message}</p>"
# Actual submission
eval_entry = {
"model": model,
"score": score,
"organisation": organisation,
"mail": mail,
}
eval_results[level].add_item(eval_entry)
success_message = f"Model {model} submitted by {organisation}."
return f"<p style='color: green; font-size: 20px; text-align: center;'>{success_message}</p>"
def refresh():
eval_results = {}
eval_dataframe = {}
for level in range(1, 4):
eval_results[level] = load_dataset(f"{owner}/BALM_ResultsDev{level}", token=BALM_TOKEN, split="dev")
eval_dataframe[level] = pd.DataFrame(eval_results[level].remove_column("mail"))
return eval_dataframe[1], eval_dataframe[2], eval_dataframe[3]
custom_css = """
#changelog-text {
font-size: 16px !important;
}
#changelog-text h2 {
font-size: 18px !important;
}
.markdown-text {
font-size: 16px !important;
}
#citation-button span {
font-size: 16px !important;
}
#citation-button textarea {
font-size: 16px !important;
}
#citation-button > label > button {
margin: 6px;
transform: scale(1.3);
}
"""
demo = gr.Blocks(css=custom_css)
with demo:
gr.HTML(TITLE)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Row():
with gr.Column():
with gr.Accordion("📙 Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
elem_id="citation-button",
).style(show_copy_button=True)
with gr.Column():
with gr.Accordion("✨ CHANGELOG", open=False):
changelog = gr.Markdown(CHANGELOG_TEXT, elem_id="changelog-text")
with gr.Tab("Results: Level 1"):
with gr.Tab("Results on Dev Set"):
leaderboard_table_1 = gr.components.Dataframe(
value=eval_dataframe[1], headers=COLS, datatype=TYPES, max_rows=20
)
with gr.Tab("Results on Test Set"):
gr.Textbox(value="The test set is currently private! Come back when performances on the dev set increased!")
with gr.Tab("Results: Level 2"):
with gr.Tab("Results on Dev Set"):
leaderboard_table_2 = gr.components.Dataframe(
value=eval_dataframe[2], headers=COLS, datatype=TYPES, max_rows=20
)
with gr.Tab("Results on Test Set"):
gr.Textbox(value="The test set is currently private! Come back when performances on the dev set increased!")
with gr.Tab("Results: Level 3"):
with gr.Tab("Results on Dev Set"):
leaderboard_table_3 = gr.components.Dataframe(
value=eval_dataframe[3], headers=COLS, datatype=TYPES, max_rows=20
)
with gr.Tab("Results on Test Set"):
gr.Textbox(value="The test set is currently private! Come back when performances on the dev set increased!")
refresh_button = gr.Button("Refresh")
refresh_button.click(
refresh,
inputs=[],
outputs=[
eval_dataframe[1],
eval_dataframe[2],
eval_dataframe[3],
],
)
with gr.Accordion("Submit a new model for evaluation"):
#with gr.Row():
with gr.Column():
level_of_dev = gr.Radio(["Level 1", "Level 2", "Level 3"], value="Level 1", label="Dev set")
model_name_textbox = gr.Textbox(label="Model name")
score = gr.Textbox(label="Score")
organisation = gr.Textbox(label="Organisation")
mail = gr.Textbox(label="Contact email")
submit_button = gr.Button("Submit Eval")
submission_result = gr.Markdown()
submit_button.click(
add_new_eval,
[
level_of_dev,
model_name_textbox,
score,
organisation,
mail
],
submission_result,
)
scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=3600)
scheduler.start()
demo.launch()
|