Ver 2.7.0 maybe

This commit is contained in:
litagin02
2025-08-24 11:27:27 +09:00
parent 4859d64e9f
commit c51c80fe1a
24 changed files with 173 additions and 33 deletions

101
gradio_tabs/convert_onnx.py Normal file
View File

@@ -0,0 +1,101 @@
from pathlib import Path
import gradio as gr
from style_bert_vits2.constants import GRADIO_THEME
from style_bert_vits2.logging import logger
from style_bert_vits2.tts_model import NullModelParam, TTSModelHolder
from style_bert_vits2.utils.subprocess import run_script_with_log
def call_convert_onnx(
model: str,
):
if model == "":
return "Error: モデル名を入力してください。"
logger.info("Start converting model to onnx...")
cmd = [
"convert_onnx.py",
"--model",
model,
]
success, message = run_script_with_log(cmd, ignore_warning=True)
if not success:
return f"Error: {message}"
return "ONNX変換が完了しました。"
initial_md = """
safetensors形式のモデルをONNX形式に変換します。
このONNXモデルは、[AIVM Generator](https://aivm-generator.aivis-project.com/) 等でさらにAIVM形式・AIVMX形式に変換して[AivisSpeech](https://aivis-project.com/)で利用できます。
変換には5分以上ほどの時間がかかります。進捗状況はターミナルのログを参照してください。
"""
def create_onnx_app(model_holder: TTSModelHolder) -> gr.Blocks:
def get_model_files(model_name: str):
return [str(f) for f in model_holder.model_files_dict[model_name]]
model_names = model_holder.model_names
if len(model_names) == 0:
logger.error(
f"モデルが見つかりませんでした。{model_holder.root_dir}にモデルを置いてください。"
)
with gr.Blocks() as app:
gr.Markdown(
f"Error: モデルが見つかりませんでした。{model_holder.root_dir}にモデルを置いてください。"
)
return app
initial_id = 0
initial_pth_files = get_model_files(model_names[initial_id])
with gr.Blocks(theme=GRADIO_THEME) as app:
gr.Markdown(initial_md)
with gr.Row():
with gr.Column():
model_name = gr.Dropdown(
label="モデル一覧",
choices=model_names,
value=model_names[initial_id],
)
model_path = gr.Dropdown(
label="モデルファイル",
choices=initial_pth_files,
value=initial_pth_files[0],
)
refresh_button = gr.Button("更新")
convert_button = gr.Button("ONNX形式に変換", variant="primary")
info = gr.Textbox(label="情報")
model_name.change(
model_holder.update_model_files_for_gradio,
inputs=[model_name],
outputs=[model_path],
)
def refresh_fn() -> tuple[gr.Dropdown, gr.Dropdown]:
names, files, _ = model_holder.update_model_names_for_gradio()
return names, files
refresh_button.click(
refresh_fn,
outputs=[model_name, model_path],
)
convert_button.click(
call_convert_onnx,
inputs=[model_path],
outputs=[info],
)
return app
if __name__ == "__main__":
from config import get_path_config
path_config = get_path_config()
assets_root = path_config.assets_root
model_holder = TTSModelHolder(assets_root, "cpu", "", ignore_onnx=True)
app = create_onnx_app(model_holder)
app.launch(inbrowser=True)

View File

@@ -51,6 +51,11 @@ def do_transcribe(
):
if model_name == "":
return "Error: モデル名を入力してください。"
if hf_repo_id == "litagin/anime-whisper":
logger.info(
"Since litagin/anime-whisper does not support initial prompt, it will be ignored."
)
initial_prompt = ""
cmd = [
"transcribe.py",
@@ -159,34 +164,30 @@ def create_dataset_app() -> gr.Blocks:
result1 = gr.Textbox(label="結果")
with gr.Row():
with gr.Column():
use_hf_whisper = gr.Checkbox(
label="HuggingFaceのWhisperを使う速度が速いがVRAMを多く使う",
value=False,
)
whisper_model = gr.Dropdown(
[
"tiny",
"base",
"small",
"medium",
"large",
"large-v2",
"large-v3",
],
label="Whisperモデル",
value="large-v3",
)
use_hf_whisper = gr.Checkbox(
label="HuggingFaceのWhisperを使う速度が速いがVRAMを多く使う",
value=False,
visible=True,
)
hf_repo_id = gr.Dropdown(
[
"openai/whisper-large-v3-turbo",
"openai/whisper-large-v3",
"openai/whisper-large-v2",
"kotoba-tech/kotoba-whisper-v1.1",
"kotoba-tech/kotoba-whisper-v2.1",
"litagin/anime-whisper",
],
label="HuggingFaceのWhisper repo_id",
value="openai/whisper-large-v3",
value="openai/whisper-large-v3-turbo",
visible=False,
)
compute_type = gr.Dropdown(
@@ -258,12 +259,13 @@ def create_dataset_app() -> gr.Blocks:
)
use_hf_whisper.change(
lambda x: (
gr.update(visible=not x),
gr.update(visible=x),
gr.update(visible=x),
gr.update(visible=not x),
),
inputs=[use_hf_whisper],
outputs=[hf_repo_id, batch_size, compute_type],
outputs=[whisper_model, hf_repo_id, batch_size, compute_type],
)
return app

View File

@@ -322,6 +322,7 @@ def save_style_vectors_by_dirs(model_name: str, audio_dir_str: str):
total=len(audio_files),
file=SAFE_STDOUT,
desc="Generating style vectors",
dynamic_ncols=True,
)
)