ACloudCenter commited on
Commit
9ae9cad
·
1 Parent(s): d5cf69f

Fix tuple stream error

Browse files
Files changed (1) hide show
  1. app.py +31 -13
app.py CHANGED
@@ -332,6 +332,8 @@ def create_demo_interface():
332
  speakers = speakers_and_params[:4]
333
  cfg_scale_val = speakers_and_params[4]
334
  current_log = ""
 
 
335
 
336
  # Stream updates from the Modal function
337
  for update in remote_generate_function.remote_gen(
@@ -347,21 +349,37 @@ def create_demo_interface():
347
  if not update:
348
  continue
349
 
350
- audio_payload = update.get("audio")
351
- progress_pct = update.get("pct", 0)
352
- stage_label = update.get("stage", "").replace("_", " ").title() or "Status"
353
- status_line = update.get("status") or "Processing…"
354
- current_log = update.get("log", current_log)
 
355
 
356
- status_formatted = f"**{stage_label}**\n{status_line}"
357
- audio_output = audio_payload if audio_payload is not None else gr.update()
358
 
359
- yield (
360
- audio_output,
361
- current_log,
362
- status_formatted,
363
- gr.update(value=progress_pct),
364
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  except Exception as e:
366
  tb = traceback.format_exc()
367
  print(f"Error calling Modal: {e}")
 
332
  speakers = speakers_and_params[:4]
333
  cfg_scale_val = speakers_and_params[4]
334
  current_log = ""
335
+ last_pct = 0
336
+ last_status = "**Connecting**\nRequesting GPU resources…"
337
 
338
  # Stream updates from the Modal function
339
  for update in remote_generate_function.remote_gen(
 
349
  if not update:
350
  continue
351
 
352
+ if isinstance(update, dict):
353
+ audio_payload = update.get("audio")
354
+ progress_pct = update.get("pct", last_pct)
355
+ stage_label = update.get("stage", "").replace("_", " ").title() or "Status"
356
+ status_line = update.get("status") or "Processing…"
357
+ current_log = update.get("log", current_log)
358
 
359
+ status_formatted = f"**{stage_label}**\n{status_line}"
360
+ audio_output = audio_payload if audio_payload is not None else gr.update()
361
 
362
+ last_pct = progress_pct
363
+ last_status = status_formatted
364
+
365
+ yield (
366
+ audio_output,
367
+ current_log,
368
+ status_formatted,
369
+ gr.update(value=progress_pct),
370
+ )
371
+ else:
372
+ # Backwards compatibility: older backend returns (audio, log)
373
+ audio_payload, log_text = update if isinstance(update, (tuple, list)) else (None, str(update))
374
+ if log_text:
375
+ current_log = log_text
376
+ audio_output = audio_payload if audio_payload is not None else gr.update()
377
+ yield (
378
+ audio_output,
379
+ current_log,
380
+ last_status,
381
+ gr.update(value=last_pct),
382
+ )
383
  except Exception as e:
384
  tb = traceback.format_exc()
385
  print(f"Error calling Modal: {e}")