Add HuggingFace token setting for speaker detection

- Add "Speakers" tab in Settings with HF token input field
- Include step-by-step instructions for obtaining the token
- Pass hf_token from settings through Rust → Python pipeline → diarize
- Token can also be set via HF_TOKEN environment variable as fallback
- Move skip_diarization checkbox to Speakers tab

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 18:08:51 -08:00
parent ed626b8ba0
commit baf820286f
7 changed files with 67 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ class DiarizeService:
def __init__(self) -> None:
self._pipeline: Any = None
def _ensure_pipeline(self) -> Any:
def _ensure_pipeline(self, hf_token: str | None = None) -> Any:
"""Load the pyannote diarization pipeline (lazy)."""
if self._pipeline is not None:
return self._pipeline
@@ -44,7 +44,9 @@ class DiarizeService:
print("[sidecar] Loading pyannote diarization pipeline...", file=sys.stderr, flush=True)
hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or None
# Use token from argument, fall back to environment variable
if not hf_token:
hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or None
models = [
"pyannote/speaker-diarization-3.1",
@@ -81,6 +83,7 @@ class DiarizeService:
num_speakers: int | None = None,
min_speakers: int | None = None,
max_speakers: int | None = None,
hf_token: str | None = None,
) -> DiarizationResult:
"""Run speaker diarization on an audio file.
@@ -98,7 +101,7 @@ class DiarizeService:
progress_message(request_id, 0, "loading_diarization", "Loading diarization model...")
)
pipeline = self._ensure_pipeline()
pipeline = self._ensure_pipeline(hf_token=hf_token)
write_message(
progress_message(request_id, 20, "diarizing", "Running speaker diarization...")