Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -157,6 +157,18 @@ def stream(session_id: str) -> str:
|
|
| 157 |
while read_slot(session_id) is None and time.time() < deadline:
|
| 158 |
time.sleep(0.05)
|
| 159 |
gen = torch.Generator(device=dev).manual_seed(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
notes, drums = [-1] * 128, [-1]
|
| 161 |
cur_name = model = dstate = history = source = cur_tokens = cur_notes = None
|
| 162 |
emitted = 0
|
|
@@ -283,8 +295,8 @@ def stream(session_id: str) -> str:
|
|
| 283 |
buf_log, buf_t = [], time.time()
|
| 284 |
sleep_for = max(0.0, ahead - buf)
|
| 285 |
cl = read_client_lead(session_id) # client's real Web-Audio queue (ms)
|
| 286 |
-
if cl is not None and cl - buf * 1000.0 >
|
| 287 |
-
sleep_for = max(sleep_for, (cl - buf * 1000.0) / 1000.0 * 0.
|
| 288 |
if sleep_for > 0:
|
| 289 |
time.sleep(min(sleep_for, 0.5))
|
| 290 |
|
|
|
|
| 157 |
while read_slot(session_id) is None and time.time() < deadline:
|
| 158 |
time.sleep(0.05)
|
| 159 |
gen = torch.Generator(device=dev).manual_seed(0)
|
| 160 |
+
try: # one-time GPU warm-up so the first audio frame isn't slow
|
| 161 |
+
style_model.embed("warmup")
|
| 162 |
+
_wd = mrt_base.model.decoder.init_streaming_f(1, dev, dt)
|
| 163 |
+
_wc = mrt_base._conditioning([-1] * mrt_base.num_musiccoca, [-1] * 128, [-1],
|
| 164 |
+
[discretize_cfg(1.6, 0.2, 40), discretize_cfg(2.4, 0.2, 40), discretize_cfg(4.0, 1.0, 8)])
|
| 165 |
+
_ws = mrt_base.model.encode(_wc).to(dt)
|
| 166 |
+
for _ in range(2):
|
| 167 |
+
mrt_base.model.decoder.step_f(_wd, _ws, sampler=make_sampler(1.1, 50, gen),
|
| 168 |
+
temporal_step=mrt_base._temporal_step, depth_step=mrt_base._depth_step)
|
| 169 |
+
print("[warmup] done", flush=True)
|
| 170 |
+
except Exception as _e:
|
| 171 |
+
print("[warmup]", repr(_e), flush=True)
|
| 172 |
notes, drums = [-1] * 128, [-1]
|
| 173 |
cur_name = model = dstate = history = source = cur_tokens = cur_notes = None
|
| 174 |
emitted = 0
|
|
|
|
| 295 |
buf_log, buf_t = [], time.time()
|
| 296 |
sleep_for = max(0.0, ahead - buf)
|
| 297 |
cl = read_client_lead(session_id) # client's real Web-Audio queue (ms)
|
| 298 |
+
if cl is not None and cl - buf * 1000.0 > 200: # only drain a genuinely-deep queue (target+200ms)
|
| 299 |
+
sleep_for = max(sleep_for, min((cl - buf * 1000.0) / 1000.0 * 0.3, 0.2)) # gentle + capped
|
| 300 |
if sleep_for > 0:
|
| 301 |
time.sleep(min(sleep_for, 0.5))
|
| 302 |
|