Upload app.py with huggingface_hub
Browse files93 unmodified lines94959697989918 unmodified lines11811912012112212317 unmodified lines14114214314414514610 unmodified lines15715815916016116293 unmodified lines"onsetmode": bool(body.get("onsetmode", False)),"reset": int(body.get("reset", 0)),"seed": int(body.get("seed", 0)),})return {"ok": True}18 unmodified linesreturn {"ok": True}@app.api(name="stream")@spaces.GPU(duration=90)def stream(session_id: str) -> str:17 unmodified linescur_reset = cur_seed = 0force_reenc = Falsetxt_cache, aud_cache = {}, {}while time.time() - t0 < 55.0:c = read_slot(session_id)if c is None:10 unmodified linesif seed != cur_seed:cur_seed = seedgen = torch.Generator(device=dev).manual_seed(seed)toks = []for _ in range(10): # per-frame slot read -> steering applies ~instantlyc = read_slot(session_id) or c93 unmodified lines94959697989910018 unmodified lines11912012112212312412512612712812913017 unmodified lines14814915015115215315410 unmodified lines16516616716816917017117217317417517617717817918018118218393 unmodified lines"onsetmode": bool(body.get("onsetmode", False)),"reset": int(body.get("reset", 0)),"seed": int(body.get("seed", 0)),"bank_op": body.get("bank_op", prev.get("bank_op")),})return {"ok": True}18 unmodified linesreturn {"ok": True}@app.get("/banks")async def banks(session_id: str = ""):sid = os.path.basename(session_id)return {"bankStatus": [os.path.exists(os.path.join(SESSION_DIR, f"{sid}_bank{i}.pt")) for i in range(3)]}@app.api(name="stream")@spaces.GPU(duration=90)def stream(session_id: str) -> str:17 unmodified linescur_reset = cur_seed = 0force_reenc = Falsetxt_cache, aud_cache = {}, {}cur_bank_ver = 0while time.time() - t0 < 55.0:c = read_slot(session_id)if c is None:10 unmodified linesif seed != cur_seed:cur_seed = seedgen = torch.Generator(device=dev).manual_seed(seed)bop = c.get("bank_op")if bop and int(bop.get("ver", 0)) != cur_bank_ver: # save/recall generation statecur_bank_ver = int(bop.get("ver", 0))bpath = os.path.join(SESSION_DIR, f"{os.path.basename(session_id)}_bank{int(bop.get('idx', 0))}.pt")try:if bop.get("action") == "save":torch.save({"dstate": dstate, "history": history, "emitted": emitted}, bpath)elif bop.get("action") == "load" and os.path.exists(bpath):d = torch.load(bpath, map_location=dev)dstate, history, emitted = d["dstate"], d["history"].to(dev), int(d["emitted"])source, cur_sig = None, Noneexcept Exception as e:print("[bank] error:", repr(e), flush=True)toks = []for _ in range(10): # per-frame slot read -> steering applies ~instantlyc = read_slot(session_id) or c
app.py+21