Commit
·
c774b6d
1
Parent(s):
45e6546
up
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from pandas import read_csv
|
|
| 3 |
import os
|
| 4 |
import jiwer
|
| 5 |
from huggingface_hub import Repository
|
|
|
|
| 6 |
|
| 7 |
REFERENCE_NAME = "references"
|
| 8 |
SUBMISSION_NAME = "submissions"
|
|
@@ -59,41 +60,6 @@ all_submissions = [
|
|
| 59 |
if os.path.isdir(os.path.join(SUBMISSION_NAME, folder)) and folder != ".git"
|
| 60 |
]
|
| 61 |
|
| 62 |
-
all_results = read_csv(CSV_RESULTS_FILE)
|
| 63 |
-
evaluated_submissions = all_results["name"].values.tolist()
|
| 64 |
-
|
| 65 |
-
non_evaluated_submissions = set(all_submissions) - set(evaluated_submissions)
|
| 66 |
-
if len(non_evaluated_submissions) > 0:
|
| 67 |
-
for submission in non_evaluated_submissions:
|
| 68 |
-
print(f"Evaluate {submission}")
|
| 69 |
-
results = {"name": submission}
|
| 70 |
-
submitted_files = os.listdir(os.path.join(SUBMISSION_NAME, submission))
|
| 71 |
-
|
| 72 |
-
submitted_files = [f for f in submitted_files if f in EXPECTED_TEST_FILES]
|
| 73 |
-
|
| 74 |
-
if sorted(EXPECTED_TEST_FILES) != sorted(submitted_files):
|
| 75 |
-
raise ValueError(
|
| 76 |
-
f"{', '.join(submitted_files)} were submitted, but expected {', '.join(EXPECTED_TEST_FILES)}"
|
| 77 |
-
)
|
| 78 |
-
|
| 79 |
-
for file in submitted_files:
|
| 80 |
-
ref_file = os.path.join(REFERENCE_NAME, file)
|
| 81 |
-
pred_file = os.path.join(SUBMISSION_NAME, submission, file)
|
| 82 |
-
|
| 83 |
-
wer = compute_wer(pred_file, ref_file)
|
| 84 |
-
results[file.split(".")[0]] = str(wer)
|
| 85 |
-
|
| 86 |
-
wer_values = [float(results[t]) for t in TEST_SETS]
|
| 87 |
-
all_wer = sum(wer_values) / len(wer_values)
|
| 88 |
-
|
| 89 |
-
results["esc-score"] = all_wer
|
| 90 |
-
all_results = all_results.append(results, ignore_index=True)
|
| 91 |
-
|
| 92 |
-
# save and upload new evaluated results
|
| 93 |
-
all_results.to_csv(CSV_RESULTS_FILE)
|
| 94 |
-
|
| 95 |
-
commit_url = reference_repo.push_to_hub()
|
| 96 |
-
print(commit_url)
|
| 97 |
|
| 98 |
COLUMN_NAMES = {
|
| 99 |
"librispeech-clean": "ls-clean",
|
|
@@ -109,7 +75,11 @@ COLUMN_NAMES = {
|
|
| 109 |
"switch-board": "swbd",
|
| 110 |
}
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
esc_column = table.pop("esc-score")
|
| 115 |
name_column = table.pop("name")
|
|
@@ -151,9 +121,45 @@ st.markdown("TODO: Add instructions ...")
|
|
| 151 |
|
| 152 |
# Using the "with" syntax
|
| 153 |
with st.form(key="my_form"):
|
| 154 |
-
text_input = st.text_input(label="Name")
|
| 155 |
uploaded_file = st.file_uploader("Choose a zip file")
|
| 156 |
submit_button = st.form_submit_button(label="Submit")
|
| 157 |
|
| 158 |
if submit_button:
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import os
|
| 4 |
import jiwer
|
| 5 |
from huggingface_hub import Repository
|
| 6 |
+
import zipfile
|
| 7 |
|
| 8 |
REFERENCE_NAME = "references"
|
| 9 |
SUBMISSION_NAME = "submissions"
|
|
|
|
| 60 |
if os.path.isdir(os.path.join(SUBMISSION_NAME, folder)) and folder != ".git"
|
| 61 |
]
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
COLUMN_NAMES = {
|
| 65 |
"librispeech-clean": "ls-clean",
|
|
|
|
| 75 |
"switch-board": "swbd",
|
| 76 |
}
|
| 77 |
|
| 78 |
+
all_results = read_csv(CSV_RESULTS_FILE)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# Write table form CSV
|
| 82 |
+
table = all_results.copy()
|
| 83 |
|
| 84 |
esc_column = table.pop("esc-score")
|
| 85 |
name_column = table.pop("name")
|
|
|
|
| 121 |
|
| 122 |
# Using the "with" syntax
|
| 123 |
with st.form(key="my_form"):
|
|
|
|
| 124 |
uploaded_file = st.file_uploader("Choose a zip file")
|
| 125 |
submit_button = st.form_submit_button(label="Submit")
|
| 126 |
|
| 127 |
if submit_button:
|
| 128 |
+
if uploaded_file is None:
|
| 129 |
+
raise ValueError("Please make sure to have uploaded a zip file.")
|
| 130 |
+
|
| 131 |
+
submission = uploaded_file.name.split(".zip")[0]
|
| 132 |
+
with st.spinner(f"Uploading {submission}..."):
|
| 133 |
+
with zipfile.ZipFile(uploaded_file, 'r') as zip_ref:
|
| 134 |
+
zip_ref.extractall(submission_repo.local_dir)
|
| 135 |
+
submission_repo.push_to_hub()
|
| 136 |
+
|
| 137 |
+
with st.spinner(f"Computing ESC Score for {submission}..."):
|
| 138 |
+
results = {"name": submission}
|
| 139 |
+
submitted_files = os.listdir(os.path.join(SUBMISSION_NAME, submission))
|
| 140 |
+
|
| 141 |
+
submitted_files = [f for f in submitted_files if f in EXPECTED_TEST_FILES]
|
| 142 |
+
|
| 143 |
+
if sorted(EXPECTED_TEST_FILES) != sorted(submitted_files):
|
| 144 |
+
raise ValueError(
|
| 145 |
+
f"{', '.join(submitted_files)} were submitted, but expected {', '.join(EXPECTED_TEST_FILES)}"
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
for file in submitted_files:
|
| 149 |
+
ref_file = os.path.join(REFERENCE_NAME, file)
|
| 150 |
+
pred_file = os.path.join(SUBMISSION_NAME, submission, file)
|
| 151 |
+
|
| 152 |
+
wer = compute_wer(pred_file, ref_file)
|
| 153 |
+
results[file.split(".")[0]] = str(wer)
|
| 154 |
+
|
| 155 |
+
wer_values = [float(results[t]) for t in TEST_SETS]
|
| 156 |
+
all_wer = sum(wer_values) / len(wer_values)
|
| 157 |
+
|
| 158 |
+
results["esc-score"] = all_wer
|
| 159 |
+
all_results = all_results.append(results, ignore_index=True)
|
| 160 |
+
|
| 161 |
+
# save and upload new evaluated results
|
| 162 |
+
all_results.to_csv(CSV_RESULTS_FILE)
|
| 163 |
+
commit_url = submission_repo.push_to_hub()
|
| 164 |
+
|
| 165 |
+
st.success('Please refresh this space (CTRL+R) to see your result')
|