sbv2-web / app.py
Googlefan
refactor(app.py): wrap example in list
a58b40e
raw
history blame
1.89 kB
import os
os.system("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y")
os.system(
'. "$HOME/.cargo/env" && pip install -U "git+https://github.com/tuna2134/sbv2-api#egg=sbv2_bindings&subdirectory=sbv2_bindings"'
)
import gradio as gr
from huggingface_hub import hf_hub_download
from sbv2_bindings import TTSModel
from uuid import uuid4
bert = hf_hub_download("googlefan/sbv2_onnx_models", "deberta.onnx")
tokenizer = hf_hub_download("googlefan/sbv2_onnx_models", "tokenizer.json")
model = TTSModel.from_path(bert, tokenizer)
def load_and_synthesize(text: str, path: str, sdp: float = 0.0, speed: float = 1.0):
uid = str(uuid4())
path = path.split("/")
filename = path[-1]
repo_id = "/".join(path[:-1])
model.load_sbv2file_from_path(uid, hf_hub_download(repo_id, filename))
print("All setup is done!")
style_vector = model.get_style_vector(uid, 0, 1.0)
return model.synthesize(text, uid, style_vector, sdp, 1.0 / speed)
iface = gr.Interface(
fn=load_and_synthesize, # The function to call
inputs=[
gr.Textbox(lines=2, placeholder="テキスト"), # Text input
gr.Textbox(lines=1, max_lines=1, placeholder="パス"), # Path input
gr.Slider(
minimum=0.0, maximum=1.0, step=0.01, value=0.0, label="SDP"
), # SDP input
gr.Slider(
minimum=0.5, maximum=2.0, step=0.1, value=1.0, label="Speed"
), # Speed input
],
outputs="audio",
title="SBV2音声合成",
description="テキストとモデルのパスを入力して音声を生成します。SDPと速度を調整して音声の質を変更できます。",
examples=[
[
"おはようございます。",
"googlefan/sbv2_personal_models/tenkas.sbv2",
0.0,
1.0,
]
],
)
# Launch the Gradio app
iface.launch()