fuze-eletrik commited on
Commit
e45ca08
·
verified ·
1 Parent(s): 002abca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -66,7 +66,7 @@ PAGE = r"""
66
  </header>
67
  <section class="panel">
68
  <div class="section-head"><div class="step">01</div><div><h2>Source & settings</h2><div class="muted">Choose a recording and describe what you want to isolate.</div></div></div>
69
- <div class="file-wrap"><label for="sam-audio-file">Audio file</label><input id="sam-audio-file" type="file" accept="audio/*,.wav,.mp3,.flac,.ogg,.m4a"><div class="muted" style="margin-top:8px">WAV, MP3, FLAC, OGG, or M4A · Recommended: a short clip for the first run</div></div>
70
  <div class="controls">
71
  <div class="field prompt-field"><label for="sam-prompt">What should be isolated?</label><input id="sam-prompt" type="text" value="a person speaking" placeholder="e.g. a person speaking"></div>
72
  <div class="field"><label for="sam-provider">Processing device</label><select id="sam-provider"><option value="auto" selected>Automatic</option><option value="webgpu">GPU · WebGPU</option><option value="wasm">CPU · WASM</option></select></div>
@@ -97,6 +97,7 @@ async () => {
97
  const $ = (id) => root.querySelector("#" + id);
98
  const MODEL_BASE = "https://huggingface.co/matbee/sam-audio-small-onnx/resolve/main";
99
  const CACHE_NAME = "sam-audio-webgpu-models-v1";
 
100
  const MODEL_FILES = {
101
  encoder: "dacvae_encoder.onnx",
102
  decoder: "dacvae_decoder.onnx",
@@ -378,6 +379,9 @@ async () => {
378
  const context = new AudioContextClass();
379
  try {
380
  const decoded = await context.decodeAudioData(bytes.slice(0));
 
 
 
381
  const offline = new OfflineAudioContext(1, Math.ceil(decoded.duration * 48000), 48000);
382
  const source = offline.createBufferSource();
383
  const mono = offline.createBuffer(1, decoded.length, decoded.sampleRate);
@@ -546,7 +550,7 @@ async () => {
546
  if (!Number.isInteger(steps) || steps < 1 || steps > 16) throw new Error("ODE steps must be between 1 and 16.");
547
  const audio = await decodeAudio(file);
548
  const expectedSamples = audio.samples.length;
549
- if (expectedSamples > 48000 * 20) throw new Error("For this first prototype, use audio no longer than 20 seconds.");
550
  setStatus("Loading models for " + deviceLabel + "…");
551
  if (provider === "wasm") {
552
  setLog("CPU mode selected. ONNX Runtime will use WebAssembly in a background worker where supported, keeping the page responsive. This may take longer than GPU inference.");
 
66
  </header>
67
  <section class="panel">
68
  <div class="section-head"><div class="step">01</div><div><h2>Source & settings</h2><div class="muted">Choose a recording and describe what you want to isolate.</div></div></div>
69
+ <div class="file-wrap"><label for="sam-audio-file">Audio file</label><input id="sam-audio-file" type="file" accept=".wav,.mp3,.flac,.ogg,.m4a,audio/wav,audio/mpeg,audio/flac,audio/ogg,audio/mp4"><div class="muted" style="margin-top:8px">WAV, MP3, FLAC, OGG, or M4A · Maximum duration: 2 minutes</div></div>
70
  <div class="controls">
71
  <div class="field prompt-field"><label for="sam-prompt">What should be isolated?</label><input id="sam-prompt" type="text" value="a person speaking" placeholder="e.g. a person speaking"></div>
72
  <div class="field"><label for="sam-provider">Processing device</label><select id="sam-provider"><option value="auto" selected>Automatic</option><option value="webgpu">GPU · WebGPU</option><option value="wasm">CPU · WASM</option></select></div>
 
97
  const $ = (id) => root.querySelector("#" + id);
98
  const MODEL_BASE = "https://huggingface.co/matbee/sam-audio-small-onnx/resolve/main";
99
  const CACHE_NAME = "sam-audio-webgpu-models-v1";
100
+ const MAX_AUDIO_SECONDS = 120;
101
  const MODEL_FILES = {
102
  encoder: "dacvae_encoder.onnx",
103
  decoder: "dacvae_decoder.onnx",
 
379
  const context = new AudioContextClass();
380
  try {
381
  const decoded = await context.decodeAudioData(bytes.slice(0));
382
+ if (decoded.duration > MAX_AUDIO_SECONDS) {
383
+ throw new Error("Audio must be 2 minutes or shorter. Selected file is " + formatDuration(decoded.duration) + ".");
384
+ }
385
  const offline = new OfflineAudioContext(1, Math.ceil(decoded.duration * 48000), 48000);
386
  const source = offline.createBufferSource();
387
  const mono = offline.createBuffer(1, decoded.length, decoded.sampleRate);
 
550
  if (!Number.isInteger(steps) || steps < 1 || steps > 16) throw new Error("ODE steps must be between 1 and 16.");
551
  const audio = await decodeAudio(file);
552
  const expectedSamples = audio.samples.length;
553
+ if (expectedSamples > 48000 * MAX_AUDIO_SECONDS) throw new Error("Audio must be 2 minutes or shorter.");
554
  setStatus("Loading models for " + deviceLabel + "…");
555
  if (provider === "wasm") {
556
  setLog("CPU mode selected. ONNX Runtime will use WebAssembly in a background worker where supported, keeping the page responsive. This may take longer than GPU inference.");