Spaces:
Sleeping
Sleeping
Luis J Camargo commited on
Commit 路
a0fb777
1
Parent(s): 197cb52
feat: Enhance curated examples display with individual audio players and add a script for parsing results.
Browse files
app.py
CHANGED
|
@@ -277,8 +277,8 @@ def predict_language(audio_path, fam_k=1, fam_thresh=0.0, super_k=1, super_thres
|
|
| 277 |
table_data.append([name, f"{score:.2%}"])
|
| 278 |
|
| 279 |
if not table_data:
|
| 280 |
-
return pd.DataFrame(columns=[
|
| 281 |
-
return pd.DataFrame(table_data, columns=[
|
| 282 |
|
| 283 |
df_fam = build_df(fam_probs, fam_k, fam_thresh, label_extractor.family_labels)
|
| 284 |
df_super = build_df(super_probs, super_k, super_thresh, label_extractor.super_labels)
|
|
@@ -304,18 +304,8 @@ except Exception as e:
|
|
| 304 |
icon_html = ""
|
| 305 |
|
| 306 |
# --- Load curated examples ---
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
table_headers = [
|
| 310 |
-
i18n("col_sample"),
|
| 311 |
-
i18n("col_pred_fam"),
|
| 312 |
-
i18n("col_pred_super"),
|
| 313 |
-
i18n("col_pred_code"),
|
| 314 |
-
i18n("col_act_fam"),
|
| 315 |
-
i18n("col_act_super"),
|
| 316 |
-
i18n("col_act_code"),
|
| 317 |
-
i18n("col_match")
|
| 318 |
-
]
|
| 319 |
try:
|
| 320 |
with open("results.txt", "r", encoding="utf-8") as f:
|
| 321 |
results_content = f.read()
|
|
@@ -327,22 +317,8 @@ try:
|
|
| 327 |
block = sample_blocks[i+1].strip()
|
| 328 |
audio_path = f"samples/sample{sample_num}.wav"
|
| 329 |
if os.path.exists(audio_path):
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
match_val = re.search(r'Match:\s*([0-9.\s鉁匽+)', block)
|
| 333 |
-
|
| 334 |
-
t_fam, t_sup, t_code = truth_match.groups() if truth_match else ("-", "-", "-")
|
| 335 |
-
p_fam, p_sup, p_code = pred_match.groups() if pred_match else ("-", "-", "-")
|
| 336 |
-
m_val = match_val.group(1).strip() if match_val else "-"
|
| 337 |
-
|
| 338 |
-
row_data = [
|
| 339 |
-
f"馃攰 {sample_num}",
|
| 340 |
-
p_fam, p_sup, p_code,
|
| 341 |
-
t_fam, t_sup, t_code,
|
| 342 |
-
m_val
|
| 343 |
-
]
|
| 344 |
-
curated_examples.append(row_data)
|
| 345 |
-
audio_paths.append(audio_path)
|
| 346 |
except Exception as e:
|
| 347 |
print(f"Warning: Could not parse results.txt: {e}")
|
| 348 |
|
|
@@ -353,7 +329,8 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
| 353 |
<div style="text-align: center; padding: 30px; background: linear-gradient(120deg, rgb(2, 132, 199) 0%, rgb(16, 185, 129) 60%, rgb(5, 150, 105) 100%); color: white; border-radius: 15px; margin-bottom: 25px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);">
|
| 354 |
{icon_html}
|
| 355 |
<h1 style="color: white; margin: 0; font-size: 2.5em;">馃Α Tachiwin AudioId 馃Α</h1>
|
| 356 |
-
<p style="font-size: 1.2em; opacity: 0.9; margin-top: 10px;">
|
|
|
|
| 357 |
</div>
|
| 358 |
"""
|
| 359 |
)
|
|
@@ -389,9 +366,9 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
| 389 |
|
| 390 |
with gr.Column(scale=1):
|
| 391 |
gr.Markdown(i18n("results_header"))
|
| 392 |
-
fam_table = gr.Dataframe(headers=[
|
| 393 |
-
super_table = gr.Dataframe(headers=[
|
| 394 |
-
code_table = gr.Dataframe(headers=[
|
| 395 |
|
| 396 |
submit_btn.click(
|
| 397 |
fn=predict_language,
|
|
@@ -408,15 +385,16 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
| 408 |
gr.Markdown(i18n("curated_header"))
|
| 409 |
gr.Markdown(i18n("curated_desc"))
|
| 410 |
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
|
|
|
| 420 |
|
| 421 |
if __name__ == "__main__":
|
| 422 |
demo.launch(ssr_mode=False, i18n=i18n)
|
|
|
|
| 277 |
table_data.append([name, f"{score:.2%}"])
|
| 278 |
|
| 279 |
if not table_data:
|
| 280 |
+
return pd.DataFrame(columns=["Prediction / Predicci贸n", "Confidence / Confianza"])
|
| 281 |
+
return pd.DataFrame(table_data, columns=["Prediction / Predicci贸n", "Confidence / Confianza"])
|
| 282 |
|
| 283 |
df_fam = build_df(fam_probs, fam_k, fam_thresh, label_extractor.family_labels)
|
| 284 |
df_super = build_df(super_probs, super_k, super_thresh, label_extractor.super_labels)
|
|
|
|
| 304 |
icon_html = ""
|
| 305 |
|
| 306 |
# --- Load curated examples ---
|
| 307 |
+
curated_labels = []
|
| 308 |
+
curated_audio = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
try:
|
| 310 |
with open("results.txt", "r", encoding="utf-8") as f:
|
| 311 |
results_content = f.read()
|
|
|
|
| 317 |
block = sample_blocks[i+1].strip()
|
| 318 |
audio_path = f"samples/sample{sample_num}.wav"
|
| 319 |
if os.path.exists(audio_path):
|
| 320 |
+
curated_audio.append(audio_path)
|
| 321 |
+
curated_labels.append(f"Sample {sample_num}:\n{block}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
except Exception as e:
|
| 323 |
print(f"Warning: Could not parse results.txt: {e}")
|
| 324 |
|
|
|
|
| 329 |
<div style="text-align: center; padding: 30px; background: linear-gradient(120deg, rgb(2, 132, 199) 0%, rgb(16, 185, 129) 60%, rgb(5, 150, 105) 100%); color: white; border-radius: 15px; margin-bottom: 25px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);">
|
| 330 |
{icon_html}
|
| 331 |
<h1 style="color: white; margin: 0; font-size: 2.5em;">馃Α Tachiwin AudioId 馃Α</h1>
|
| 332 |
+
<p style="font-size: 1.2em; opacity: 0.9; margin-top: 10px;">Identify any of the 68 languages of Mexico and their 360 variants<br/>
|
| 333 |
+
<i>Identifica cualquiera de las 68 lenguas originarias de M茅xico y sus 360 variantes</i></p>
|
| 334 |
</div>
|
| 335 |
"""
|
| 336 |
)
|
|
|
|
| 366 |
|
| 367 |
with gr.Column(scale=1):
|
| 368 |
gr.Markdown(i18n("results_header"))
|
| 369 |
+
fam_table = gr.Dataframe(headers=["Prediction / Predicci贸n", "Confidence / Confianza"], datatype=["str", "str"], label=i18n("pred_fam_label"), interactive=False, wrap=True)
|
| 370 |
+
super_table = gr.Dataframe(headers=["Prediction / Predicci贸n", "Confidence / Confianza"], datatype=["str", "str"], label=i18n("pred_super_label"), interactive=False, wrap=True)
|
| 371 |
+
code_table = gr.Dataframe(headers=["Prediction / Predicci贸n", "Confidence / Confianza"], datatype=["str", "str"], label=i18n("pred_code_label"), interactive=False, wrap=True)
|
| 372 |
|
| 373 |
submit_btn.click(
|
| 374 |
fn=predict_language,
|
|
|
|
| 385 |
gr.Markdown(i18n("curated_header"))
|
| 386 |
gr.Markdown(i18n("curated_desc"))
|
| 387 |
|
| 388 |
+
with gr.Group():
|
| 389 |
+
columns = 3
|
| 390 |
+
for row_idx in range(0, len(curated_audio), columns):
|
| 391 |
+
with gr.Row():
|
| 392 |
+
for i in range(row_idx, min(row_idx+columns, len(curated_audio))):
|
| 393 |
+
with gr.Column(scale=1):
|
| 394 |
+
gr.Markdown(f"```text\n{curated_labels[i]}\n```")
|
| 395 |
+
gr.Audio(value=curated_audio[i], interactive=False, show_label=False)
|
| 396 |
+
btn = gr.Button("Load / Cargar", size="sm")
|
| 397 |
+
btn.click(fn=lambda url=curated_audio[i]: url, inputs=[], outputs=[audio_input])
|
| 398 |
|
| 399 |
if __name__ == "__main__":
|
| 400 |
demo.launch(ssr_mode=False, i18n=i18n)
|