Fix Gradio 4.x Audio compatibility on server
Only pass show_download_button and show_share_button when the installed Gradio Audio component supports them, fixing PM2 startup TypeError. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,7 @@ Gradio Web 中控:音色锁定 → Whisper 识别 → Gemma4 润色 → ChatTT
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@@ -74,6 +75,22 @@ def ui_initial_history() -> tuple[dict, dict]:
|
|||||||
return gr.update(choices=choices, value=latest), ui_history_play(latest)
|
return gr.update(choices=choices, value=latest), ui_history_play(latest)
|
||||||
|
|
||||||
|
|
||||||
|
def _tts_output_audio(label: str) -> gr.Audio:
|
||||||
|
"""成品播放器:兼容 Gradio 4.x(无 show_download_button 等参数)。"""
|
||||||
|
kwargs: dict = {
|
||||||
|
"label": label,
|
||||||
|
"type": "filepath",
|
||||||
|
"interactive": False,
|
||||||
|
"elem_classes": ["tts-output-audio"],
|
||||||
|
}
|
||||||
|
params = inspect.signature(gr.Audio.__init__).parameters
|
||||||
|
if "show_download_button" in params:
|
||||||
|
kwargs["show_download_button"] = True
|
||||||
|
if "show_share_button" in params:
|
||||||
|
kwargs["show_share_button"] = False
|
||||||
|
return gr.Audio(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# 全局 UI 状态(Gradio State)
|
# 全局 UI 状态(Gradio State)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -1148,14 +1165,7 @@ def build_app() -> gr.Blocks:
|
|||||||
with gr.Row(elem_classes=["pipeline-output-row"]):
|
with gr.Row(elem_classes=["pipeline-output-row"]):
|
||||||
pipe_raw = gr.Textbox(label="转写原文", lines=6)
|
pipe_raw = gr.Textbox(label="转写原文", lines=6)
|
||||||
pipe_polished = gr.Textbox(label="润色稿", lines=6)
|
pipe_polished = gr.Textbox(label="润色稿", lines=6)
|
||||||
pipe_output = gr.Audio(
|
pipe_output = _tts_output_audio("成品配音")
|
||||||
label="成品配音",
|
|
||||||
type="filepath",
|
|
||||||
interactive=False,
|
|
||||||
show_download_button=True,
|
|
||||||
show_share_button=False,
|
|
||||||
elem_classes=["tts-output-audio"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# ---- Tab 2: 分步流水线 ----
|
# ---- Tab 2: 分步流水线 ----
|
||||||
with gr.Tab("🔧 分步流水线"):
|
with gr.Tab("🔧 分步流水线"):
|
||||||
@@ -1202,14 +1212,7 @@ def build_app() -> gr.Blocks:
|
|||||||
)
|
)
|
||||||
synth_btn = gr.Button("🔊 合成配音 WAV", variant="primary")
|
synth_btn = gr.Button("🔊 合成配音 WAV", variant="primary")
|
||||||
synth_log = gr.Textbox(label="合成日志", lines=3, interactive=False)
|
synth_log = gr.Textbox(label="合成日志", lines=3, interactive=False)
|
||||||
output_audio = gr.Audio(
|
output_audio = _tts_output_audio("成品配音")
|
||||||
label="成品配音",
|
|
||||||
type="filepath",
|
|
||||||
interactive=False,
|
|
||||||
show_download_button=True,
|
|
||||||
show_share_button=False,
|
|
||||||
elem_classes=["tts-output-audio"],
|
|
||||||
)
|
|
||||||
|
|
||||||
transcribe_btn.click(ui_transcribe, rec_audio, [raw_text, transcribe_log])
|
transcribe_btn.click(ui_transcribe, rec_audio, [raw_text, transcribe_log])
|
||||||
polish_btn.click(ui_polish, raw_text, [polished_text, polish_log])
|
polish_btn.click(ui_polish, raw_text, [polished_text, polish_log])
|
||||||
@@ -1255,14 +1258,7 @@ def build_app() -> gr.Blocks:
|
|||||||
scale=4,
|
scale=4,
|
||||||
)
|
)
|
||||||
history_refresh_btn = gr.Button("🔄 刷新", scale=0, min_width=100)
|
history_refresh_btn = gr.Button("🔄 刷新", scale=0, min_width=100)
|
||||||
history_player = gr.Audio(
|
history_player = _tts_output_audio("历史试听 / 下载")
|
||||||
label="历史试听 / 下载",
|
|
||||||
type="filepath",
|
|
||||||
interactive=False,
|
|
||||||
show_download_button=True,
|
|
||||||
show_share_button=False,
|
|
||||||
elem_classes=["tts-output-audio"],
|
|
||||||
)
|
|
||||||
|
|
||||||
history_refresh_btn.click(ui_history_dropdown, outputs=[history_select])
|
history_refresh_btn.click(ui_history_dropdown, outputs=[history_select])
|
||||||
history_select.change(ui_history_play, history_select, history_player)
|
history_select.change(ui_history_play, history_select, history_player)
|
||||||
|
|||||||
Reference in New Issue
Block a user