Spaces:
Runtime error
Runtime error
increase streaming timeout to 120s; add plain-text + CSV export
Browse files1234514 unmodified lines20212223242526193 unmodified lines22022122222322422522631 unmodified lines25825926026126226326465 unmodified lines33033133233333433533668 unmodified lines405406407408409410411412413414415416import ioimport osimport 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 fallbackdef _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.", ""token = hf_token.strip() or os.environ.get("HF_TOKEN") or None31 unmodified lineslog.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)# ββ Phase 2: batch embed all clips in one shot βββββββββββββββββββββββββββlog.append(f"[{_ts()}] --- Phase 2: batch embed ---")65 unmodified linessummary = f"β {len(repo_names)} books β {n_speakers} unique speakers ({total_ms/1000:.1f}s total)"log.append(f"[{_ts()}] === DONE: {total_ms}ms total ===")return df, summary, "\n".join(log)DESCRIPTION = """68 unmodified linesheaders=["dataset", "speaker_id", "books_with_speaker", "intra_sim", "closest_match"],wrap=True,)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],)demo.launch()12345614 unmodified lines21222324252627193 unmodified lines22122222322422522622731 unmodified lines25926026126226326426565 unmodified lines33133233333433533633733833934034134234334434534634734834935068 unmodified lines419420421422423424425426427428429430431432433434435436437438import 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 = 120 # seconds before giving up on streaming fallbackdef _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.", "", "", Nonetoken = hf_token.strip() or os.environ.get("HF_TOKEN") or None31 unmodified lineslog.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), "", None# ββ Phase 2: batch embed all clips in one shot βββββββββββββββββββββββββββlog.append(f"[{_ts()}] --- Phase 2: batch embed ---")65 unmodified linessummary = 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 downloadtmp = 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), plain_text, tmp.nameDESCRIPTION = """68 unmodified linesheaders=["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, text_out, csv_out],)demo.launch()
app.py+27-5