Skip to content

Feature/add-gradio-webui#123

Open
ByronLeeeee wants to merge 2 commits into
k2-fsa:masterfrom
ByronLeeeee:feature/add-gradio-webui
Open

Feature/add-gradio-webui#123
ByronLeeeee wants to merge 2 commits into
k2-fsa:masterfrom
ByronLeeeee:feature/add-gradio-webui

Conversation

@ByronLeeeee

Copy link
Copy Markdown

This PR introduces a user-friendly Chinese WebUI based on Gradio, making it easier for users to experience ZipVoice without using the command line.

The WebUI supports: Single-speaker TTS (PyTorch & ONNX), Dialogue TTS, Batch inference via TSV.

To run the WebUI:

  1. Install new dependencies: pip install -r requirements-webui.txt

  2. Run the script: python webui_zh.py

@pkufool pkufool requested a review from Copilot September 16, 2025 08:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a Chinese WebUI for ZipVoice using Gradio, providing a user-friendly interface for TTS tasks without requiring command-line usage. The WebUI supports multiple TTS modes including single-speaker PyTorch/ONNX inference, dialogue synthesis, and batch processing via TSV files.

Key changes:

  • Added a comprehensive Chinese WebUI (webui_zh.py) with support for various TTS modes
  • Added Gradio dependency for the WebUI functionality
  • Fixed encoding issues in existing Python scripts for better Unicode support

Reviewed Changes

Copilot reviewed 4 out of 14 changed files in this pull request and generated 4 comments.

File Description
webui_zh.py Main WebUI implementation with Chinese interface for all TTS modes
requirements-webui.txt Gradio dependency for WebUI functionality
egs/zipvoice_dialog/local/prepare_opendialog.py Fixed file encoding to UTF-8 for Unicode support
egs/zipvoice/local/prepare_token_file_emilia.py Fixed file encoding to UTF-8 for Unicode support

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread webui_zh.py
# 确保输出目录存在
os.makedirs("outputs", exist_ok=True)

os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting global environment variables in application code is not recommended. Consider making this configurable through command-line arguments or configuration files, or document this as a China-specific mirror requirement.

Suggested change
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
# 如需使用中国大陆 HuggingFace 镜像,请在启动时添加 --hf-mirror 参数,或设置环境变量 USE_HF_MIRROR=1
if '--hf-mirror' in sys.argv or os.environ.get('USE_HF_MIRROR') == '1':
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
logging.info("已启用 HuggingFace 中国大陆镜像 (https://hf-mirror.com)")

Copilot uses AI. Check for mistakes.
Comment thread webui_zh.py
Comment on lines +42 to +44
# --- 核心命令行执行函数 ---
def run_command(command, progress_desc="正在合成..."):
"""执行命令行命令并记录输出。"""

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subprocess call uses shell=False which is good for security, but consider validating the command arguments to prevent potential command injection if any user input reaches this function.

Suggested change
# --- 核心命令行执行函数 ---
def run_command(command, progress_desc="正在合成..."):
"""执行命令行命令并记录输出。"""
# --- 核心命令行执行函数 ---
def validate_command_args(command):
"""验证命令参数,防止命令注入。"""
if not isinstance(command, (list, tuple)):
raise gr.Error("命令参数必须为列表或元组。")
for arg in command:
if not isinstance(arg, str):
raise gr.Error("命令参数中的每一项都必须为字符串。")
if '\x00' in arg:
raise gr.Error("命令参数中不能包含空字节。")
# 可根据需要添加更多检查,例如禁止某些特殊字符
def run_command(command, progress_desc="正在合成..."):
"""执行命令行命令并记录输出。"""
validate_command_args(command)

Copilot uses AI. Check for mistakes.
Comment thread webui_zh.py
logging.error(f"命令执行失败! 返回码: {process.returncode}")
logging.error(f"标准输出:\n{stdout}")
logging.error(f"标准错误:\n{stderr}")
raise gr.Error(f"后端脚本执行失败: {stderr[:1000]}")

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truncating error messages to 1000 characters could potentially expose sensitive information from stderr. Consider sanitizing or filtering the error output before displaying it to users.

Copilot uses AI. Check for mistakes.
Comment thread webui_zh.py
Comment on lines +447 to +448
try:
df = pd.read_csv(file.name, sep='\t', header=None)

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading user-uploaded files without validation could be a security risk. Consider validating file size, content type, and sanitizing the file path before processing.

Suggested change
try:
df = pd.read_csv(file.name, sep='\t', header=None)
# Validate file size (e.g., max 5MB)
max_size = 5 * 1024 * 1024 # 5MB
file.file.seek(0, os.SEEK_END)
size = file.file.tell()
file.file.seek(0)
if size > max_size:
raise gr.Error("上传的文件过大,最大支持 5MB。")
# Validate file extension
allowed_exts = ['.tsv', '.txt']
_, ext = os.path.splitext(file.name)
if ext.lower() not in allowed_exts:
raise gr.Error("仅支持 .tsv 或 .txt 文件。")
try:
# Try reading a few bytes to check if it's text
sample = file.file.read(1024)
try:
sample.decode('utf-8')
except Exception:
raise gr.Error("文件不是有效的文本文件,请上传 UTF-8 编码的 TSV 文件。")
file.file.seek(0)
df = pd.read_csv(file.file, sep='\t', header=None)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants