multimodalart HF Staff commited on
Commit
e32d01d
·
verified ·
1 Parent(s): 728e2fc

Stop after completed reply; GPU budget guard

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -585,7 +585,7 @@ def _duration(text="", audio=None, voice=None, tail_seconds=20, *args, **kwargs)
585
  except Exception:
586
  secs = MAX_INPUT_SECONDS
587
  reminder = MAX_REMINDER_SECONDS if text and parse_timer_request(text) else 0
588
- return int(min(240, 45 + 0.6 * (secs + int(tail_seconds) + reminder)))
589
 
590
 
591
  def _fmt(t):
@@ -615,6 +615,7 @@ def converse(text: str = "", audio: str | None = None, voice: str | None = None,
615
  raise gr.Error("Type a message or record/upload some speech first.")
616
  voice_path = voice or DEFAULT_VOICE
617
  started = time.perf_counter()
 
618
 
619
  units = []
620
  if text:
@@ -640,7 +641,6 @@ def converse(text: str = "", audio: str | None = None, voice: str | None = None,
640
  query_reset = False
641
  pending = [] # dicts: ready_unit, event, label
642
  deadline = len(units) + tail
643
- quiet = 0
644
  spoke = False
645
  u = 0
646
  while u < min(deadline, MAX_UNITS):
@@ -722,10 +722,13 @@ def converse(text: str = "", audio: str | None = None, voice: str | None = None,
722
  busy = bool(pending) or native_speaking or awaiting_ack or not speech_complete
723
  if pending:
724
  deadline = max(deadline, max(p["ready_unit"] for p in pending) + tail)
725
- if u >= len(units) - 1:
726
- quiet = 0 if (busy or action != "listen") else quiet + 1
727
- if spoke and quiet >= 4 and not pending:
728
  break
 
 
 
729
  u += 1
730
 
731
  if current_line.strip():
 
585
  except Exception:
586
  secs = MAX_INPUT_SECONDS
587
  reminder = MAX_REMINDER_SECONDS if text and parse_timer_request(text) else 0
588
+ return int(min(180, 20 + 1.0 * (secs + int(tail_seconds)) + 0.4 * reminder))
589
 
590
 
591
  def _fmt(t):
 
615
  raise gr.Error("Type a message or record/upload some speech first.")
616
  voice_path = voice or DEFAULT_VOICE
617
  started = time.perf_counter()
618
+ budget = _duration(text, audio, voice, tail_seconds)
619
 
620
  units = []
621
  if text:
 
641
  query_reset = False
642
  pending = [] # dicts: ready_unit, event, label
643
  deadline = len(units) + tail
 
644
  spoke = False
645
  u = 0
646
  while u < min(deadline, MAX_UNITS):
 
722
  busy = bool(pending) or native_speaking or awaiting_ack or not speech_complete
723
  if pending:
724
  deadline = max(deadline, max(p["ready_unit"] for p in pending) + tail)
725
+ if u >= len(units) - 1 and spoke and not busy:
726
+ # the reply finished and nothing is pending: end the turn (prevents re-answering)
727
+ if action == "listen" or result["end_of_turn"]:
728
  break
729
+ if time.perf_counter() - started > budget - 8: # stay inside the ZeroGPU reservation
730
+ log.append("*(stopped early to stay within the GPU time budget)*")
731
+ break
732
  u += 1
733
 
734
  if current_line.strip():