Spaces:
Runtime error
Runtime error
increase streaming timeout to 120s; add plain-text + CSV export
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import io
|
| 2 |
import os
|
|
|
|
| 3 |
import time
|
| 4 |
import datetime
|
| 5 |
import threading
|
|
@@ -20,7 +21,7 @@ os.environ.setdefault("HF_XET_HIGH_PERFORMANCE", "1")
|
|
| 20 |
N_CPUS = os.cpu_count() or 2
|
| 21 |
BATCH_SIZE = 64 # max clips per ONNX forward pass
|
| 22 |
API_TIMEOUT = 12 # seconds per datasets-server attempt (one try per endpoint)
|
| 23 |
-
STREAMING_TIMEOUT =
|
| 24 |
|
| 25 |
|
| 26 |
def _ts() -> str:
|
|
@@ -220,7 +221,7 @@ def identify_speakers(
|
|
| 220 |
):
|
| 221 |
repos = [r.strip() for r in repo_ids_text.strip().splitlines() if r.strip()]
|
| 222 |
if not repos:
|
| 223 |
-
return pd.DataFrame(), "No repos provided.", ""
|
| 224 |
|
| 225 |
token = hf_token.strip() or os.environ.get("HF_TOKEN") or None
|
| 226 |
|
|
@@ -258,7 +259,7 @@ def identify_speakers(
|
|
| 258 |
log.append(f"[{_ts()}] Phase 1 done: {ok} ok, {failed} failed, phase_total={int((time.time()-t_total)*1000)}ms")
|
| 259 |
|
| 260 |
if not repo_arrays:
|
| 261 |
-
return pd.DataFrame(), "No audio downloaded.", "\n".join(log)
|
| 262 |
|
| 263 |
# ββ Phase 2: batch embed all clips in one shot βββββββββββββββββββββββββββ
|
| 264 |
log.append(f"[{_ts()}] --- Phase 2: batch embed ---")
|
|
@@ -330,7 +331,20 @@ def identify_speakers(
|
|
| 330 |
summary = f"β
{len(repo_names)} books β {n_speakers} unique speakers ({total_ms/1000:.1f}s total)"
|
| 331 |
log.append(f"[{_ts()}] === DONE: {total_ms}ms total ===")
|
| 332 |
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
|
| 336 |
DESCRIPTION = """
|
|
@@ -405,12 +419,20 @@ with gr.Blocks(title="Speaker Identifier") as demo:
|
|
| 405 |
headers=["dataset", "speaker_id", "books_with_speaker", "intra_sim", "closest_match"],
|
| 406 |
wrap=True,
|
| 407 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
errors_out = gr.Textbox(label="Errors / Timing", interactive=False)
|
| 409 |
|
| 410 |
run_btn.click(
|
| 411 |
identify_speakers,
|
| 412 |
inputs=[repo_input, samples, audio_sec, threshold, hf_token],
|
| 413 |
-
outputs=[table_out, summary_out, errors_out],
|
| 414 |
)
|
| 415 |
|
| 416 |
demo.launch()
|
|
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
+
import tempfile
|
| 4 |
import time
|
| 5 |
import datetime
|
| 6 |
import threading
|
|
|
|
| 21 |
N_CPUS = os.cpu_count() or 2
|
| 22 |
BATCH_SIZE = 64 # max clips per ONNX forward pass
|
| 23 |
API_TIMEOUT = 12 # seconds per datasets-server attempt (one try per endpoint)
|
| 24 |
+
STREAMING_TIMEOUT = 120 # seconds before giving up on streaming fallback
|
| 25 |
|
| 26 |
|
| 27 |
def _ts() -> str:
|
|
|
|
| 221 |
):
|
| 222 |
repos = [r.strip() for r in repo_ids_text.strip().splitlines() if r.strip()]
|
| 223 |
if not repos:
|
| 224 |
+
return pd.DataFrame(), "No repos provided.", "", "", None
|
| 225 |
|
| 226 |
token = hf_token.strip() or os.environ.get("HF_TOKEN") or None
|
| 227 |
|
|
|
|
| 259 |
log.append(f"[{_ts()}] Phase 1 done: {ok} ok, {failed} failed, phase_total={int((time.time()-t_total)*1000)}ms")
|
| 260 |
|
| 261 |
if not repo_arrays:
|
| 262 |
+
return pd.DataFrame(), "No audio downloaded.", "\n".join(log), "", None
|
| 263 |
|
| 264 |
# ββ Phase 2: batch embed all clips in one shot βββββββββββββββββββββββββββ
|
| 265 |
log.append(f"[{_ts()}] --- Phase 2: batch embed ---")
|
|
|
|
| 331 |
summary = f"β
{len(repo_names)} books β {n_speakers} unique speakers ({total_ms/1000:.1f}s total)"
|
| 332 |
log.append(f"[{_ts()}] === DONE: {total_ms}ms total ===")
|
| 333 |
|
| 334 |
+
# Plain-text copy-friendly output (space-separated, matches log format)
|
| 335 |
+
text_lines = []
|
| 336 |
+
for _, r in df.iterrows():
|
| 337 |
+
text_lines.append(
|
| 338 |
+
f"{r['dataset']} {r['speaker_id']} {r['books_with_speaker']} {r['intra_sim']} {r['closest_match']}"
|
| 339 |
+
)
|
| 340 |
+
plain_text = "\n".join(text_lines)
|
| 341 |
+
|
| 342 |
+
# CSV file for download
|
| 343 |
+
tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".csv", delete=False, encoding="utf-8")
|
| 344 |
+
df.to_csv(tmp.name, index=False)
|
| 345 |
+
tmp.close()
|
| 346 |
+
|
| 347 |
+
return df, summary, "\n".join(log), plain_text, tmp.name
|
| 348 |
|
| 349 |
|
| 350 |
DESCRIPTION = """
|
|
|
|
| 419 |
headers=["dataset", "speaker_id", "books_with_speaker", "intra_sim", "closest_match"],
|
| 420 |
wrap=True,
|
| 421 |
)
|
| 422 |
+
with gr.Row():
|
| 423 |
+
text_out = gr.Textbox(
|
| 424 |
+
label="Plain text (copy-friendly)",
|
| 425 |
+
interactive=False,
|
| 426 |
+
lines=12,
|
| 427 |
+
info="dataset speaker_id n_books intra_sim closest_match",
|
| 428 |
+
)
|
| 429 |
+
csv_out = gr.File(label="Download CSV", file_types=[".csv"])
|
| 430 |
errors_out = gr.Textbox(label="Errors / Timing", interactive=False)
|
| 431 |
|
| 432 |
run_btn.click(
|
| 433 |
identify_speakers,
|
| 434 |
inputs=[repo_input, samples, audio_sec, threshold, hf_token],
|
| 435 |
+
outputs=[table_out, summary_out, errors_out, text_out, csv_out],
|
| 436 |
)
|
| 437 |
|
| 438 |
demo.launch()
|