Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -161,21 +161,26 @@ if uploaded_file:
|
|
| 161 |
|
| 162 |
diarization_output = pipeline("audio_optimized.m4a")
|
| 163 |
|
|
|
|
|
|
|
|
|
|
| 164 |
# Fix for 'DiarizeOutput' object has no attribute 'itertracks'
|
| 165 |
if isinstance(diarization_output, tuple):
|
| 166 |
diarization = diarization_output[0]
|
| 167 |
else:
|
| 168 |
diarization = diarization_output
|
| 169 |
|
| 170 |
-
#
|
| 171 |
if not hasattr(diarization, "itertracks"):
|
|
|
|
| 172 |
if hasattr(diarization_output, "annotation"):
|
| 173 |
diarization = diarization_output.annotation
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
else:
|
| 175 |
-
|
| 176 |
-
diarization = diarization_output['annotation']
|
| 177 |
-
except:
|
| 178 |
-
pass
|
| 179 |
|
| 180 |
except Exception as e:
|
| 181 |
st.error(f"Diarization Error: {e}")
|
|
@@ -193,12 +198,21 @@ if uploaded_file:
|
|
| 193 |
speaker_turns = []
|
| 194 |
if diarization:
|
| 195 |
try:
|
| 196 |
-
# Safely extract tracks
|
|
|
|
| 197 |
if hasattr(diarization, 'itertracks'):
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
speaker_turns.append({"start": turn.start, "end": turn.end, "speaker": speaker_id})
|
| 200 |
# DEBUG LOG: Verify we actually found speakers
|
| 201 |
-
print(f"DEBUG: Found {len(speaker_turns)} speaker turns
|
|
|
|
|
|
|
|
|
|
| 202 |
except Exception as e:
|
| 203 |
print(f"Error iterating tracks: {e}")
|
| 204 |
|
|
|
|
| 161 |
|
| 162 |
diarization_output = pipeline("audio_optimized.m4a")
|
| 163 |
|
| 164 |
+
# DEBUG: Print output type to logs
|
| 165 |
+
print(f"DEBUG: Output type: {type(diarization_output)}")
|
| 166 |
+
|
| 167 |
# Fix for 'DiarizeOutput' object has no attribute 'itertracks'
|
| 168 |
if isinstance(diarization_output, tuple):
|
| 169 |
diarization = diarization_output[0]
|
| 170 |
else:
|
| 171 |
diarization = diarization_output
|
| 172 |
|
| 173 |
+
# CRITICAL FIX: Extract annotation from wrapper if needed
|
| 174 |
if not hasattr(diarization, "itertracks"):
|
| 175 |
+
# Case 1: .annotation attribute
|
| 176 |
if hasattr(diarization_output, "annotation"):
|
| 177 |
diarization = diarization_output.annotation
|
| 178 |
+
# Case 2: Dict-like object
|
| 179 |
+
elif hasattr(diarization_output, "get"):
|
| 180 |
+
diarization = diarization_output.get("annotation", diarization_output)
|
| 181 |
+
# Case 3: It's just a wrapper, try iterating directly?
|
| 182 |
else:
|
| 183 |
+
pass
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
except Exception as e:
|
| 186 |
st.error(f"Diarization Error: {e}")
|
|
|
|
| 198 |
speaker_turns = []
|
| 199 |
if diarization:
|
| 200 |
try:
|
| 201 |
+
# Safely extract tracks based on the object type
|
| 202 |
+
iterator = None
|
| 203 |
if hasattr(diarization, 'itertracks'):
|
| 204 |
+
iterator = diarization.itertracks(yield_label=True)
|
| 205 |
+
elif hasattr(diarization, 'iter'): # Some versions
|
| 206 |
+
iterator = diarization.iter()
|
| 207 |
+
|
| 208 |
+
if iterator:
|
| 209 |
+
for turn, _, speaker_id in iterator:
|
| 210 |
speaker_turns.append({"start": turn.start, "end": turn.end, "speaker": speaker_id})
|
| 211 |
# DEBUG LOG: Verify we actually found speakers
|
| 212 |
+
print(f"DEBUG: Found {len(speaker_turns)} speaker turns.")
|
| 213 |
+
else:
|
| 214 |
+
print("DEBUG: Could not find iteration method on diarization object.")
|
| 215 |
+
|
| 216 |
except Exception as e:
|
| 217 |
print(f"Error iterating tracks: {e}")
|
| 218 |
|