Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ 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
|
|
@@ -164,13 +165,18 @@ if uploaded_file:
|
|
| 164 |
|
| 165 |
pipeline = Pipeline.from_pretrained(config_path)
|
| 166 |
|
| 167 |
-
#
|
|
|
|
|
|
|
|
|
|
| 168 |
if torch.cuda.is_available():
|
| 169 |
st.write("🚀 Using GPU for Diarization")
|
| 170 |
pipeline.to(torch.device("cuda"))
|
|
|
|
| 171 |
|
| 172 |
-
# Run
|
| 173 |
-
|
|
|
|
| 174 |
|
| 175 |
# Handle Wrapper
|
| 176 |
if isinstance(diarization_output, tuple):
|
|
@@ -178,7 +184,7 @@ if uploaded_file:
|
|
| 178 |
else:
|
| 179 |
diarization = diarization_output
|
| 180 |
|
| 181 |
-
# Extract
|
| 182 |
if not hasattr(diarization, "itertracks"):
|
| 183 |
if hasattr(diarization_output, "annotation"):
|
| 184 |
diarization = diarization_output.annotation
|
|
@@ -221,6 +227,7 @@ if uploaded_file:
|
|
| 221 |
mid_time = (segment['start'] + segment['end']) / 2
|
| 222 |
speaker = "Unknown"
|
| 223 |
|
|
|
|
| 224 |
if speaker_turns:
|
| 225 |
# 1. Strict
|
| 226 |
for turn in speaker_turns:
|
|
@@ -263,6 +270,7 @@ if uploaded_file:
|
|
| 263 |
st.error("Gemini API Key required. Please set it in Secrets or app.py.")
|
| 264 |
else:
|
| 265 |
with st.spinner("Analyzing..."):
|
|
|
|
| 266 |
edl_segments = call_gemini_for_edl(st.session_state.transcript, brief, ACTIVE_GEMINI_KEY)
|
| 267 |
if edl_segments:
|
| 268 |
final_edl = generate_cmx_edl("AI_Senior_Editor_Cut", edl_segments, uploaded_file.name, fps)
|
|
|
|
| 6 |
import requests
|
| 7 |
import torch
|
| 8 |
import numpy
|
| 9 |
+
import torchaudio
|
| 10 |
from datetime import timedelta
|
| 11 |
from pyannote.audio import Pipeline
|
| 12 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 165 |
|
| 166 |
pipeline = Pipeline.from_pretrained(config_path)
|
| 167 |
|
| 168 |
+
# Load audio manually into tensor for robust processing
|
| 169 |
+
waveform, sample_rate = torchaudio.load("temp_audio.wav")
|
| 170 |
+
|
| 171 |
+
# Ensure we are on GPU
|
| 172 |
if torch.cuda.is_available():
|
| 173 |
st.write("🚀 Using GPU for Diarization")
|
| 174 |
pipeline.to(torch.device("cuda"))
|
| 175 |
+
waveform = waveform.to(torch.device("cuda"))
|
| 176 |
|
| 177 |
+
# Run pipeline by passing the tensor dictionary
|
| 178 |
+
# This is the most reliable way to avoid file I/O issues in Docker
|
| 179 |
+
diarization_output = pipeline({"waveform": waveform, "sample_rate": sample_rate})
|
| 180 |
|
| 181 |
# Handle Wrapper
|
| 182 |
if isinstance(diarization_output, tuple):
|
|
|
|
| 184 |
else:
|
| 185 |
diarization = diarization_output
|
| 186 |
|
| 187 |
+
# CRITICAL FIX: Extract annotation from wrapper
|
| 188 |
if not hasattr(diarization, "itertracks"):
|
| 189 |
if hasattr(diarization_output, "annotation"):
|
| 190 |
diarization = diarization_output.annotation
|
|
|
|
| 227 |
mid_time = (segment['start'] + segment['end']) / 2
|
| 228 |
speaker = "Unknown"
|
| 229 |
|
| 230 |
+
# Matching logic
|
| 231 |
if speaker_turns:
|
| 232 |
# 1. Strict
|
| 233 |
for turn in speaker_turns:
|
|
|
|
| 270 |
st.error("Gemini API Key required. Please set it in Secrets or app.py.")
|
| 271 |
else:
|
| 272 |
with st.spinner("Analyzing..."):
|
| 273 |
+
# Fixed missing parenthesis here
|
| 274 |
edl_segments = call_gemini_for_edl(st.session_state.transcript, brief, ACTIVE_GEMINI_KEY)
|
| 275 |
if edl_segments:
|
| 276 |
final_edl = generate_cmx_edl("AI_Senior_Editor_Cut", edl_segments, uploaded_file.name, fps)
|