Update app.py
Browse files
app.py
CHANGED
|
@@ -147,7 +147,7 @@ if uploaded_file:
|
|
| 147 |
st.write("🗣️ **Running Speaker Diarization...**")
|
| 148 |
diarization = None
|
| 149 |
try:
|
| 150 |
-
#
|
| 151 |
config_path = hf_hub_download(
|
| 152 |
repo_id="pyannote/speaker-diarization-3.1",
|
| 153 |
filename="config.yaml",
|
|
@@ -155,21 +155,14 @@ if uploaded_file:
|
|
| 155 |
)
|
| 156 |
pipeline = Pipeline.from_pretrained(config_path)
|
| 157 |
|
| 158 |
-
#
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
#
|
| 162 |
-
|
| 163 |
-
resampler = T.Resample(sample_rate, 16000)
|
| 164 |
-
waveform = resampler(waveform)
|
| 165 |
-
sample_rate = 16000
|
| 166 |
|
| 167 |
-
# Move to GPU if available
|
| 168 |
-
if torch.cuda.is_available():
|
| 169 |
-
st.write("🚀 Using GPU for Diarization")
|
| 170 |
-
pipeline.to(torch.device("cuda"))
|
| 171 |
-
waveform = waveform.to(torch.device("cuda"))
|
| 172 |
-
|
| 173 |
# Run Pipeline on Tensor directly
|
| 174 |
diarization_output = pipeline({"waveform": waveform, "sample_rate": sample_rate})
|
| 175 |
|
|
@@ -183,6 +176,8 @@ if uploaded_file:
|
|
| 183 |
if not hasattr(diarization, "itertracks"):
|
| 184 |
if hasattr(diarization_output, "annotation"):
|
| 185 |
diarization = diarization_output.annotation
|
|
|
|
|
|
|
| 186 |
|
| 187 |
except Exception as e:
|
| 188 |
st.error(f"Diarization Error: {e}")
|
|
@@ -190,6 +185,7 @@ if uploaded_file:
|
|
| 190 |
|
| 191 |
# 2. Whisper Transcription
|
| 192 |
st.write("📝 **Transcribing with Whisper...**")
|
|
|
|
| 193 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 194 |
model = whisper.load_model("medium", device=device)
|
| 195 |
result = model.transcribe("temp_audio.wav", word_timestamps=True)
|
|
|
|
| 147 |
st.write("🗣️ **Running Speaker Diarization...**")
|
| 148 |
diarization = None
|
| 149 |
try:
|
| 150 |
+
# Load Config Manually
|
| 151 |
config_path = hf_hub_download(
|
| 152 |
repo_id="pyannote/speaker-diarization-3.1",
|
| 153 |
filename="config.yaml",
|
|
|
|
| 155 |
)
|
| 156 |
pipeline = Pipeline.from_pretrained(config_path)
|
| 157 |
|
| 158 |
+
# Use CPU for stability (avoid CUDA kernel issues on T4 for segmentation)
|
| 159 |
+
# While slower, it guarantees results.
|
| 160 |
+
st.write("⚠️ Using CPU for Diarization (Stability Mode)")
|
| 161 |
+
pipeline.to(torch.device("cpu"))
|
| 162 |
|
| 163 |
+
# Load Audio into Memory
|
| 164 |
+
waveform, sample_rate = torchaudio.load("temp_audio.wav")
|
|
|
|
|
|
|
|
|
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
# Run Pipeline on Tensor directly
|
| 167 |
diarization_output = pipeline({"waveform": waveform, "sample_rate": sample_rate})
|
| 168 |
|
|
|
|
| 176 |
if not hasattr(diarization, "itertracks"):
|
| 177 |
if hasattr(diarization_output, "annotation"):
|
| 178 |
diarization = diarization_output.annotation
|
| 179 |
+
elif hasattr(diarization_output, "get"):
|
| 180 |
+
diarization = diarization_output.get("annotation", diarization_output)
|
| 181 |
|
| 182 |
except Exception as e:
|
| 183 |
st.error(f"Diarization Error: {e}")
|
|
|
|
| 185 |
|
| 186 |
# 2. Whisper Transcription
|
| 187 |
st.write("📝 **Transcribing with Whisper...**")
|
| 188 |
+
# Use GPU for Whisper (it works reliably there)
|
| 189 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 190 |
model = whisper.load_model("medium", device=device)
|
| 191 |
result = model.transcribe("temp_audio.wav", word_timestamps=True)
|