multimodalart HF Staff commited on
Commit
a0edc57
·
verified ·
1 Parent(s): 1cc4b5c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -180,6 +180,7 @@ def stream(session_id: str) -> str:
180
  cur_reset = cur_seed = 0
181
  force_reenc = False
182
  txt_cache, aud_cache = {}, {}
 
183
  cur_bank_ver = 0
184
  while time.time() - t0 < 55.0:
185
  c = read_slot(session_id)
@@ -212,7 +213,7 @@ def stream(session_id: str) -> str:
212
  print("[bank] error:", repr(e), flush=True)
213
  toks = []
214
  gen_t = time.time()
215
- for _ in range(10): # per-frame slot read -> steering applies ~instantly
216
  c = read_slot(session_id) or c
217
  prompts = c.get("prompts") or ["instrumental music"]
218
  weights = c.get("weights") or [1.0] * len(prompts)
@@ -279,7 +280,7 @@ def stream(session_id: str) -> str:
279
  temporal_step=model._temporal_step, depth_step=model._depth_step))
280
  history = torch.cat([history] + toks, dim=1)
281
  audio, emitted = model._decode_stream(history, emitted)
282
- frame_ms = (time.time() - gen_t) * 1000.0 / 10.0 # real per-frame inference time
283
  if audio.shape[1] > 0:
284
  b64 = base64.b64encode(_float_to_int16(audio[0].float().cpu().numpy()).astype("<i2").tobytes()).decode("ascii")
285
  yield f"{frame_ms:.1f}|{b64}"
 
180
  cur_reset = cur_seed = 0
181
  force_reenc = False
182
  txt_cache, aud_cache = {}, {}
183
+ CHUNK = 5 # frames per yield (smaller = finer delivery, lower buffer floor)
184
  cur_bank_ver = 0
185
  while time.time() - t0 < 55.0:
186
  c = read_slot(session_id)
 
213
  print("[bank] error:", repr(e), flush=True)
214
  toks = []
215
  gen_t = time.time()
216
+ for _ in range(CHUNK): # per-frame slot read -> steering applies ~instantly
217
  c = read_slot(session_id) or c
218
  prompts = c.get("prompts") or ["instrumental music"]
219
  weights = c.get("weights") or [1.0] * len(prompts)
 
280
  temporal_step=model._temporal_step, depth_step=model._depth_step))
281
  history = torch.cat([history] + toks, dim=1)
282
  audio, emitted = model._decode_stream(history, emitted)
283
+ frame_ms = (time.time() - gen_t) * 1000.0 / CHUNK # real per-frame inference time
284
  if audio.shape[1] > 0:
285
  b64 = base64.b64encode(_float_to_int16(audio[0].float().cpu().numpy()).astype("<i2").tobytes()).decode("ascii")
286
  yield f"{frame_ms:.1f}|{b64}"