Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download tests/test_wer_chart.py from treble-technologies/ffasr: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/spaces/treble-technologies/ffasr/resolve/main/tests/test_wer_chart.py
- Command line
-
hf download hf://spaces/treble-technologies/ffasr/tests/test_wer_chart.py
-
curl -L -o test_wer_chart.py https://huggingface.co/spaces/treble-technologies/ffasr/resolve/main/tests/test_wer_chart.py
2.34 kB
| """Avg WER chart above the ASR board (leaderboard_view.render_wer_chart).""" | |
| from __future__ import annotations | |
| import re | |
| import pandas as pd | |
| import pytest | |
| import leaderboard_view as lv | |
| AVG = lv.AutoEvalColumn.avg_wer_core.name | |
| def _frame(rows): | |
| return pd.DataFrame(rows, columns=[lv.RANK_COL, lv.MODEL_COL, AVG]) | |
| def test_columns_follow_rank_with_avg_wer_heights(): | |
| df = _frame([[2, "org/b", 6.0], [1, "org/a", 5.0], [3, "org/c", 7.0]]) | |
| extras = {"org/a": {"ffas": 80.0}, "org/b": {"ffas": 91.5, "rtf": 120.0, "params": 0.6}} | |
| core = {"org/b": (4.0, 6.0, 9.0, 60.0)} | |
| html = lv.render_wer_chart(df, core, extras) | |
| assert re.findall(r"data-model='([^']+)'", html) == ["org/a", "org/b", "org/c"] | |
| assert re.findall(r"data-rank='(\d+)'", html) == ["1", "2", "3"] | |
| # Axis tops out at the next round number above the tallest bar (7 -> 8). | |
| assert "data-scale='8'" in html and "--v:62.5%" in html and "--v:87.5%" in html | |
| assert re.findall(r"data-t='\d+'>([\d.]+)<", html) == ["0", "2", "4", "6", "8"] | |
| # Avg WER on the caps; FFAS and the rest for the hover card. | |
| assert "<span class='ff-colval'>5.00</span>" in html | |
| assert "data-ffas='91.5'" in html and "data-low='60.00'" in html and "data-rtf='120.0'" in html | |
| assert "data-ffas=''" in html # org/c has no FFAS, still drawn | |
| assert html.count("tabindex='0'") == 1 | |
| assert "Avg WER by model" in html and "FFAS, 0–100" not in html | |
| def test_chart_scale(top, scale): | |
| assert lv.chart_scale(top) == scale | |
| def test_models_without_avg_wer_are_counted_not_drawn(): | |
| df = _frame([[1, "org/a", 5.0], [2, "org/b", None]]) | |
| html = lv.render_wer_chart(df, {}, {}) | |
| assert re.findall(r"data-model='([^']+)'", html) == ["org/a"] | |
| assert "1 model has no Avg WER yet" in html | |
| def test_empty_frames_render_nothing(): | |
| assert lv.render_wer_chart(_frame([]), {}, {}) == "" | |
| assert lv.render_wer_chart(_frame([[1, "org/a", None]]), {}, {}) == "" | |
| def test_model_names_are_escaped(): | |
| cell = "org/<img src=x onerror=alert(1)>" | |
| html = lv.render_wer_chart(_frame([[1, cell, 5.0]]), {}, {}) | |
| assert "<img" not in html | |
| assert "<img" in html | |