Joffrey Thomas commited on
Commit
351cfea
·
1 Parent(s): 3314796

change app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -522,11 +522,14 @@ def auto_start_recording(session):
522
  if session.is_running:
523
  return get_transcription_html(session.transcription_text, session.status_message, session.current_wpm)
524
 
525
- # Check if we've hit max concurrent sessions
526
  with _sessions_lock:
527
- if len(_active_sessions) >= MAX_CONCURRENT_SESSIONS:
528
- session.status_message = "error"
529
- return get_transcription_html("Server at capacity. Please try again later.", "error", "")
 
 
 
530
 
531
  session.transcription_text = ""
532
  session.word_timestamps = []
@@ -625,18 +628,21 @@ def clear_history(session_id):
625
 
626
  def process_audio(audio, session_id):
627
  """Process incoming audio and queue for streaming."""
628
- # Check capacity - if at max, kill ALL sessions to reset
629
  with _sessions_lock:
630
- at_capacity = len(_active_sessions) >= MAX_CONCURRENT_SESSIONS
 
 
631
 
632
- if at_capacity:
 
 
633
  kill_all_sessions()
634
- # Return error to this user - they can retry immediately
635
  return get_transcription_html(
636
  "Server reset due to capacity. Please click the microphone to restart.",
637
  "error",
638
  ""
639
- ), None # Return None to force fresh session on retry
640
 
641
  # Always ensure we have a valid session first
642
  try:
 
522
  if session.is_running:
523
  return get_transcription_html(session.transcription_text, session.status_message, session.current_wpm)
524
 
525
+ # Check if we've hit max concurrent sessions - kill all if so
526
  with _sessions_lock:
527
+ at_capacity = len(_active_sessions) >= MAX_CONCURRENT_SESSIONS
528
+
529
+ if at_capacity:
530
+ kill_all_sessions()
531
+ session.status_message = "error"
532
+ return get_transcription_html("Server reset due to capacity. Please click the microphone to restart.", "error", "")
533
 
534
  session.transcription_text = ""
535
  session.word_timestamps = []
 
628
 
629
  def process_audio(audio, session_id):
630
  """Process incoming audio and queue for streaming."""
631
+ # Check capacity - if at or above max, kill ALL sessions to reset
632
  with _sessions_lock:
633
+ current_count = len(_active_sessions)
634
+ # Check if THIS user is already active (they can continue)
635
+ is_active_user = session_id and any(s.session_id == session_id for s in _active_sessions.values())
636
 
637
+ # Kill all if at capacity AND this is a new user trying to join
638
+ # OR if we've exceeded capacity (shouldn't happen, but safety check)
639
+ if current_count > MAX_CONCURRENT_SESSIONS or (current_count >= MAX_CONCURRENT_SESSIONS and not is_active_user):
640
  kill_all_sessions()
 
641
  return get_transcription_html(
642
  "Server reset due to capacity. Please click the microphone to restart.",
643
  "error",
644
  ""
645
+ ), None
646
 
647
  # Always ensure we have a valid session first
648
  try: