NickVerri commited on
Commit
7f21605
·
verified ·
1 Parent(s): ccb78b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -7
app.py CHANGED
@@ -5,7 +5,7 @@ import json
5
  import os
6
  import requests
7
  import torch
8
- import numpy # Added missing import
9
  from datetime import timedelta
10
  from pyannote.audio import Pipeline
11
  from huggingface_hub import hf_hub_download
@@ -158,7 +158,27 @@ if uploaded_file:
158
  if torch.cuda.is_available():
159
  pipeline.to(torch.device("cuda"))
160
 
161
- diarization = pipeline("audio_optimized.m4a")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  except Exception as e:
163
  st.error(f"Diarization Error: {e}")
164
  st.stop()
@@ -172,11 +192,17 @@ if uploaded_file:
172
  for segment in result['segments']:
173
  mid_time = (segment['start'] + segment['end']) / 2
174
  speaker = "Unknown"
175
- for turn, _, speaker_id in diarization.itertracks(yield_label=True):
176
- if turn.start <= mid_time <= turn.end:
177
- speaker = speaker_id
178
- break
179
 
 
 
 
 
 
 
 
 
 
 
180
  final_segments.append({
181
  "speaker": speaker,
182
  "text": segment['text'],
@@ -194,4 +220,19 @@ if uploaded_file:
194
  # Diarization Preview to help the user identify roles
195
  with st.expander("Transcript Preview (Diarized)"):
196
  for seg in st.session_state.transcript[:20]: # Show first 20 segments
197
- st.write(f"**{seg['speaker']}:** {seg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  import os
6
  import requests
7
  import torch
8
+ import numpy
9
  from datetime import timedelta
10
  from pyannote.audio import Pipeline
11
  from huggingface_hub import hf_hub_download
 
158
  if torch.cuda.is_available():
159
  pipeline.to(torch.device("cuda"))
160
 
161
+ diarization_output = pipeline("audio_optimized.m4a")
162
+
163
+ # Fix for 'DiarizeOutput' object has no attribute 'itertracks'
164
+ # Handle potential tuple output or direct object
165
+ if isinstance(diarization_output, tuple):
166
+ diarization = diarization_output[0]
167
+ else:
168
+ diarization = diarization_output
169
+
170
+ # Verify we have the annotation object by checking for itertracks
171
+ if not hasattr(diarization, "itertracks"):
172
+ # If it's a Hook/Wrapper object (common in some versions), try getting the annotation
173
+ if hasattr(diarization_output, "annotation"):
174
+ diarization = diarization_output.annotation
175
+ else:
176
+ # Last resort: if it behaves like a dict, try getting 'annotation' key
177
+ try:
178
+ diarization = diarization_output['annotation']
179
+ except:
180
+ pass
181
+
182
  except Exception as e:
183
  st.error(f"Diarization Error: {e}")
184
  st.stop()
 
192
  for segment in result['segments']:
193
  mid_time = (segment['start'] + segment['end']) / 2
194
  speaker = "Unknown"
 
 
 
 
195
 
196
+ # Safe iteration over tracks
197
+ try:
198
+ for turn, _, speaker_id in diarization.itertracks(yield_label=True):
199
+ if turn.start <= mid_time <= turn.end:
200
+ speaker = speaker_id
201
+ break
202
+ except AttributeError:
203
+ # Fallback if diarization object is still malformed
204
+ speaker = "Error-No-Speaker"
205
+
206
  final_segments.append({
207
  "speaker": speaker,
208
  "text": segment['text'],
 
220
  # Diarization Preview to help the user identify roles
221
  with st.expander("Transcript Preview (Diarized)"):
222
  for seg in st.session_state.transcript[:20]: # Show first 20 segments
223
+ # FIXED: Ensure this line is a complete string with no breaks
224
+ st.write(f"**{seg['speaker']}:** {seg['text']}")
225
+
226
+ brief = st.text_area("Creative Brief", placeholder="e.g. Focus on the yeast story, remove the interviewer.")
227
+
228
+ if st.button("Step 2: Create EDL"):
229
+ if not ACTIVE_GEMINI_KEY:
230
+ st.error("Gemini API Key required. Please set it in Secrets or app.py.")
231
+ else:
232
+ with st.spinner("Analyzing..."):
233
+ edl_segments = call_gemini_for_edl(st.session_state.transcript, brief, ACTIVE_GEMINI_KEY)
234
+ if edl_segments:
235
+ final_edl = generate_cmx_edl("AI_Senior_Editor_Cut", edl_segments, uploaded_file.name, fps)
236
+ st.subheader("EDL Preview")
237
+ st.code(final_edl, language="text")
238
+ st.download_button("Download EDL", data=final_edl, file_name="edit.edl")