Spaces:
Running on Zero
Running on Zero
Jahmori commited on
Commit ·
1394761
1
Parent(s): b5eaf6c
- changed bucket sync directory name
Browse files- added whisper timestamp chunks for testing
app.py
CHANGED
|
@@ -8,7 +8,6 @@ import gradio as gr
|
|
| 8 |
import spaces
|
| 9 |
from pathlib import Path
|
| 10 |
from speechbrain.inference.separation import SepformerSeparation
|
| 11 |
-
from speechbrain.utils.fetching import FetchConfig
|
| 12 |
from pyannote.audio import Pipeline
|
| 13 |
from pyannote.core import Segment, Annotation
|
| 14 |
from transformers import pipeline, AutoModelForSpeechSeq2Seq, AutoProcessor
|
|
@@ -36,7 +35,6 @@ torch.backends.cudnn.allow_tf32 = False
|
|
| 36 |
|
| 37 |
|
| 38 |
token = os.environ.get("HF_TOKEN")
|
| 39 |
-
# model_path = "/home/user/app/pretrained_models/resepformer-librimix2spk"
|
| 40 |
temp_dir = tempfile.gettempdir()
|
| 41 |
|
| 42 |
|
|
@@ -53,7 +51,8 @@ def process_audio(mixture):
|
|
| 53 |
Path.mkdir(sources,exist_ok=True)
|
| 54 |
|
| 55 |
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
# ---------------------------------------------------------
|
| 59 |
# INITIALIZE MODELS
|
|
@@ -63,7 +62,7 @@ def process_audio(mixture):
|
|
| 63 |
|
| 64 |
#Loading Resepformer Model
|
| 65 |
try:
|
| 66 |
-
separator = SepformerSeparation.from_hparams(source=f"./
|
| 67 |
|
| 68 |
# separator = SepformerSeparation.from_hparams(
|
| 69 |
# source="Jahmori-R/resepformer-librimix2spk",
|
|
@@ -157,33 +156,24 @@ def process_audio(mixture):
|
|
| 157 |
spk_1 = file_paths[0]
|
| 158 |
spk_2 = file_paths[1]
|
| 159 |
|
| 160 |
-
|
| 161 |
for i, path in enumerate(file_paths):
|
| 162 |
speaker_key = f"speaker_{i}"
|
| 163 |
log[speaker_key] = {}
|
| 164 |
|
| 165 |
-
waveform, sample_rate = torchaudio.load(path)
|
| 166 |
-
|
| 167 |
-
print(f"Diarizing {speaker_key}...")
|
| 168 |
|
| 169 |
try:
|
| 170 |
# diarization = diarize({"waveform": waveform, "sample_rate": sample_rate, "speakers": 1})
|
| 171 |
diarization = diarize(path, num_speakers=1)
|
| 172 |
-
|
| 173 |
-
|
| 174 |
timestamps = []
|
| 175 |
|
| 176 |
for turn,_ in diarization.speaker_diarization:
|
| 177 |
-
|
| 178 |
timestamps.append({
|
| 179 |
'start': float(round(turn.start,2)),
|
| 180 |
"end": float(round(turn.end,2)),
|
| 181 |
})
|
| 182 |
-
|
| 183 |
log[speaker_key]["timestamps"] = timestamps
|
| 184 |
-
|
| 185 |
-
# with open("audio.rttm","w") as rttm_file:
|
| 186 |
-
# diarization.speaker_diarization.write_rttm(rttm_file)
|
| 187 |
except Exception as e:
|
| 188 |
print(f"Pyannote error: {e}")
|
| 189 |
raise SystemExit()
|
|
@@ -202,19 +192,32 @@ def process_audio(mixture):
|
|
| 202 |
"return_timestamps": True
|
| 203 |
}
|
| 204 |
|
| 205 |
-
transcriptions ={f"{transcribe(path,generate_kwargs=generate_kwargs)}"}
|
| 206 |
|
| 207 |
|
| 208 |
log[speaker_key]["transcriptions"] = transcriptions
|
| 209 |
|
| 210 |
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
demo = gr.Interface(
|
| 214 |
fn=process_audio,
|
| 215 |
inputs = gr.Audio(type="filepath", label = "Upload Mixture Audio"),
|
| 216 |
-
outputs = [gr.Audio(label="Speaker 1"),gr.Audio(label="Speaker 2"),gr.JSON(label="Logs")],
|
| 217 |
-
title="
|
| 218 |
)
|
| 219 |
|
| 220 |
if __name__ == "__main__":
|
|
|
|
| 8 |
import spaces
|
| 9 |
from pathlib import Path
|
| 10 |
from speechbrain.inference.separation import SepformerSeparation
|
|
|
|
| 11 |
from pyannote.audio import Pipeline
|
| 12 |
from pyannote.core import Segment, Annotation
|
| 13 |
from transformers import pipeline, AutoModelForSpeechSeq2Seq, AutoProcessor
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
token = os.environ.get("HF_TOKEN")
|
|
|
|
| 38 |
temp_dir = tempfile.gettempdir()
|
| 39 |
|
| 40 |
|
|
|
|
| 51 |
Path.mkdir(sources,exist_ok=True)
|
| 52 |
|
| 53 |
|
| 54 |
+
# Downloads RE-SepFormer model from huggingface buckets to space local directory
|
| 55 |
+
sync_bucket("hf://buckets/Jahmori-R/PureVoiceAISpace-storage","./models" )
|
| 56 |
|
| 57 |
# ---------------------------------------------------------
|
| 58 |
# INITIALIZE MODELS
|
|
|
|
| 62 |
|
| 63 |
#Loading Resepformer Model
|
| 64 |
try:
|
| 65 |
+
separator = SepformerSeparation.from_hparams(source=f"./models/resepformer-librimix2spk",hparams_file="hyperparams.yaml",run_opts={"device": "cuda"})
|
| 66 |
|
| 67 |
# separator = SepformerSeparation.from_hparams(
|
| 68 |
# source="Jahmori-R/resepformer-librimix2spk",
|
|
|
|
| 156 |
spk_1 = file_paths[0]
|
| 157 |
spk_2 = file_paths[1]
|
| 158 |
|
| 159 |
+
full_timestamp = []
|
| 160 |
for i, path in enumerate(file_paths):
|
| 161 |
speaker_key = f"speaker_{i}"
|
| 162 |
log[speaker_key] = {}
|
| 163 |
|
| 164 |
+
# waveform, sample_rate = torchaudio.load(path)
|
|
|
|
|
|
|
| 165 |
|
| 166 |
try:
|
| 167 |
# diarization = diarize({"waveform": waveform, "sample_rate": sample_rate, "speakers": 1})
|
| 168 |
diarization = diarize(path, num_speakers=1)
|
|
|
|
|
|
|
| 169 |
timestamps = []
|
| 170 |
|
| 171 |
for turn,_ in diarization.speaker_diarization:
|
|
|
|
| 172 |
timestamps.append({
|
| 173 |
'start': float(round(turn.start,2)),
|
| 174 |
"end": float(round(turn.end,2)),
|
| 175 |
})
|
|
|
|
| 176 |
log[speaker_key]["timestamps"] = timestamps
|
|
|
|
|
|
|
|
|
|
| 177 |
except Exception as e:
|
| 178 |
print(f"Pyannote error: {e}")
|
| 179 |
raise SystemExit()
|
|
|
|
| 192 |
"return_timestamps": True
|
| 193 |
}
|
| 194 |
|
| 195 |
+
transcriptions ={f"{transcribe(path,generate_kwargs=generate_kwargs,return_timestamps=True)}"}
|
| 196 |
|
| 197 |
|
| 198 |
log[speaker_key]["transcriptions"] = transcriptions
|
| 199 |
|
| 200 |
|
| 201 |
+
segments = transcriptions["chunks"]
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
for segment in segments:
|
| 205 |
+
full_timestamp.append({
|
| 206 |
+
"segment":segment
|
| 207 |
+
})
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
return spk_1, spk_2, log, full_timestamp
|
| 215 |
|
| 216 |
demo = gr.Interface(
|
| 217 |
fn=process_audio,
|
| 218 |
inputs = gr.Audio(type="filepath", label = "Upload Mixture Audio"),
|
| 219 |
+
outputs = [gr.Audio(label="Speaker 1"),gr.Audio(label="Speaker 2"),gr.JSON(label="Logs"),gr.JSON(label="Whisper Logs")],
|
| 220 |
+
title="PureVoiceAI Project 2026", description = "Source separated end-to-end transcription processing pipeline"
|
| 221 |
)
|
| 222 |
|
| 223 |
if __name__ == "__main__":
|