Spaces:
Running
Running
Commit
·
8fc70f8
1
Parent(s):
fed47e0
json file in results
Browse files- app.py +13 -26
- notes.txt +12 -0
- src/about.py +1 -1
- src/display/utils.py +13 -0
- src/result_samples/speech.json +0 -0
- src/result_samples/text.json +0 -0
- src/submission/submit.py +100 -164
- src/submission_samples/model_name_speech.csv +1 -1
- src/submission_samples/model_name_text.csv +1 -1
app.py
CHANGED
|
@@ -25,46 +25,47 @@ from src.display.utils import (
|
|
| 25 |
ModelType,
|
| 26 |
fields,
|
| 27 |
WeightType,
|
| 28 |
-
Precision
|
| 29 |
)
|
| 30 |
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
|
| 31 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
| 32 |
from src.submission.submit import handle_csv_submission
|
| 33 |
-
from pathlib import Path
|
| 34 |
|
| 35 |
text_sample_path = "src/submission_samples/model_name_text.csv"
|
| 36 |
speech_sample_path = "src/submission_samples/model_name_speech.csv"
|
| 37 |
|
|
|
|
| 38 |
def restart_space():
|
| 39 |
API.restart_space(repo_id=REPO_ID)
|
| 40 |
|
|
|
|
| 41 |
### Space initialisation
|
| 42 |
try:
|
| 43 |
print(EVAL_REQUESTS_PATH)
|
| 44 |
snapshot_download(
|
| 45 |
-
repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30,
|
|
|
|
| 46 |
)
|
| 47 |
except Exception:
|
| 48 |
restart_space()
|
| 49 |
try:
|
| 50 |
print(EVAL_RESULTS_PATH)
|
| 51 |
snapshot_download(
|
| 52 |
-
repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30,
|
|
|
|
| 53 |
)
|
| 54 |
except Exception:
|
| 55 |
restart_space()
|
| 56 |
|
| 57 |
|
| 58 |
-
# LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS, BENCHMARK_COLS)
|
| 59 |
-
|
| 60 |
-
|
| 61 |
(
|
| 62 |
finished_eval_queue_df,
|
| 63 |
running_eval_queue_df,
|
| 64 |
pending_eval_queue_df,
|
| 65 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 66 |
|
| 67 |
-
|
|
|
|
| 68 |
if dataframe is None or dataframe.empty:
|
| 69 |
raise ValueError("Leaderboard DataFrame is empty or None.")
|
| 70 |
column_class = AutoEvalColumn if result_type == "text" else AutoEvalColumnSpeech
|
|
@@ -98,19 +99,6 @@ def init_leaderboard(dataframe,result_type='text'):
|
|
| 98 |
interactive=False,
|
| 99 |
)
|
| 100 |
|
| 101 |
-
REGION_MAP = {
|
| 102 |
-
"All": "All",
|
| 103 |
-
"Africa": "Africa",
|
| 104 |
-
"Americas/Oceania": "Americas_Oceania",
|
| 105 |
-
"Asia (S)": "Asia_S",
|
| 106 |
-
"Asia (SE)": "Asia_SE",
|
| 107 |
-
"Asia (W, C)": "Asia_W_C",
|
| 108 |
-
"Asia (E)": "Asia_E",
|
| 109 |
-
"Europe (W, N, S)": "Europe_W_N_S",
|
| 110 |
-
"Europe (E)": "Europe_E",
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
REGIONS = ["All", "Africa", "Americas_Oceania", "Asia_S", "Asia_SE", "Asia_W_C", "Asia_E", "Europe_W_N_S", "Europe_E"]
|
| 114 |
|
| 115 |
leaderboard_dataframes = {
|
| 116 |
region: get_leaderboard_df(
|
|
@@ -121,7 +109,7 @@ leaderboard_dataframes = {
|
|
| 121 |
region if region != "All" else None,
|
| 122 |
result_type="text"
|
| 123 |
)
|
| 124 |
-
for region in
|
| 125 |
}
|
| 126 |
|
| 127 |
leaderboard_dataframes_speech = {
|
|
@@ -133,7 +121,7 @@ leaderboard_dataframes_speech = {
|
|
| 133 |
region if region != "All" else None,
|
| 134 |
result_type="speech"
|
| 135 |
)
|
| 136 |
-
for region in
|
| 137 |
}
|
| 138 |
# Preload leaderboard blocks
|
| 139 |
js_switch_code = """
|
|
@@ -164,7 +152,6 @@ js_switch_code = """
|
|
| 164 |
}
|
| 165 |
"""
|
| 166 |
|
| 167 |
-
|
| 168 |
demo = gr.Blocks(css=custom_css)
|
| 169 |
with demo:
|
| 170 |
gr.HTML(TITLE)
|
|
@@ -205,7 +192,7 @@ with demo:
|
|
| 205 |
elem_id=f"speech-leaderboard-{region_key}",
|
| 206 |
elem_classes=["visible"] if region_key == "All" else []
|
| 207 |
):
|
| 208 |
-
init_leaderboard(leaderboard_dataframes_speech[region_key],result_type='speech')
|
| 209 |
|
| 210 |
speech_region_dropdown.change(
|
| 211 |
None,
|
|
@@ -267,4 +254,4 @@ with demo:
|
|
| 267 |
scheduler = BackgroundScheduler()
|
| 268 |
scheduler.add_job(restart_space, "interval", seconds=1800)
|
| 269 |
scheduler.start()
|
| 270 |
-
demo.queue(default_concurrency_limit=40).launch()
|
|
|
|
| 25 |
ModelType,
|
| 26 |
fields,
|
| 27 |
WeightType,
|
| 28 |
+
Precision, REGION_MAP
|
| 29 |
)
|
| 30 |
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
|
| 31 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
| 32 |
from src.submission.submit import handle_csv_submission
|
|
|
|
| 33 |
|
| 34 |
text_sample_path = "src/submission_samples/model_name_text.csv"
|
| 35 |
speech_sample_path = "src/submission_samples/model_name_speech.csv"
|
| 36 |
|
| 37 |
+
|
| 38 |
def restart_space():
|
| 39 |
API.restart_space(repo_id=REPO_ID)
|
| 40 |
|
| 41 |
+
|
| 42 |
### Space initialisation
|
| 43 |
try:
|
| 44 |
print(EVAL_REQUESTS_PATH)
|
| 45 |
snapshot_download(
|
| 46 |
+
repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30,
|
| 47 |
+
token=TOKEN
|
| 48 |
)
|
| 49 |
except Exception:
|
| 50 |
restart_space()
|
| 51 |
try:
|
| 52 |
print(EVAL_RESULTS_PATH)
|
| 53 |
snapshot_download(
|
| 54 |
+
repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30,
|
| 55 |
+
token=TOKEN
|
| 56 |
)
|
| 57 |
except Exception:
|
| 58 |
restart_space()
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
| 61 |
(
|
| 62 |
finished_eval_queue_df,
|
| 63 |
running_eval_queue_df,
|
| 64 |
pending_eval_queue_df,
|
| 65 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 66 |
|
| 67 |
+
|
| 68 |
+
def init_leaderboard(dataframe, result_type='text'):
|
| 69 |
if dataframe is None or dataframe.empty:
|
| 70 |
raise ValueError("Leaderboard DataFrame is empty or None.")
|
| 71 |
column_class = AutoEvalColumn if result_type == "text" else AutoEvalColumnSpeech
|
|
|
|
| 99 |
interactive=False,
|
| 100 |
)
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
leaderboard_dataframes = {
|
| 104 |
region: get_leaderboard_df(
|
|
|
|
| 109 |
region if region != "All" else None,
|
| 110 |
result_type="text"
|
| 111 |
)
|
| 112 |
+
for region in REGION_MAP.values()
|
| 113 |
}
|
| 114 |
|
| 115 |
leaderboard_dataframes_speech = {
|
|
|
|
| 121 |
region if region != "All" else None,
|
| 122 |
result_type="speech"
|
| 123 |
)
|
| 124 |
+
for region in REGION_MAP.values()
|
| 125 |
}
|
| 126 |
# Preload leaderboard blocks
|
| 127 |
js_switch_code = """
|
|
|
|
| 152 |
}
|
| 153 |
"""
|
| 154 |
|
|
|
|
| 155 |
demo = gr.Blocks(css=custom_css)
|
| 156 |
with demo:
|
| 157 |
gr.HTML(TITLE)
|
|
|
|
| 192 |
elem_id=f"speech-leaderboard-{region_key}",
|
| 193 |
elem_classes=["visible"] if region_key == "All" else []
|
| 194 |
):
|
| 195 |
+
init_leaderboard(leaderboard_dataframes_speech[region_key], result_type='speech')
|
| 196 |
|
| 197 |
speech_region_dropdown.change(
|
| 198 |
None,
|
|
|
|
| 254 |
scheduler = BackgroundScheduler()
|
| 255 |
scheduler.add_job(restart_space, "interval", seconds=1800)
|
| 256 |
scheduler.start()
|
| 257 |
+
demo.queue(default_concurrency_limit=40).launch()
|
notes.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The submission flow for the project is as follows:
|
| 2 |
+
|
| 3 |
+
When a csv is submitted, we store the csv in the msteb requests dataset in the folder that's appropriate
|
| 4 |
+
based on text or speech results.
|
| 5 |
+
|
| 6 |
+
Then this csv result is in the same flow converted into a json file and uploaded to results dataset.
|
| 7 |
+
|
| 8 |
+
This helps the leaderboard parse those results and display it.
|
| 9 |
+
|
| 10 |
+
There are validation checks for the csv being formatted correctly and that at least one result value is present.
|
| 11 |
+
|
| 12 |
+
|
src/about.py
CHANGED
|
@@ -51,7 +51,7 @@ https://github.com/McGill-NLP/mSTEB
|
|
| 51 |
|
| 52 |
EVALUATION_QUEUE_TEXT = """
|
| 53 |
## Submit your results
|
| 54 |
-
Please
|
| 55 |
|
| 56 |
Kindly format the results in the same way as provided in the sample csv files below.
|
| 57 |
"""
|
|
|
|
| 51 |
|
| 52 |
EVALUATION_QUEUE_TEXT = """
|
| 53 |
## Submit your results
|
| 54 |
+
Please provide the model name, csv file and select the appropriate result type to upload your evaluation results for mSTEB.
|
| 55 |
|
| 56 |
Kindly format the results in the same way as provided in the sample csv files below.
|
| 57 |
"""
|
src/display/utils.py
CHANGED
|
@@ -123,3 +123,16 @@ EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
|
|
| 123 |
|
| 124 |
BENCHMARK_COLS = [t.value.col_name for t in Tasks]
|
| 125 |
SPEECH_BENCHMARK_COLS = [t.value.col_name for t in SpeechTasks]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
BENCHMARK_COLS = [t.value.col_name for t in Tasks]
|
| 125 |
SPEECH_BENCHMARK_COLS = [t.value.col_name for t in SpeechTasks]
|
| 126 |
+
|
| 127 |
+
REGION_MAP = {
|
| 128 |
+
"All": "All",
|
| 129 |
+
"Africa": "Africa",
|
| 130 |
+
"Americas/Oceania": "Americas_Oceania",
|
| 131 |
+
"Asia (S)": "Asia_S",
|
| 132 |
+
"Asia (SE)": "Asia_SE",
|
| 133 |
+
"Asia (W, C)": "Asia_W_C",
|
| 134 |
+
"Asia (E)": "Asia_E",
|
| 135 |
+
"Europe (W, N, S)": "Europe_W_N_S",
|
| 136 |
+
"Europe (E)": "Europe_E",
|
| 137 |
+
}
|
| 138 |
+
|
src/result_samples/speech.json
ADDED
|
File without changes
|
src/result_samples/text.json
ADDED
|
File without changes
|
src/submission/submit.py
CHANGED
|
@@ -3,121 +3,14 @@ import os
|
|
| 3 |
import pandas as pd
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
|
|
|
|
| 6 |
from src.display.formatting import styled_error, styled_message, styled_warning
|
| 7 |
-
from src.
|
| 8 |
-
from src.
|
| 9 |
-
already_submitted_models,
|
| 10 |
-
check_model_card,
|
| 11 |
-
get_model_size,
|
| 12 |
-
is_model_on_hub,
|
| 13 |
-
)
|
| 14 |
|
| 15 |
REQUESTED_MODELS = None
|
| 16 |
USERS_TO_SUBMISSION_DATES = None
|
| 17 |
|
| 18 |
-
# def add_new_eval(
|
| 19 |
-
# model: str,
|
| 20 |
-
# base_model: str,
|
| 21 |
-
# revision: str,
|
| 22 |
-
# precision: str,
|
| 23 |
-
# weight_type: str,
|
| 24 |
-
# model_type: str,
|
| 25 |
-
# ):
|
| 26 |
-
# global REQUESTED_MODELS
|
| 27 |
-
# global USERS_TO_SUBMISSION_DATES
|
| 28 |
-
# if not REQUESTED_MODELS:
|
| 29 |
-
# REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
|
| 30 |
-
#
|
| 31 |
-
# user_name = ""
|
| 32 |
-
# model_path = model
|
| 33 |
-
# if "/" in model:
|
| 34 |
-
# user_name = model.split("/")[0]
|
| 35 |
-
# model_path = model.split("/")[1]
|
| 36 |
-
#
|
| 37 |
-
# precision = precision.split(" ")[0]
|
| 38 |
-
# current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 39 |
-
#
|
| 40 |
-
# if model_type is None or model_type == "":
|
| 41 |
-
# return styled_error("Please select a model type.")
|
| 42 |
-
#
|
| 43 |
-
# # Does the model actually exist?
|
| 44 |
-
# if revision == "":
|
| 45 |
-
# revision = "main"
|
| 46 |
-
#
|
| 47 |
-
# # Is the model on the hub?
|
| 48 |
-
# if weight_type in ["Delta", "Adapter"]:
|
| 49 |
-
# base_model_on_hub, error, _ = is_model_on_hub(model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 50 |
-
# if not base_model_on_hub:
|
| 51 |
-
# return styled_error(f'Base model "{base_model}" {error}')
|
| 52 |
-
#
|
| 53 |
-
# if not weight_type == "Adapter":
|
| 54 |
-
# model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 55 |
-
# if not model_on_hub:
|
| 56 |
-
# return styled_error(f'Model "{model}" {error}')
|
| 57 |
-
#
|
| 58 |
-
# # Is the model info correctly filled?
|
| 59 |
-
# try:
|
| 60 |
-
# model_info = API.model_info(repo_id=model, revision=revision)
|
| 61 |
-
# except Exception:
|
| 62 |
-
# return styled_error("Could not get your model information. Please fill it up properly.")
|
| 63 |
-
#
|
| 64 |
-
# model_size = get_model_size(model_info=model_info, precision=precision)
|
| 65 |
-
#
|
| 66 |
-
# # Were the model card and license filled?
|
| 67 |
-
# try:
|
| 68 |
-
# license = model_info.cardData["license"]
|
| 69 |
-
# except Exception:
|
| 70 |
-
# return styled_error("Please select a license for your model")
|
| 71 |
-
#
|
| 72 |
-
# modelcard_OK, error_msg = check_model_card(model)
|
| 73 |
-
# if not modelcard_OK:
|
| 74 |
-
# return styled_error(error_msg)
|
| 75 |
-
#
|
| 76 |
-
# # Seems good, creating the eval
|
| 77 |
-
# print("Adding new eval")
|
| 78 |
-
#
|
| 79 |
-
# eval_entry = {
|
| 80 |
-
# "model": model,
|
| 81 |
-
# "base_model": base_model,
|
| 82 |
-
# "revision": revision,
|
| 83 |
-
# "precision": precision,
|
| 84 |
-
# "weight_type": weight_type,
|
| 85 |
-
# "status": "PENDING",
|
| 86 |
-
# "submitted_time": current_time,
|
| 87 |
-
# "model_type": model_type,
|
| 88 |
-
# "likes": model_info.likes,
|
| 89 |
-
# "params": model_size,
|
| 90 |
-
# "license": license,
|
| 91 |
-
# "private": False,
|
| 92 |
-
# }
|
| 93 |
-
#
|
| 94 |
-
# # Check for duplicate submission
|
| 95 |
-
# if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
|
| 96 |
-
# return styled_warning("This model has been already submitted.")
|
| 97 |
-
#
|
| 98 |
-
# print("Creating eval file")
|
| 99 |
-
# OUT_DIR = f"{EVAL_REQUESTS_PATH}/{user_name}"
|
| 100 |
-
# os.makedirs(OUT_DIR, exist_ok=True)
|
| 101 |
-
# out_path = f"{OUT_DIR}/{model_path}_eval_request_False_{precision}_{weight_type}.json"
|
| 102 |
-
#
|
| 103 |
-
# with open(out_path, "w") as f:
|
| 104 |
-
# f.write(json.dumps(eval_entry))
|
| 105 |
-
#
|
| 106 |
-
# print("Uploading eval file")
|
| 107 |
-
# API.upload_file(
|
| 108 |
-
# path_or_fileobj=out_path,
|
| 109 |
-
# path_in_repo=out_path.split("eval-queue/")[1],
|
| 110 |
-
# repo_id=QUEUE_REPO,
|
| 111 |
-
# repo_type="dataset",
|
| 112 |
-
# commit_message=f"Add {model} to eval queue",
|
| 113 |
-
# )
|
| 114 |
-
#
|
| 115 |
-
# # Remove the local file
|
| 116 |
-
# os.remove(out_path)
|
| 117 |
-
#
|
| 118 |
-
# return styled_message(
|
| 119 |
-
# "Your request has been submitted to the evaluation queue!\nPlease wait for up to an hour for the model to show in the PENDING list."
|
| 120 |
-
# )
|
| 121 |
|
| 122 |
def handle_csv_submission(
|
| 123 |
model_name: str,
|
|
@@ -129,11 +22,7 @@ def handle_csv_submission(
|
|
| 129 |
if csv_file is None:
|
| 130 |
return styled_error("Please provide a CSV file with results.")
|
| 131 |
|
| 132 |
-
# print("Handling CSV submission...")
|
| 133 |
-
# print(type(csv_file))
|
| 134 |
-
# print(csv_file)
|
| 135 |
df = pd.read_csv(csv_file)
|
| 136 |
-
# print(df)
|
| 137 |
|
| 138 |
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 139 |
|
|
@@ -142,7 +31,7 @@ def handle_csv_submission(
|
|
| 142 |
os.makedirs(subdir, exist_ok=True)
|
| 143 |
|
| 144 |
filename = f"{current_time}_{model_name}_{result_type}_results.csv"
|
| 145 |
-
remote_path = f"{result_type}_requests/{filename}"
|
| 146 |
|
| 147 |
csv_save_path = os.path.join(subdir,filename)
|
| 148 |
df.to_csv(csv_save_path, index=False)
|
|
@@ -156,52 +45,99 @@ def handle_csv_submission(
|
|
| 156 |
commit_message=f"Add {result_type} request for {model_name} at {current_time}",
|
| 157 |
)
|
| 158 |
|
| 159 |
-
#
|
| 160 |
-
|
| 161 |
-
#
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
#
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
#
|
| 197 |
-
#
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
|
| 6 |
+
from src.about import Tasks, SpeechTasks
|
| 7 |
from src.display.formatting import styled_error, styled_message, styled_warning
|
| 8 |
+
from src.display.utils import REGION_MAP
|
| 9 |
+
from src.envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO, RESULTS_REPO, EVAL_RESULTS_PATH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
REQUESTED_MODELS = None
|
| 12 |
USERS_TO_SUBMISSION_DATES = None
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def handle_csv_submission(
|
| 16 |
model_name: str,
|
|
|
|
| 22 |
if csv_file is None:
|
| 23 |
return styled_error("Please provide a CSV file with results.")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
df = pd.read_csv(csv_file)
|
|
|
|
| 26 |
|
| 27 |
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 28 |
|
|
|
|
| 31 |
os.makedirs(subdir, exist_ok=True)
|
| 32 |
|
| 33 |
filename = f"{current_time}_{model_name}_{result_type}_results.csv"
|
| 34 |
+
remote_path = f"msteb_{result_type}_requests/{filename}"
|
| 35 |
|
| 36 |
csv_save_path = os.path.join(subdir,filename)
|
| 37 |
df.to_csv(csv_save_path, index=False)
|
|
|
|
| 45 |
commit_message=f"Add {result_type} request for {model_name} at {current_time}",
|
| 46 |
)
|
| 47 |
|
| 48 |
+
# Remove the local file
|
| 49 |
+
os.remove(csv_save_path)
|
| 50 |
+
# this converts dataframe to json and uploads it to results
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
try:
|
| 54 |
+
convert_csv_to_json_and_upload(df, model_name, result_type)
|
| 55 |
+
except ValueError as e:
|
| 56 |
+
return styled_error(f"{str(e)}")
|
| 57 |
+
return styled_message(f"Results CSV successfully submitted for `{model_name}`!")
|
| 58 |
+
|
| 59 |
+
def find_task_by_col_name(col_name, enum_cls):
|
| 60 |
+
for task in enum_cls:
|
| 61 |
+
if task.value.col_name == col_name:
|
| 62 |
+
return task
|
| 63 |
+
return None
|
| 64 |
+
def convert_csv_to_json_and_upload(df: pd.DataFrame, model_name: str, result_type: str):
|
| 65 |
+
task_enum = Tasks if result_type == "text" else SpeechTasks
|
| 66 |
+
|
| 67 |
+
task_display_names = {t.value.col_name for t in task_enum}
|
| 68 |
+
region_names = df["Region"].tolist()
|
| 69 |
+
average_row = "Average (Micro)"
|
| 70 |
+
|
| 71 |
+
# --- Validation ---
|
| 72 |
+
df_columns = set(df.columns[1:]) # exclude Region column
|
| 73 |
+
if not df_columns.issubset(task_display_names):
|
| 74 |
+
extra = df_columns - task_display_names
|
| 75 |
+
raise ValueError(f"Extra columns in CSV: {extra}")
|
| 76 |
+
if average_row not in df["Region"].values:
|
| 77 |
+
raise ValueError("Missing row for 'Average (Micro)'")
|
| 78 |
+
|
| 79 |
+
data_region_names = [r for r in region_names if r != average_row]
|
| 80 |
+
|
| 81 |
+
for region in data_region_names:
|
| 82 |
+
if region not in REGION_MAP:
|
| 83 |
+
raise ValueError(f"Region '{region}' not found in REGION_MAP keys.")
|
| 84 |
+
|
| 85 |
+
# --- Build JSON ---
|
| 86 |
+
# I go over the regions in the CSV and create a JSON object.
|
| 87 |
+
model_json = {
|
| 88 |
+
"config": {"model_name": model_name},
|
| 89 |
+
"results": {},
|
| 90 |
+
"regions": {},
|
| 91 |
+
}
|
| 92 |
+
at_least_one_number = False
|
| 93 |
+
|
| 94 |
+
for _, row in df.iterrows():
|
| 95 |
+
region_display = row["Region"]
|
| 96 |
+
|
| 97 |
+
if region_display == average_row:
|
| 98 |
+
for col, val in row.items():
|
| 99 |
+
if col == "Region":
|
| 100 |
+
continue
|
| 101 |
+
task = find_task_by_col_name(col, task_enum)
|
| 102 |
+
if val is not None and not pd.isna(val) and isinstance(val, (int, float)):
|
| 103 |
+
print(f" value {val}")
|
| 104 |
+
at_least_one_number = True
|
| 105 |
+
model_json["results"][task.value.benchmark] = {task.value.metric: val/100}
|
| 106 |
+
else:
|
| 107 |
+
model_json["regions"][REGION_MAP[region_display]] = {}
|
| 108 |
+
for col, val in row.items():
|
| 109 |
+
if col == "Region":
|
| 110 |
+
continue
|
| 111 |
+
task = find_task_by_col_name(col, task_enum)
|
| 112 |
+
if val is not None and not pd.isna(val) and isinstance(val, (int, float)):
|
| 113 |
+
model_json["regions"][REGION_MAP[region_display]][task.value.benchmark] = {task.value.metric: val/100}
|
| 114 |
+
|
| 115 |
+
# Check if at least one number is present in the results
|
| 116 |
+
print(at_least_one_number)
|
| 117 |
+
if at_least_one_number is False:
|
| 118 |
+
raise ValueError("No valid numeric results found in the CSV. Please check your input.")
|
| 119 |
+
|
| 120 |
+
# --- Save locally ---
|
| 121 |
+
subdir = os.path.join(EVAL_RESULTS_PATH, result_type)
|
| 122 |
+
os.makedirs(subdir, exist_ok=True)
|
| 123 |
+
current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 124 |
+
filename = f"{current_time}_{model_name}_{result_type}.json"
|
| 125 |
+
json_save_path = os.path.join(subdir,filename)
|
| 126 |
+
|
| 127 |
+
with open(json_save_path, "w") as f:
|
| 128 |
+
json.dump(model_json, f, indent=2)
|
| 129 |
+
|
| 130 |
+
# --- Upload to HF Hub ---
|
| 131 |
+
remote_path = f"msteb_leaderboard/msteb_{result_type}_results/{filename}"
|
| 132 |
+
API.upload_file(
|
| 133 |
+
path_or_fileobj=json_save_path,
|
| 134 |
+
path_in_repo=remote_path,
|
| 135 |
+
repo_id=RESULTS_REPO,
|
| 136 |
+
repo_type="dataset",
|
| 137 |
+
commit_message=f"Upload results for {model_name} ({result_type}) at {current_time}",
|
| 138 |
+
)
|
| 139 |
+
os.remove(json_save_path)
|
| 140 |
+
|
| 141 |
+
print(f"Uploaded to {RESULTS_REPO}/{current_time}")
|
| 142 |
+
|
| 143 |
+
return f"Uploaded to {RESULTS_REPO}/{current_time}"
|
src/submission_samples/model_name_speech.csv
CHANGED
|
@@ -3,7 +3,7 @@ Africa,,,,,
|
|
| 3 |
Americas/Oceania,,,,,
|
| 4 |
Asia (S),,,,,
|
| 5 |
Asia (SE),,,,,
|
| 6 |
-
"Asia (W,C)",,,,,
|
| 7 |
Asia (E),,,,,
|
| 8 |
"Europe (W, N, S)",,,,,
|
| 9 |
Europe (E),,,,,
|
|
|
|
| 3 |
Americas/Oceania,,,,,
|
| 4 |
Asia (S),,,,,
|
| 5 |
Asia (SE),,,,,
|
| 6 |
+
"Asia (W, C)",,,,,
|
| 7 |
Asia (E),,,,,
|
| 8 |
"Europe (W, N, S)",,,,,
|
| 9 |
Europe (E),,,,,
|
src/submission_samples/model_name_text.csv
CHANGED
|
@@ -3,7 +3,7 @@ Africa,,,,,,
|
|
| 3 |
Americas/Oceania,,,,,,
|
| 4 |
Asia (S),,,,,,
|
| 5 |
Asia (SE),,,,,,
|
| 6 |
-
"Asia (W,C)",,,,,,
|
| 7 |
Asia (E),,,,,,
|
| 8 |
"Europe (W, N, S)",,,,,,
|
| 9 |
Europe (E),,,,,,
|
|
|
|
| 3 |
Americas/Oceania,,,,,,
|
| 4 |
Asia (S),,,,,,
|
| 5 |
Asia (SE),,,,,,
|
| 6 |
+
"Asia (W, C)",,,,,,
|
| 7 |
Asia (E),,,,,,
|
| 8 |
"Europe (W, N, S)",,,,,,
|
| 9 |
Europe (E),,,,,,
|