Spaces:
Running
Running
File size: 3,019 Bytes
f854dde 7d653ef f854dde 2d48e71 9c68426 7d653ef 2d48e71 7d653ef 2d48e71 f854dde 2d48e71 f854dde 2d48e71 f854dde 2d48e71 14dda6e 2d48e71 22ba782 2d48e71 73871f8 2d48e71 7d653ef db894b5 7d653ef 2d48e71 f854dde 55ab3a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# ===================================================================
# [最重要] アプリケーションの本体を読み込む前に、モデルのセットアップを実行
import initialize
import time
print("--- [1/3] Starting Model Setup Script ---")
start_time = time.time()
# Hugging Face Spacesでは推論のみ行うのが一般的なので、
# only_infer=True を指定して不要なモデルのダウンロードをスキップします。
# これにより起動が高速化します。
initialize.main(only_infer=True)
end_time = time.time()
print(f"--- [2/3] Model Setup Complete. Elapsed time: {end_time - start_time:.2f} seconds ---")
# ===================================================================
# [3/3] モデルの準備が完了したので、アプリケーションの本体を読み込んで起動
print("--- [3/3] Initializing and launching Gradio App... ---")
import argparse
from pathlib import Path
import gradio as gr
import torch
# 拡張機能タブから必要なものだけをインポート
from gradio_tabs.single import create_synthesis_app
from gradio_tabs.merge import create_merge_app
# ▼▼▼ ここを追加 ▼▼▼
from gradio_tabs.sample import create_player_tab # sample.pyから関数をインポート
from config import get_path_config
from style_bert_vits2.constants import GRADIO_THEME, VERSION
from style_bert_vits2.nlp.japanese import pyopenjtalk_worker
from style_bert_vits2.nlp.japanese.user_dict import update_dict
from style_bert_vits2.tts_model import TTSModelHolder
# このプロセスからはワーカーを起動して辞書を使いたいので、ここで初期化
pyopenjtalk_worker.initialize_worker()
# dict_data/ 以下の辞書データを pyopenjtalk に適用
update_dict()
parser = argparse.ArgumentParser()
parser.add_argument("--device", type=str, default="cuda")
parser.add_argument("--no_autolaunch", action="store_true")
args = parser.parse_args()
device = args.device
if device == "cuda" and not torch.cuda.is_available():
print("CUDA not available, falling back to CPU.")
device = "cpu"
else:
print(f"Using device: {device}")
path_config = get_path_config()
model_holder = TTSModelHolder(Path(path_config.assets_root), device)
# 起動時にトップへスクロールさせるjsを追加
with gr.Blocks(theme=GRADIO_THEME, js="() => { window.scrollTo(0, 0); }") as app:
gr.Markdown(f"# Amateur Voice")
with gr.Tabs():
with gr.Tab("読み上げ"):
create_synthesis_app(model_holder=model_holder)
with gr.Tab("融☆合"):
create_merge_app(model_holder=model_holder)
# ▼▼▼ ここを追加 ▼▼▼
with gr.Tab("サンプル"):
create_player_tab() # インポートした関数を呼び出してUIを構築
# Hugging Face Spacesでは、share=Trueは不要(自動で公開URLが生成される)
# また、サーバー名とポートも指定しない方が安定します。
app.launch(share=True) |