multimodalart HF Staff commited on
Commit
0cfac40
·
verified ·
1 Parent(s): 22d199e

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -179,6 +179,7 @@ def stream(session_id: str) -> str:
179
  except Exception as e:
180
  print("[bank] error:", repr(e), flush=True)
181
  toks = []
 
182
  for _ in range(10): # per-frame slot read -> steering applies ~instantly
183
  c = read_slot(session_id) or c
184
  prompts = c.get("prompts") or ["instrumental music"]
@@ -243,8 +244,10 @@ def stream(session_id: str) -> str:
243
  temporal_step=model._temporal_step, depth_step=model._depth_step))
244
  history = torch.cat([history] + toks, dim=1)
245
  audio, emitted = model._decode_stream(history, emitted)
 
246
  if audio.shape[1] > 0:
247
- yield base64.b64encode(_float_to_int16(audio[0].float().cpu().numpy()).astype("<i2").tobytes()).decode("ascii")
 
248
  buf = (0.3, 0.55, 0.85)[max(0, min(2, int(c.get("buffer", 0))))]
249
  ahead = (emitted * FRAME_SAMPLES / SR) - (time.time() - t0)
250
  buf_log.append(ahead)
 
179
  except Exception as e:
180
  print("[bank] error:", repr(e), flush=True)
181
  toks = []
182
+ gen_t = time.time()
183
  for _ in range(10): # per-frame slot read -> steering applies ~instantly
184
  c = read_slot(session_id) or c
185
  prompts = c.get("prompts") or ["instrumental music"]
 
244
  temporal_step=model._temporal_step, depth_step=model._depth_step))
245
  history = torch.cat([history] + toks, dim=1)
246
  audio, emitted = model._decode_stream(history, emitted)
247
+ frame_ms = (time.time() - gen_t) * 1000.0 / 10.0 # real per-frame inference time
248
  if audio.shape[1] > 0:
249
+ b64 = base64.b64encode(_float_to_int16(audio[0].float().cpu().numpy()).astype("<i2").tobytes()).decode("ascii")
250
+ yield f"{frame_ms:.1f}|{b64}"
251
  buf = (0.3, 0.55, 0.85)[max(0, min(2, int(c.get("buffer", 0))))]
252
  ahead = (emitted * FRAME_SAMPLES / SR) - (time.time() - t0)
253
  buf_log.append(ahead)