Spaces:
Runtime error
Runtime error
Update transcription_diarization.py
Browse files- transcription_diarization.py +13 -0
transcription_diarization.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import torch
|
|
|
|
| 3 |
import math
|
| 4 |
from moviepy.editor import VideoFileClip
|
| 5 |
from pyannote.audio import Pipeline
|
|
@@ -141,14 +142,26 @@ def process_video(video_path, diarization_access_token, language):
|
|
| 141 |
diarization = pipeline(audio_path)
|
| 142 |
print("Diarization complete.")
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
print("Performing transcription...")
|
| 145 |
transcription, chunks = transcribe_audio(audio_path, language)
|
| 146 |
print("Transcription complete.")
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
combined_srt_path = f"{base_name}_combined.srt"
|
| 149 |
create_combined_srt(chunks, diarization, combined_srt_path)
|
| 150 |
print(f"Combined SRT file created and saved to {combined_srt_path}")
|
| 151 |
|
| 152 |
os.remove(audio_path)
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
return combined_srt_path
|
|
|
|
| 1 |
import os
|
| 2 |
import torch
|
| 3 |
+
import gc
|
| 4 |
import math
|
| 5 |
from moviepy.editor import VideoFileClip
|
| 6 |
from pyannote.audio import Pipeline
|
|
|
|
| 142 |
diarization = pipeline(audio_path)
|
| 143 |
print("Diarization complete.")
|
| 144 |
|
| 145 |
+
# Clear GPU memory after diarization
|
| 146 |
+
torch.cuda.empty_cache()
|
| 147 |
+
gc.collect()
|
| 148 |
+
|
| 149 |
print("Performing transcription...")
|
| 150 |
transcription, chunks = transcribe_audio(audio_path, language)
|
| 151 |
print("Transcription complete.")
|
| 152 |
|
| 153 |
+
# Clear GPU memory after transcription
|
| 154 |
+
torch.cuda.empty_cache()
|
| 155 |
+
gc.collect()
|
| 156 |
+
|
| 157 |
combined_srt_path = f"{base_name}_combined.srt"
|
| 158 |
create_combined_srt(chunks, diarization, combined_srt_path)
|
| 159 |
print(f"Combined SRT file created and saved to {combined_srt_path}")
|
| 160 |
|
| 161 |
os.remove(audio_path)
|
| 162 |
|
| 163 |
+
# Final GPU memory clear
|
| 164 |
+
torch.cuda.empty_cache()
|
| 165 |
+
gc.collect()
|
| 166 |
+
|
| 167 |
return combined_srt_path
|