multimodalart HF Staff commited on
Commit
ae7213e
·
verified ·
1 Parent(s): f78534d

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -363,9 +363,13 @@ async def audio_ws(websocket: WebSocket, session_id: str = ""):
363
  audio_q, stop_ev = sess["audio"], sess["stop"]
364
  loop = asyncio.get_event_loop()
365
  try:
366
- while not stop_ev.is_set():
 
 
 
 
367
  try:
368
- ab, fm = await loop.run_in_executor(None, lambda: audio_q.get(timeout=1.0))
369
  except Exception:
370
  continue
371
  await websocket.send_bytes(struct.pack("<f", fm) + ab)
 
363
  audio_q, stop_ev = sess["audio"], sess["stop"]
364
  loop = asyncio.get_event_loop()
365
  try:
366
+ while True:
367
+ if stop_ev.is_set():
368
+ try: await websocket.send_json({"type": "ended"}) # worker ended (quota/grant) -> tell client
369
+ except Exception: pass
370
+ break
371
  try:
372
+ ab, fm = await loop.run_in_executor(None, lambda: audio_q.get(timeout=0.5))
373
  except Exception:
374
  continue
375
  await websocket.send_bytes(struct.pack("<f", fm) + ab)