fix: handle pyannote legacy and pre-4.x diarization return types#191
Conversation
…urn types pyannote 4.x returns DiarizeOutput (with .speaker_diarization) when legacy=False, but returns Annotation directly when legacy=True or when using pyannote <4.0. Guard with hasattr check so both paths work correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pyannote>=4.0 is pinned in requirements.txt so legacy=True can never occur in this codebase. The hasattr guard was dead code. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates the diarization service to support both legacy and modern PyAnnote return types by conditionally accessing the speaker diarization attribute. The review feedback suggests improving the implementation's idiomaticity by using getattr and adding a safety check for None values to prevent potential runtime errors.
I am having trouble creating individual review comments. Click here to see my feedback.
backend/services/diarization_service.py (87-91)
The current implementation uses a verbose ternary operator to handle the different return types from PyAnnote. Using getattr with a default value is more idiomatic in Python for this pattern. Additionally, adding an explicit check for None ensures the service handles cases where the pipeline might fail to return a result without raising a confusing AttributeError when itertracks is called later.
if diarization is None:
raise ValueError("Diarization pipeline returned no result")
annotation = getattr(diarization, "speaker_diarization", diarization)Badges now cap at 160px with text-overflow: ellipsis and a title attribute for full name on hover. Container uses flex-wrap so multiple badges wrap cleanly instead of overflowing the card. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
/gemini review |
Combine getSpeakerColor inline styles (from main) with the maxWidth ellipsis truncation (from this branch). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates a comment in the backend diarization service and enhances the speaker badge UI in the frontend with flexbox layout and text truncation. Feedback highlights a missing logic implementation in the backend to handle different pyannote return types, which could cause an AttributeError. In the frontend, it is recommended to use the Bootstrap 'text-truncate' utility class instead of multiple inline styles for better maintainability.
Replace verbose inline overflow styles with Bootstrap text-truncate utility class, keeping only maxWidth in the style prop. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
diarization_service.pyassumed pyannote 4.x always returns aDiarizeOutputobject (accessing.speaker_diarization)legacy=Trueis set on the pipeline, or if someone runs with pyannote <4.0 (which returns anAnnotationdirectly)hasattrguard to handle both return types gracefullyRoot cause
pyannote 4.x
SpeakerDiarization.apply()returns:DiarizeOutputwhenlegacy=False(default)Annotationdirectly whenlegacy=True(backwards compat mode)Test plan
legacy=False🤖 Generated with Claude Code