Spaces:
Runtime error
Runtime error
Tristan Thrush
commited on
Commit
β’
341b6a4
1
Parent(s):
2d4b120
removed hf-asr-leaderboard filter, improved parser, added query param dataset select option
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ def make_clickable(model_name):
|
|
14 |
def get_model_ids():
|
15 |
api = HfApi()
|
16 |
# TODO: switch to hf-leaderboards for the final version.
|
17 |
-
models = api.list_models(filter="
|
18 |
model_ids = [x.modelId for x in models]
|
19 |
return model_ids
|
20 |
|
@@ -23,8 +23,8 @@ def get_metadata(model_id):
|
|
23 |
try:
|
24 |
readme_path = hf_hub_download(model_id, filename="README.md")
|
25 |
return metadata_load(readme_path)
|
26 |
-
except
|
27 |
-
# 404 README.md not found
|
28 |
return None
|
29 |
|
30 |
|
@@ -40,15 +40,15 @@ def parse_metric_value(value):
|
|
40 |
value = value[0]
|
41 |
else:
|
42 |
value = None
|
43 |
-
value = round(value, 2) if value
|
44 |
return value
|
45 |
|
46 |
|
47 |
def parse_metrics_rows(meta):
|
48 |
-
if "model-index" not in meta:
|
49 |
return None
|
50 |
for result in meta["model-index"][0]["results"]:
|
51 |
-
if "dataset" not in result or "metrics" not in result:
|
52 |
continue
|
53 |
dataset = result["dataset"]["type"]
|
54 |
if "args" not in result["dataset"]:
|
@@ -56,7 +56,7 @@ def parse_metrics_rows(meta):
|
|
56 |
row = {"dataset": dataset}
|
57 |
for metric in result["metrics"]:
|
58 |
type = metric["type"].lower().strip()
|
59 |
-
value = parse_metric_value(metric
|
60 |
if value is None:
|
61 |
continue
|
62 |
if type not in row or value < row[type]:
|
@@ -65,7 +65,7 @@ def parse_metrics_rows(meta):
|
|
65 |
yield row
|
66 |
|
67 |
|
68 |
-
@st.cache(ttl=
|
69 |
def get_data():
|
70 |
data = []
|
71 |
model_ids = get_model_ids()
|
@@ -86,10 +86,16 @@ selectable_datasets = list(set(dataframe.dataset.tolist()))
|
|
86 |
|
87 |
st.markdown("# π€ Leaderboards")
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
dataset = st.sidebar.selectbox(
|
90 |
"Dataset",
|
91 |
selectable_datasets,
|
92 |
-
index=selectable_datasets.index(
|
93 |
)
|
94 |
|
95 |
dataset_df = dataframe[dataframe.dataset == dataset]
|
|
|
14 |
def get_model_ids():
|
15 |
api = HfApi()
|
16 |
# TODO: switch to hf-leaderboards for the final version.
|
17 |
+
models = api.list_models(filter="model-index")
|
18 |
model_ids = [x.modelId for x in models]
|
19 |
return model_ids
|
20 |
|
|
|
23 |
try:
|
24 |
readme_path = hf_hub_download(model_id, filename="README.md")
|
25 |
return metadata_load(readme_path)
|
26 |
+
except Exception:
|
27 |
+
# 404 README.md not found or problem loading it
|
28 |
return None
|
29 |
|
30 |
|
|
|
40 |
value = value[0]
|
41 |
else:
|
42 |
value = None
|
43 |
+
value = round(value, 2) if isinstance(value, float) else None
|
44 |
return value
|
45 |
|
46 |
|
47 |
def parse_metrics_rows(meta):
|
48 |
+
if not isinstance(meta["model-index"], list) or len(meta["model-index"]) == 0 or "results" not in meta["model-index"][0]:
|
49 |
return None
|
50 |
for result in meta["model-index"][0]["results"]:
|
51 |
+
if "dataset" not in result or "metrics" not in result or "type" not in result["dataset"]:
|
52 |
continue
|
53 |
dataset = result["dataset"]["type"]
|
54 |
if "args" not in result["dataset"]:
|
|
|
56 |
row = {"dataset": dataset}
|
57 |
for metric in result["metrics"]:
|
58 |
type = metric["type"].lower().strip()
|
59 |
+
value = parse_metric_value(metric.get("value", None))
|
60 |
if value is None:
|
61 |
continue
|
62 |
if type not in row or value < row[type]:
|
|
|
65 |
yield row
|
66 |
|
67 |
|
68 |
+
@st.cache(ttl=86400)
|
69 |
def get_data():
|
70 |
data = []
|
71 |
model_ids = get_model_ids()
|
|
|
86 |
|
87 |
st.markdown("# π€ Leaderboards")
|
88 |
|
89 |
+
query_params = st.experimental_get_query_params()
|
90 |
+
default_dataset = "common_voice"
|
91 |
+
if "dataset" in query_params:
|
92 |
+
if len(query_params["dataset"]) > 0 and query_params["dataset"][0] in selectable_datasets:
|
93 |
+
default_dataset = query_params["dataset"][0]
|
94 |
+
|
95 |
dataset = st.sidebar.selectbox(
|
96 |
"Dataset",
|
97 |
selectable_datasets,
|
98 |
+
index=selectable_datasets.index(default_dataset),
|
99 |
)
|
100 |
|
101 |
dataset_df = dataframe[dataframe.dataset == dataset]
|