Monstermango commited on
Commit
1ea3709
·
verified ·
1 Parent(s): 9342404

Add speaker diarization app

Browse files
Files changed (4) hide show
  1. README.md +12 -7
  2. app.py +45 -0
  3. packages.txt +1 -0
  4. requirements.txt +1 -0
README.md CHANGED
@@ -1,13 +1,18 @@
1
  ---
2
- title: Diarization
3
- emoji: 👀
4
- colorFrom: green
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.20.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
1
  ---
2
+ title: Speaker Diarization
3
+ emoji: 🎙️
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 5.35.0
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # Speaker Diarization (pyannote)
13
+
14
+ Handy-taugliche Web-App: Audio aufnehmen oder hochladen, erkennt wer wann
15
+ spricht (pyannote/speaker-diarization-community-1).
16
+
17
+ Benötigt ein Space-Secret `HF_TOKEN` mit Lesezugriff auf die gated
18
+ pyannote-Modelle.
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gradio-App für Speaker Diarization mit pyannote (HF Space auf ZeroGPU)."""
2
+ import os
3
+
4
+ import gradio as gr
5
+ import spaces
6
+ import torch
7
+ from pyannote.audio import Pipeline
8
+
9
+ pipeline = Pipeline.from_pretrained(
10
+ "pyannote/speaker-diarization-community-1",
11
+ token=os.environ["HF_TOKEN"],
12
+ )
13
+ pipeline.to(torch.device("cuda"))
14
+
15
+
16
+ @spaces.GPU(duration=120)
17
+ def diarize(audio, num_speakers):
18
+ if audio is None:
19
+ return "Bitte zuerst Audio aufnehmen oder eine Datei hochladen."
20
+ kwargs = {}
21
+ if num_speakers and int(num_speakers) > 0:
22
+ kwargs["num_speakers"] = int(num_speakers)
23
+ output = pipeline(audio, **kwargs)
24
+ diarization = getattr(output, "speaker_diarization", output)
25
+ lines = ["Start Ende Sprecher", "-" * 32]
26
+ for turn, _, speaker in diarization.itertracks(yield_label=True):
27
+ lines.append(f"{turn.start:7.1f}s {turn.end:8.1f}s {speaker}")
28
+ lines.append("")
29
+ lines.append(f"Erkannte Sprecher: {len(diarization.labels())}")
30
+ return "\n".join(lines)
31
+
32
+
33
+ demo = gr.Interface(
34
+ fn=diarize,
35
+ inputs=[
36
+ gr.Audio(sources=["microphone", "upload"], type="filepath", label="Audio"),
37
+ gr.Number(value=0, precision=0, label="Anzahl Sprecher (0 = automatisch)"),
38
+ ],
39
+ outputs=gr.Textbox(label="Ergebnis", lines=14),
40
+ title="Speaker Diarization (pyannote)",
41
+ description="Audio aufnehmen oder hochladen — wer spricht wann?",
42
+ flagging_mode="never",
43
+ )
44
+
45
+ demo.launch()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ pyannote.audio>=4.0