Spaces:
Running
Running
| # =================================================================== | |
| # [最重要] アプリケーションの本体を読み込む前に、モデルのセットアップを実行 | |
| 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) |