Spaces:
Running
Running
clean code
Browse files- app.py +13 -22
- init.py +0 -95
- utils_display.py +0 -43
app.py
CHANGED
@@ -1,20 +1,11 @@
|
|
1 |
-
"""A gradio app that renders a static leaderboard. This is used for Hugging Face Space."""
|
2 |
-
import
|
3 |
-
import argparse
|
4 |
-
import glob
|
5 |
-
import pickle
|
6 |
-
|
7 |
import gradio as gr
|
8 |
import numpy as np
|
9 |
import pandas as pd
|
10 |
import gradio as gr
|
11 |
-
import pandas as pd
|
12 |
-
from
|
13 |
-
import json
|
14 |
-
from constants import BANNER, INTRODUCTION_TEXT, CITATION_TEXT, METRICS_TAB_TEXT, DIR_OUTPUT_REQUESTS
|
15 |
-
from init import is_model_on_hub, upload_file, load_all_info_from_dataset_hub
|
16 |
-
from utils_display import AutoEvalColumn, fields, make_clickable_model, styled_error, styled_message
|
17 |
-
from datetime import datetime, timezone
|
18 |
|
19 |
LAST_UPDATED = "Feb 27th 2024"
|
20 |
|
@@ -54,15 +45,14 @@ model_info = {
|
|
54 |
}
|
55 |
|
56 |
|
57 |
-
# Formats the columns
|
58 |
-
def formatter(x):
|
59 |
-
if type(x) is str:
|
60 |
-
x = x
|
61 |
-
else:
|
62 |
-
x = round(x, 2)
|
63 |
-
return x
|
64 |
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
def build_demo(original_df, TYPES):
|
68 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
@@ -116,7 +106,8 @@ if __name__ == "__main__":
|
|
116 |
if col == "model":
|
117 |
original_df[col] = original_df[col].apply(lambda x: x.replace(x, make_clickable_model(x, model_info)))
|
118 |
else:
|
119 |
-
|
|
|
120 |
|
121 |
# Define the first column explicitly, add 'Overall' as the second column, and then append the rest excluding 'Overall'
|
122 |
new_order = [original_df.columns[0], 'Overall'] + [col for col in original_df.columns if col not in [original_df.columns[0], 'Overall']]
|
|
|
1 |
+
"""A gradio app that renders a static leaderboard. This is used for Hugging Face Space."""
|
2 |
+
import argparse
|
|
|
|
|
|
|
|
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
import gradio as gr
|
7 |
+
import pandas as pd
|
8 |
+
from constants import BANNER, INTRODUCTION_TEXT, CITATION_TEXT, METRICS_TAB_TEXT, DIR_OUTPUT_REQUESTS
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
LAST_UPDATED = "Feb 27th 2024"
|
11 |
|
|
|
45 |
}
|
46 |
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
def make_clickable_model(model_name, model_info):
|
50 |
+
if model_info[model_name]['hf_name'].startswith("http"):
|
51 |
+
link = model_info[model_name]['hf_name']
|
52 |
+
else:
|
53 |
+
link = f"https://huggingface.co/{model_info[model_name]['hf_name']}"
|
54 |
+
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_info[model_name]["pretty_name"]}</a>'
|
55 |
+
|
56 |
|
57 |
def build_demo(original_df, TYPES):
|
58 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
|
106 |
if col == "model":
|
107 |
original_df[col] = original_df[col].apply(lambda x: x.replace(x, make_clickable_model(x, model_info)))
|
108 |
else:
|
109 |
+
pass
|
110 |
+
# original_df[col] = original_df[col].apply(formatter) # For numerical values
|
111 |
|
112 |
# Define the first column explicitly, add 'Overall' as the second column, and then append the rest excluding 'Overall'
|
113 |
new_order = [original_df.columns[0], 'Overall'] + [col for col in original_df.columns if col not in [original_df.columns[0], 'Overall']]
|
init.py
CHANGED
@@ -1,95 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import pandas as pd
|
3 |
-
from constants import EVAL_REQUESTS_PATH
|
4 |
-
from pathlib import Path
|
5 |
-
from huggingface_hub import HfApi, Repository
|
6 |
-
|
7 |
-
TOKEN_HUB = os.environ.get("TOKEN_HUB", None)
|
8 |
-
QUEUE_REPO = os.environ.get("QUEUE_REPO", None)
|
9 |
-
QUEUE_PATH = os.environ.get("QUEUE_PATH", None)
|
10 |
-
|
11 |
-
hf_api = HfApi(
|
12 |
-
endpoint="https://huggingface.co",
|
13 |
-
token=TOKEN_HUB,
|
14 |
-
)
|
15 |
-
|
16 |
-
def load_all_info_from_dataset_hub():
|
17 |
-
eval_queue_repo = None
|
18 |
-
results_csv_path = None
|
19 |
-
requested_models = None
|
20 |
-
|
21 |
-
passed = True
|
22 |
-
if TOKEN_HUB is None:
|
23 |
-
passed = False
|
24 |
-
else:
|
25 |
-
print("Pulling evaluation requests and results.")
|
26 |
-
|
27 |
-
eval_queue_repo = Repository(
|
28 |
-
local_dir=QUEUE_PATH,
|
29 |
-
clone_from=QUEUE_REPO,
|
30 |
-
use_auth_token=TOKEN_HUB,
|
31 |
-
repo_type="dataset",
|
32 |
-
)
|
33 |
-
eval_queue_repo.git_pull()
|
34 |
-
|
35 |
-
# Local directory where dataset repo is cloned + folder with eval requests
|
36 |
-
directory = QUEUE_PATH / EVAL_REQUESTS_PATH
|
37 |
-
requested_models = get_all_requested_models(directory)
|
38 |
-
requested_models = [p.stem for p in requested_models]
|
39 |
-
# Local directory where dataset repo is cloned
|
40 |
-
csv_results = get_csv_with_results(QUEUE_PATH)
|
41 |
-
# csv_results = pd.read_json(QUEUE_PATH, lines=True)
|
42 |
-
if csv_results is None:
|
43 |
-
passed = False
|
44 |
-
if not passed:
|
45 |
-
print("No HuggingFace token or result path provided. Skipping evaluation requests and results.")
|
46 |
-
|
47 |
-
return eval_queue_repo, requested_models, csv_results
|
48 |
-
|
49 |
-
|
50 |
-
def upload_file(requested_model_name, path_or_fileobj):
|
51 |
-
dest_repo_file = Path(EVAL_REQUESTS_PATH) / path_or_fileobj.name
|
52 |
-
dest_repo_file = str(dest_repo_file)
|
53 |
-
hf_api.upload_file(
|
54 |
-
path_or_fileobj=path_or_fileobj,
|
55 |
-
path_in_repo=str(dest_repo_file),
|
56 |
-
repo_id=QUEUE_REPO,
|
57 |
-
token=TOKEN_HUB,
|
58 |
-
repo_type="dataset",
|
59 |
-
commit_message=f"Add {requested_model_name} to eval queue")
|
60 |
-
|
61 |
-
def get_all_requested_models(directory):
|
62 |
-
directory = Path(directory)
|
63 |
-
all_requested_models = list(directory.glob("*.txt"))
|
64 |
-
return all_requested_models
|
65 |
-
|
66 |
-
def get_csv_with_results(directory):
|
67 |
-
directory = Path(directory)
|
68 |
-
all_csv_files = list(directory.glob("*.csv"))
|
69 |
-
latest = [f for f in all_csv_files if f.stem.endswith("latest")]
|
70 |
-
if len(latest) != 1:
|
71 |
-
return None
|
72 |
-
return latest[0]
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
def is_model_on_hub(model_name, revision="main") -> bool:
|
77 |
-
try:
|
78 |
-
model_name = model_name.replace(" ","")
|
79 |
-
author = model_name.split("/")[0]
|
80 |
-
model_id = model_name.split("/")[1]
|
81 |
-
if len(author) == 0 or len(model_id) == 0:
|
82 |
-
return False, "is not a valid model name. Please use the format `author/model_name`."
|
83 |
-
except Exception as e:
|
84 |
-
return False, "is not a valid model name. Please use the format `author/model_name`."
|
85 |
-
|
86 |
-
try:
|
87 |
-
models = list(hf_api.list_models(author=author, search=model_id))
|
88 |
-
matched = [model_name for m in models if m.modelId == model_name]
|
89 |
-
if len(matched) != 1:
|
90 |
-
return False, "was not found on the hub!"
|
91 |
-
else:
|
92 |
-
return True, None
|
93 |
-
except Exception as e:
|
94 |
-
print(f"Could not get the model from the hub.: {e}")
|
95 |
-
return False, "was not found on hub!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils_display.py
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
from dataclasses import dataclass
|
2 |
-
|
3 |
-
# These classes are for user facing column names, to avoid having to change them
|
4 |
-
# all around the code when a modif is needed
|
5 |
-
@dataclass
|
6 |
-
class ColumnContent:
|
7 |
-
name: str
|
8 |
-
type: str
|
9 |
-
|
10 |
-
def fields(raw_class):
|
11 |
-
return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"]
|
12 |
-
|
13 |
-
@dataclass(frozen=True)
|
14 |
-
class AutoEvalColumn: # Auto evals column
|
15 |
-
model = ColumnContent("Model", "markdown")
|
16 |
-
avg_wer = ColumnContent("Average WER ⬇️", "number")
|
17 |
-
rtf = ColumnContent("RTF (1e-3) ⬇️", "number")
|
18 |
-
ami_wer = ColumnContent("AMI", "number")
|
19 |
-
e22_wer = ColumnContent("Earnings22", "number")
|
20 |
-
gs_wer = ColumnContent("Gigaspeech", "number")
|
21 |
-
lsc_wer = ColumnContent("LS Clean", "number")
|
22 |
-
lso_wer = ColumnContent("LS Other", "number")
|
23 |
-
ss_wer = ColumnContent("SPGISpeech", "number")
|
24 |
-
tl_wer = ColumnContent("Tedlium", "number")
|
25 |
-
vp_wer = ColumnContent("Voxpopuli", "number")
|
26 |
-
cv_wer = ColumnContent("Common Voice", "number")
|
27 |
-
|
28 |
-
|
29 |
-
def make_clickable_model(model_name, model_info):
|
30 |
-
if model_info[model_name]['hf_name'].startswith("http"):
|
31 |
-
link = model_info[model_name]['hf_name']
|
32 |
-
else:
|
33 |
-
link = f"https://huggingface.co/{model_info[model_name]['hf_name']}"
|
34 |
-
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_info[model_name]["pretty_name"]}</a>'
|
35 |
-
|
36 |
-
def styled_error(error):
|
37 |
-
return f"<p style='color: red; font-size: 20px; text-align: center;'>{error}</p>"
|
38 |
-
|
39 |
-
def styled_warning(warn):
|
40 |
-
return f"<p style='color: orange; font-size: 20px; text-align: center;'>{warn}</p>"
|
41 |
-
|
42 |
-
def styled_message(message):
|
43 |
-
return f"<p style='color: green; font-size: 20px; text-align: center;'>{message}</p>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|