multimodalart HF Staff commited on
Commit
cb99636
·
verified ·
1 Parent(s): 8d25e7a

Fix Gradio 6 Audio/Blocks params, harden duration estimator

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -148,13 +148,16 @@ def _score_to_ui(notes: list[dict]) -> str:
148
  def _estimate_duration(task: str, *args, **kwargs) -> int:
149
  """Callable @spaces.GPU duration: reserve what this request needs, not a blanket worst case.
150
 
151
- Receives the same inputs as the decorated function, keyword-first: task is
152
- inserted by each handler so we don't depend on positional layout. Calibrated
153
- on an RTX PRO 6000: ~18 s cold-start overhead + flow_steps × ~55 ms per
154
- generated patch + decode time.
 
155
  """
156
- text = kwargs.get("text") or kwargs.get("score_text") or ""
157
  flow_steps = kwargs.get("flow_steps")
 
 
158
  steps = int(flow_steps) if flow_steps else 10
159
  steps = max(steps, 2)
160
  if task == "svs" and isinstance(text, str) and "|" in text:
@@ -342,7 +345,7 @@ def svs_examples() -> list[list]:
342
  return rows
343
 
344
 
345
- with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="SemBridge — Speech & Singing") as demo:
346
  gr.HTML(
347
  "<div style='text-align:center'>"
348
  "<h1>🎤 SemBridge</h1>"
@@ -369,8 +372,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="SemBridge — Speech &
369
  lines=2, autofocus=True,
370
  )
371
  tts_run = gr.Button("Generate speech", variant="primary")
372
- tts_out = gr.Audio(label="Generated speech", type="filepath",
373
- show_download_button=True)
374
  tts_status = gr.Textbox(label="Info", show_label=False, interactive=False)
375
  with gr.Accordion("Reference voice (required)", open=True):
376
  tts_voice = gr.Dropdown(list(VOICE_BY_LABEL) + [CUSTOM],
@@ -403,8 +405,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="SemBridge — Speech &
403
  lines=8, autofocus=True,
404
  )
405
  svs_run = gr.Button("Generate singing", variant="primary")
406
- svs_out = gr.Audio(label="Generated singing", type="filepath",
407
- show_download_button=True)
408
  svs_status = gr.Textbox(label="Info", show_label=False, interactive=False)
409
  with gr.Accordion("Sung reference voice (required)", open=True):
410
  svs_voice = gr.Dropdown(list(VOICE_BY_LABEL) + [CUSTOM],
@@ -440,8 +441,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="SemBridge — Speech &
440
  label="Case (speech → singing → speech)",
441
  )
442
  uni_run = gr.Button("Generate mixed sequence", variant="primary")
443
- uni_out = gr.Audio(label="Generated mixed audio", type="filepath",
444
- show_download_button=True)
445
  uni_status = gr.Textbox(label="Info", show_label=False, interactive=False)
446
  with gr.Accordion("Generation overrides (optional)", open=False):
447
  with gr.Row():
@@ -476,4 +476,4 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="SemBridge — Speech &
476
  inputs=[case_id, uni_flow, uni_cfg, uni_temp, uni_seed],
477
  outputs=[uni_out, uni_status], api_name="unified")
478
 
479
- demo.launch(mcp_server=True)
 
148
  def _estimate_duration(task: str, *args, **kwargs) -> int:
149
  """Callable @spaces.GPU duration: reserve what this request needs, not a blanket worst case.
150
 
151
+ Receives the same inputs as the decorated function (positional layout of
152
+ the handler signature when ZeroGPU passes args positionally, keywords as
153
+ a fallback — both are accepted). Calibrated on an RTX PRO 6000: ~18 s
154
+ cold-start overhead + flow_steps × ~55 ms per generated patch + decode
155
+ time.
156
  """
157
+ text = kwargs.get("text") or kwargs.get("score_text") or (args[0] if args else "") or ""
158
  flow_steps = kwargs.get("flow_steps")
159
+ if flow_steps is None and len(args) >= 5:
160
+ flow_steps = args[4]
161
  steps = int(flow_steps) if flow_steps else 10
162
  steps = max(steps, 2)
163
  if task == "svs" and isinstance(text, str) and "|" in text:
 
345
  return rows
346
 
347
 
348
+ with gr.Blocks(title="SemBridge — Speech & Singing") as demo:
349
  gr.HTML(
350
  "<div style='text-align:center'>"
351
  "<h1>🎤 SemBridge</h1>"
 
372
  lines=2, autofocus=True,
373
  )
374
  tts_run = gr.Button("Generate speech", variant="primary")
375
+ tts_out = gr.Audio(label="Generated speech", type="filepath")
 
376
  tts_status = gr.Textbox(label="Info", show_label=False, interactive=False)
377
  with gr.Accordion("Reference voice (required)", open=True):
378
  tts_voice = gr.Dropdown(list(VOICE_BY_LABEL) + [CUSTOM],
 
405
  lines=8, autofocus=True,
406
  )
407
  svs_run = gr.Button("Generate singing", variant="primary")
408
+ svs_out = gr.Audio(label="Generated singing", type="filepath")
 
409
  svs_status = gr.Textbox(label="Info", show_label=False, interactive=False)
410
  with gr.Accordion("Sung reference voice (required)", open=True):
411
  svs_voice = gr.Dropdown(list(VOICE_BY_LABEL) + [CUSTOM],
 
441
  label="Case (speech → singing → speech)",
442
  )
443
  uni_run = gr.Button("Generate mixed sequence", variant="primary")
444
+ uni_out = gr.Audio(label="Generated mixed audio", type="filepath")
 
445
  uni_status = gr.Textbox(label="Info", show_label=False, interactive=False)
446
  with gr.Accordion("Generation overrides (optional)", open=False):
447
  with gr.Row():
 
476
  inputs=[case_id, uni_flow, uni_cfg, uni_temp, uni_seed],
477
  outputs=[uni_out, uni_status], api_name="unified")
478
 
479
+ demo.launch(mcp_server=True, theme=gr.themes.Citrus(), css=CSS)