Spaces:
Runtime error
Runtime error
nithinraok
commited on
Commit
β’
81d7107
1
Parent(s):
80d3696
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from nemo.collections.asr.models import NeuralDiarizer
|
2 |
+
from nemo.collections.asr.parts.utils.speaker_utils import rttm_to_labels
|
3 |
+
import gradio as gr
|
4 |
+
import torch
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
|
9 |
+
model = NeuralDiarizer.from_pretrained("diar_msdd_telephonic").to(device)
|
10 |
+
|
11 |
+
|
12 |
+
def run_diarization(path1):
|
13 |
+
annotation = model(path1)
|
14 |
+
rttm=annotation.to_rttm()
|
15 |
+
df = pd.DataFrame(columns=['start_time', 'end_time', 'speaker'])
|
16 |
+
for idx,line in enumerate(rttm.splitlines()):
|
17 |
+
split = line.split()
|
18 |
+
start_time, end_time, speaker = split[3], split[4], split[7]
|
19 |
+
df.loc[idx] = start_time, end_time, speaker
|
20 |
+
return df
|
21 |
+
|
22 |
+
inputs = [
|
23 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Input Audio"),
|
24 |
+
]
|
25 |
+
output = gr.outputs.Dataframe()
|
26 |
+
|
27 |
+
|
28 |
+
description = (
|
29 |
+
"This demonstration will perform offline speaker diarization on an audio file using nemo"
|
30 |
+
)
|
31 |
+
|
32 |
+
article = (
|
33 |
+
"<p style='text-align: center'>"
|
34 |
+
"<a href='https://huggingface.co/nvidia/speakerverification_en_titanet_large' target='_blank'>ποΈ Learn more about TitaNet model</a> | "
|
35 |
+
"<a href='https://arxiv.org/pdf/2110.04410.pdf' target='_blank'>π TitaNet paper</a> | "
|
36 |
+
"<a href='https://github.com/NVIDIA/NeMo' target='_blank'>π§βπ» Repository</a>"
|
37 |
+
"</p>"
|
38 |
+
)
|
39 |
+
examples = [
|
40 |
+
"data/id10270_5r0dWxy17C8-00001.wav",
|
41 |
+
]
|
42 |
+
|
43 |
+
interface = gr.Interface(
|
44 |
+
fn=run_diarization,
|
45 |
+
inputs=inputs,
|
46 |
+
outputs=output,
|
47 |
+
title="Offline Speaker Diarization with NeMo",
|
48 |
+
description=description,
|
49 |
+
article=article,
|
50 |
+
layout="horizontal",
|
51 |
+
theme="huggingface",
|
52 |
+
allow_flagging=False,
|
53 |
+
live=False,
|
54 |
+
examples=examples,
|
55 |
+
)
|
56 |
+
interface.launch(enable_queue=True)
|