Spaces:
Runtime error
Runtime error
increase streaming timeout to 120s; add plain-text + CSV export
Browse files12345614 unmodified lines2122232324252627193 unmodified lines22122222322322422522622731 unmodified lines25926026126126226326426565 unmodified lines33133233333433533633733833934034134234334434534633334734834935068 unmodified lines419420421422423424425426427428429430431432433434413435436437438import ioimport osimport tempfileimport timeimport datetimeimport threading14 unmodified linesN_CPUS = os.cpu_count() or 2BATCH_SIZE = 64 # max clips per ONNX forward passAPI_TIMEOUT = 12 # seconds per datasets-server attempt (one try per endpoint)STREAMING_TIMEOUT = 45 # seconds before giving up on streaming fallbackSTREAMING_TIMEOUT = 120 # seconds before giving up on streaming fallback
def _ts() -> str:193 unmodified lines): repos = [r.strip() for r in repo_ids_text.strip().splitlines() if r.strip()] if not repos: return pd.DataFrame(), "No repos provided.", "" return pd.DataFrame(), "No repos provided.", "", "", None
token = hf_token.strip() or os.environ.get("HF_TOKEN") or None
31 unmodified lines log.append(f"[{_ts()}] Phase 1 done: {ok} ok, {failed} failed, phase_total={int((time.time()-t_total)*1000)}ms")
if not repo_arrays: return pd.DataFrame(), "No audio downloaded.", "\n".join(log) return pd.DataFrame(), "No audio downloaded.", "\n".join(log), "", None
# ββ Phase 2: batch embed all clips in one shot βββββββββββββββββββββββββββ log.append(f"[{_ts()}] --- Phase 2: batch embed ---")65 unmodified lines summary = f"β
{len(repo_names)} books β {n_speakers} unique speakers ({total_ms/1000:.1f}s total)" log.append(f"[{_ts()}] === DONE: {total_ms}ms total ===")
# Plain-text copy-friendly output (space-separated, matches log format) text_lines = [] for _, r in df.iterrows(): text_lines.append( f"{r['dataset']} {r['speaker_id']} {r['books_with_speaker']} {r['intra_sim']} {r['closest_match']}" ) plain_text = "\n".join(text_lines)
# CSV file for download tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".csv", delete=False, encoding="utf-8") df.to_csv(tmp.name, index=False) tmp.close()
return df, summary, "\n".join(log) return df, summary, "\n".join(log), plain_text, tmp.name
DESCRIPTION = """68 unmodified lines headers=["dataset", "speaker_id", "books_with_speaker", "intra_sim", "closest_match"], wrap=True, ) with gr.Row(): text_out = gr.Textbox( label="Plain text (copy-friendly)", interactive=False, lines=12, info="dataset speaker_id n_books intra_sim closest_match", ) csv_out = gr.File(label="Download CSV", file_types=[".csv"]) errors_out = gr.Textbox(label="Errors / Timing", interactive=False)
run_btn.click( identify_speakers, inputs=[repo_input, samples, audio_sec, threshold, hf_token], outputs=[table_out, summary_out, errors_out], outputs=[table_out, summary_out, errors_out, text_out, csv_out], )
demo.launch()app.py+27-5