Joffrey Thomas commited on
Commit
5e50efb
·
1 Parent(s): 42230e1

update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -298,6 +298,13 @@ def start_websocket(session):
298
  pass
299
 
300
 
 
 
 
 
 
 
 
301
  def auto_start_recording(session):
302
  """Automatically start the transcription service when audio begins."""
303
  # Protect against startup races: Gradio can call `process_audio` concurrently.
@@ -319,6 +326,7 @@ def auto_start_recording(session):
319
 
320
  def clear_history(session):
321
  """Stop the websocket connection and clear all history."""
 
322
  session.is_running = False
323
  session.last_audio_time = None
324
 
@@ -340,6 +348,7 @@ def clear_history(session):
340
 
341
  def process_audio(audio, session):
342
  """Process incoming audio and queue for streaming."""
 
343
  try:
344
  # Quick return if audio is None
345
  if audio is None:
 
298
  pass
299
 
300
 
301
+ def ensure_session(session):
302
+ """Ensure we have a valid UserSession instance."""
303
+ if session is None or callable(session):
304
+ return UserSession()
305
+ return session
306
+
307
+
308
  def auto_start_recording(session):
309
  """Automatically start the transcription service when audio begins."""
310
  # Protect against startup races: Gradio can call `process_audio` concurrently.
 
326
 
327
  def clear_history(session):
328
  """Stop the websocket connection and clear all history."""
329
+ session = ensure_session(session)
330
  session.is_running = False
331
  session.last_audio_time = None
332
 
 
348
 
349
  def process_audio(audio, session):
350
  """Process incoming audio and queue for streaming."""
351
+ session = ensure_session(session)
352
  try:
353
  # Quick return if audio is None
354
  if audio is None: