ALWOAL commited on
Commit
caa467a
·
verified ·
1 Parent(s): c1b448c

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-314.pyc +0 -0
  2. app.py +10 -4
__pycache__/app.cpython-314.pyc CHANGED
Binary files a/__pycache__/app.cpython-314.pyc and b/__pycache__/app.cpython-314.pyc differ
 
app.py CHANGED
@@ -45,6 +45,8 @@ def _encode_decode(audio_path: str, levels: tuple) -> dict:
45
  """Reconstruct `audio_path` once per weight-quantization level, scoring each result."""
46
  ref, sr = core.load_audio(audio_path, SAMPLE_RATE, MAX_SECONDS)
47
  sig = torch.from_numpy(ref).unsqueeze(0).cuda()
 
 
48
  rows, reconstructed = [], {}
49
  for level in levels:
50
  codec.load_state_dict(BASE_STATE if level == "fp32" else core.quantize_state(BASE_STATE, level))
@@ -60,6 +62,10 @@ def _encode_decode(audio_path: str, levels: tuple) -> dict:
60
  return {"input": (sr, ref), "rows": rows, "audio": reconstructed}
61
 
62
 
 
 
 
 
63
  _CACHE: dict[str, dict] = {}
64
 
65
 
@@ -99,14 +105,14 @@ def playground(audio_path: str, level: str):
99
  return (
100
  rec,
101
  core.spectrogram_figure(result["input"][1], rec[1], SAMPLE_RATE, level),
102
- [result["rows"][0]],
103
  )
104
 
105
 
106
  def benchmark(audio_path: str):
107
  """Score every quantization level on one input: metrics table plus summary chart."""
108
  result = run(audio_path, QUANT_LEVELS)
109
- return result["rows"], core.metrics_figure(result["rows"])
110
 
111
 
112
  HEADER = f"""# ⚡ FocalCodec 12.5 Hz — weight quantization lab
@@ -123,7 +129,7 @@ The bitrate never changes — **{core.BITRATE_KBPS:g} kbps** (12.5 tokens/s × 1
123
  FOOTER = """Audio examples from the [FocalCodec repository](https://github.com/lucadellalib/focalcodec)
124
  (LibriSpeech, VoiceBank, MagicData). Model and method by Luca Della Libera et al., Apache-2.0."""
125
 
126
- with gr.Blocks(title="FocalCodec quantization lab", theme=gr.themes.Soft()) as demo:
127
  gr.Markdown(HEADER)
128
 
129
  with gr.Tab("Compare"):
@@ -190,4 +196,4 @@ with gr.Blocks(title="FocalCodec quantization lab", theme=gr.themes.Soft()) as d
190
 
191
  gr.Markdown(FOOTER)
192
 
193
- demo.launch(mcp_server=True)
 
45
  """Reconstruct `audio_path` once per weight-quantization level, scoring each result."""
46
  ref, sr = core.load_audio(audio_path, SAMPLE_RATE, MAX_SECONDS)
47
  sig = torch.from_numpy(ref).unsqueeze(0).cuda()
48
+ with torch.inference_mode(): # untimed warmup so the first row's RTF isn't inflated
49
+ codec.sig_to_sig(sig)
50
  rows, reconstructed = [], {}
51
  for level in levels:
52
  codec.load_state_dict(BASE_STATE if level == "fp32" else core.quantize_state(BASE_STATE, level))
 
62
  return {"input": (sr, ref), "rows": rows, "audio": reconstructed}
63
 
64
 
65
+ def _table(rows: list[dict]) -> list[list]:
66
+ return [[row[header] for header in HEADERS] for row in rows]
67
+
68
+
69
  _CACHE: dict[str, dict] = {}
70
 
71
 
 
105
  return (
106
  rec,
107
  core.spectrogram_figure(result["input"][1], rec[1], SAMPLE_RATE, level),
108
+ _table(result["rows"]),
109
  )
110
 
111
 
112
  def benchmark(audio_path: str):
113
  """Score every quantization level on one input: metrics table plus summary chart."""
114
  result = run(audio_path, QUANT_LEVELS)
115
+ return _table(result["rows"]), core.metrics_figure(result["rows"])
116
 
117
 
118
  HEADER = f"""# ⚡ FocalCodec 12.5 Hz — weight quantization lab
 
129
  FOOTER = """Audio examples from the [FocalCodec repository](https://github.com/lucadellalib/focalcodec)
130
  (LibriSpeech, VoiceBank, MagicData). Model and method by Luca Della Libera et al., Apache-2.0."""
131
 
132
+ with gr.Blocks(title="FocalCodec quantization lab") as demo:
133
  gr.Markdown(HEADER)
134
 
135
  with gr.Tab("Compare"):
 
196
 
197
  gr.Markdown(FOOTER)
198
 
199
+ demo.launch(mcp_server=True, theme=gr.themes.Soft())