karl4th commited on
Commit
2600a23
·
verified ·
1 Parent(s): 221267c

Kezek demo on ZeroGPU

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ examples/conv_31bedfc99b53_1.wav filter=lfs diff=lfs merge=lfs -text
37
+ examples/conv_5a798c657bb0_1.wav filter=lfs diff=lfs merge=lfs -text
38
+ examples/conv_e11edcca8521_2.wav filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,27 @@
1
  ---
2
  title: Kezek
3
- emoji: 📊
4
- colorFrom: yellow
5
- colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 6.32.0
8
- python_version: '3.12'
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: Kezek
3
+ emoji: 🎙️
4
+ colorFrom: indigo
5
+ colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 5.49.1
8
+ python_version: "3.10"
9
  app_file: app.py
10
  pinned: false
11
+ license: mit
12
+ models:
13
+ - manifestro/kezek-v1
14
+ short_description: Two people, one mono recording → one track per person
15
  ---
16
 
17
+ # Kezek demo
18
+
19
+ Upload a mono recording of exactly two people and get one track per person, with the original length and timing.
20
+
21
+ - Code: https://github.com/Manifestro/kezek (MIT)
22
+ - Weights: https://huggingface.co/manifestro/kezek-v1 (Apache-2.0)
23
+ - Install: `pip install kezek`
24
+
25
+ This Space runs on ZeroGPU and processes up to 10 minutes per request.
26
+
27
+ The examples are 30 s excerpts from the Open Yap 1K public sample (CC BY 4.0, The Agentic Data Company), shown with the company's permission.
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Kezek demo: a mono recording of two people -> one track per person."""
2
+
3
+ import json
4
+ import os
5
+
6
+ try:
7
+ import spaces # ZeroGPU: a GPU is attached only while a decorated call runs
8
+ ZERO = bool(os.environ.get("SPACES_ZERO_GPU"))
9
+ except ImportError:
10
+ spaces, ZERO = None, False
11
+
12
+ import gradio as gr
13
+ import numpy as np
14
+ import torch
15
+
16
+ from kezek import Kezek
17
+
18
+ SR = 16_000
19
+ DEV = "cuda" if ZERO or torch.cuda.is_available() else "cpu"
20
+ MAX_S = float(os.environ.get("KEZEK_MAX_S", "600" if DEV == "cuda" else "60"))
21
+ torch.set_num_threads(max(1, os.cpu_count() or 1))
22
+ KZ = Kezek.from_pretrained(dev=DEV)
23
+
24
+ EXAMPLES = [[f"examples/{f}"] for f in sorted(os.listdir("examples")) if f.endswith(".wav")]
25
+
26
+
27
+ def to16k_mono(sr, x):
28
+ x = np.asarray(x)
29
+ if np.issubdtype(x.dtype, np.integer):
30
+ x = x.astype(np.float32) / np.iinfo(x.dtype).max
31
+ x = x.astype(np.float32)
32
+ if x.ndim == 2:
33
+ x = x.mean(1)
34
+ if sr != SR:
35
+ import torchaudio.functional as AF
36
+
37
+ x = AF.resample(torch.from_numpy(x), sr, SR).numpy()
38
+ return x
39
+
40
+
41
+ def _gpu(fn):
42
+ return spaces.GPU(duration=60)(fn) if ZERO else fn
43
+
44
+
45
+ @_gpu
46
+ def separate(audio):
47
+ if audio is None:
48
+ raise gr.Error("Upload or record a conversation of two people.")
49
+ sr, x = audio
50
+ x = to16k_mono(sr, x)
51
+ note = ""
52
+ if len(x) > MAX_S * SR:
53
+ x = x[: int(MAX_S * SR)]
54
+ note = f"Only the first {MAX_S:.0f} s were processed on this {DEV.upper()} demo. "
55
+ peak = max(float(np.abs(x).max()), 1e-4)
56
+ y, act, info = KZ((x * 0.9 / peak).astype(np.float32))
57
+ y = y * peak / 0.9
58
+ summary = (f"{note}{info['seconds']:.1f} s: person A speaks {info['speech_s']['A']:.1f} s, "
59
+ f"person B {info['speech_s']['B']:.1f} s, both at once {info['overlap_s']:.1f} s.")
60
+ return (SR, y[0].astype(np.float32)), (SR, y[1].astype(np.float32)), summary, json.dumps(info, indent=1)
61
+
62
+
63
+ DESC = """
64
+ **Kezek** turns a mono recording of exactly two people into one track per person, with the original length and
65
+ timing. Overlaps and short replies ("yeah", "mm-hm") stay on the track of the person who said them, and the two
66
+ tracks always sum to the input.
67
+
68
+ [Code](https://github.com/Manifestro/kezek) · [Weights](https://huggingface.co/manifestro/kezek-v1) · `pip install kezek`
69
+ """
70
+
71
+ with gr.Blocks(title="Kezek") as demo:
72
+ gr.Markdown("# Kezek: two people, one mono recording → one track each")
73
+ gr.Markdown(DESC)
74
+ with gr.Row():
75
+ with gr.Column():
76
+ inp = gr.Audio(label="Conversation (mono, two people)", type="numpy", sources=["upload", "microphone"])
77
+ btn = gr.Button("Separate", variant="primary")
78
+ gr.Markdown(f"Runs on {DEV.upper()}; up to {MAX_S:.0f} s per request.")
79
+ with gr.Column():
80
+ out_a = gr.Audio(label="Person A", type="numpy")
81
+ out_b = gr.Audio(label="Person B", type="numpy")
82
+ summ = gr.Markdown()
83
+ with gr.Accordion("Details", open=False):
84
+ det = gr.Code(language="json")
85
+ btn.click(separate, inputs=inp, outputs=[out_a, out_b, summ, det])
86
+ if EXAMPLES:
87
+ gr.Examples(EXAMPLES, inputs=inp, label="Examples: Open Yap 1K public sample (CC BY 4.0, The Agentic Data Company)")
88
+ gr.Markdown("Examples are 30 s excerpts of Open Yap 1K conversations (public sample, CC BY 4.0, "
89
+ "© The Agentic Data Company), shown with the company's permission. They were not used in training. "
90
+ "Use Kezek only on recordings you have the right to process; do not use it to identify speakers "
91
+ "or clone voices.")
92
+
93
+ demo.queue(max_size=8).launch()
examples/conv_31bedfc99b53_1.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef624f4c9c1ba08c17b631daff2d386e190fe26b66b88aabddbe66cf529f1559
3
+ size 960044
examples/conv_5a798c657bb0_1.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25d1587da67b2bb22dca248bde34ea3840fe3478cd9eb7780b86684a6c702782
3
+ size 960044
examples/conv_e11edcca8521_2.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a5f71193f06cb911add6ac5784a6c5bb5e14084c3d311a339dc21d8f60c46a8
3
+ size 960044
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch==2.5.1
2
+ torchaudio==2.5.1
3
+ numpy<2.1
4
+ soundfile
5
+ huggingface_hub
6
+ kezek==1.0.1