cockolo terada commited on
Commit
9c5f6d1
·
verified ·
1 Parent(s): 0a8cb74

Update initialize.py

Browse files
Files changed (1) hide show
  1. initialize.py +72 -51
initialize.py CHANGED
@@ -9,13 +9,14 @@ import logging
9
  logging.basicConfig(level=logging.INFO)
10
  logger = logging.getLogger(__name__)
11
 
12
- def create_symlink_if_not_exists(repo_id, filename, link_dir):
13
  """
14
- Hugging Face Hubからファイルをキャッシュにダウンロードし、
15
- 指定された場所にシンボリックリンクを作成するヘルパー関数。
16
  """
17
- # リンクを配置したいパスを定義 (例: pretrained/G_0.safetensors)
18
- link_path = Path(link_dir) / filename
 
19
 
20
  # リンクが既に存在する場合はスキップ
21
  if link_path.exists():
@@ -24,13 +25,14 @@ def create_symlink_if_not_exists(repo_id, filename, link_dir):
24
  # リンク先の親ディレクトリがなければ作成
25
  link_path.parent.mkdir(parents=True, exist_ok=True)
26
 
27
- logger.info(f"Downloading {repo_id}/{filename}")
28
 
29
- # Hugging Face Hubからファイルをダウンロード(キャッシュ優先)し、実際のパスを取得
30
  try:
31
- actual_file_path = hf_hub_download(repo_id=repo_id, filename=filename)
 
32
  except Exception as e:
33
- logger.error(f"Failed to download {filename}: {e}")
34
  return
35
 
36
  # シンボリックリンクを作成
@@ -47,15 +49,18 @@ def setup_bert_models():
47
  # BERTモデルは 'bert/モデル名/' というサブディレクトリに配置
48
  link_dir = Path("bert") / model_name
49
  for file in model_info["files"]:
50
- create_symlink_if_not_exists(repo_id, file, link_dir)
51
 
52
  def setup_slm_model():
53
  logger.info("Setting up SLM model...")
 
 
54
  # SLMモデルは 'slm/wavlm-base-plus/' というサブディレクトリに配置
55
  create_symlink_if_not_exists(
56
  repo_id="microsoft/wavlm-base-plus",
57
- filename="pytorch_model.bin",
58
- link_dir="slm/wavlm-base-plus/"
 
59
  )
60
 
61
  def setup_pretrained_models():
@@ -63,61 +68,77 @@ def setup_pretrained_models():
63
  repo_id = "litagin/Style-Bert-VITS2-1.0-base"
64
  files = ["G_0.safetensors", "D_0.safetensors", "DUR_0.safetensors"]
65
  for file in files:
66
- create_symlink_if_not_exists(repo_id, file, "pretrained")
67
 
68
  def setup_jp_extra_pretrained_models():
69
  logger.info("Setting up JP-Extra Pretrained models...")
70
  repo_id = "litagin/Style-Bert-VITS2-2.0-base-JP-Extra"
71
  files = ["G_0.safetensors", "D_0.safetensors", "WD_0.safetensors"]
72
  for file in files:
73
- create_symlink_if_not_exists(repo_id, file, "pretrained_jp_extra")
74
 
75
  def setup_default_models():
76
  logger.info("Setting up default speaker models...")
77
- # 先ほどの回答で示した `model_assets` 以下のモデル
78
  models_to_link = {
79
  "litagin/style_bert_vits2_jvnv": [
80
  "jvnv-F1-jp/config.json", "jvnv-F1-jp/jvnv-F1-jp_e160_s14000.safetensors", "jvnv-F1-jp/style_vectors.npy",
81
- # ... 他のjvnvモデルも同様に追加
82
  ],
83
- "teradakokoro/voice_models/CO": ["ANNYUI/config.json", "ANNYUI/style_settings.json", "ANNYUI/style_vectors.npy", "ANNYUI/ANNYUI_e101_s21000.safetensors"],
84
- "teradakokoro/voice_models": ["CO/ASTK/config.json", "CO/ASTK/style_settings.json", "CO/ASTK/style_vectors.npy", "CO/ASTK/ASTK_e501_s28000.safetensors"],
85
- "teradakokoro/voice_models": ["CO/AZS/config.json", "CO/AZS/style_settings.json", "CO/AZS/style_vectors.npy", "CO/AZS/AZS_e442_s34000.safetensors"],
86
- "teradakokoro/voice_models": ["CO/BNKRG/config.json", "CO/BNKRG/style_settings.json", "CO/BNKRG/style_vectors.npy", "CO/BNKRG/BNKRG_e222_s31000.safetensors"],
87
- "teradakokoro/voice_models": ["CO/ESK/config.json", "CO/ESK/style_settings.json", "CO/ESK/style_vectors.npy", "CO/ESK/ESK_e42_s11000.safetensors"],
88
- "teradakokoro/voice_models": ["CO/HNS/config.json", "CO/HNS/style_settings.json", "CO/HNS/style_vectors.npy", "CO/HNS/HNS_e1000_s11000.safetensors"],
89
- "teradakokoro/voice_models": ["CO/HSI/config.json", "CO/HSI/style_settings.json", "CO/HSI/style_vectors.npy", "CO/HSI/HSI_e209_s26000.safetensors"],
90
- "teradakokoro/voice_models": ["CO/KNN/config.json", "CO/KNN/style_settings.json", "CO/KNN/style_vectors.npy", "CO/KNN/KNN_e68_s15000.safetensors"],
91
- "teradakokoro/voice_models": ["CO/MZ/config.json", "CO/MZ/style_settings.json", "CO/MZ/style_vectors.npy", "CO/MZ/MZ_e137_s14000.safetensors"],
92
- "teradakokoro/voice_models": ["CO/NEL/config.json", "CO/NEL/style_settings.json", "CO/NEL/style_vectors.npy", "CO/NEL/NEL_e1000_s16000.safetensors"],
93
- "teradakokoro/voice_models": ["CO/PSR/config.json", "CO/PSR/style_settings.json", "CO/PSR/style_vectors.npy", "CO/PSR/PSR_e142_s25000.safetensors"],
94
- "teradakokoro/voice_models": ["CO/RI/config.json", "CO/RI/style_settings.json", "CO/RI/style_vectors.npy", "CO/RI/RI_e94_s20000.safetensors"],
95
- "teradakokoro/voice_models": ["CO/SKRNBU/config.json", "CO/SKRNBU/style_settings.json", "CO/SKRNBU/style_vectors.npy", "CO/SKRNBU/SKRNBU_e135_s25000.safetensors"],
96
- "teradakokoro/voice_models": ["CO/SNNN/config.json", "CO/SNNN/style_settings.json", "CO/SNNN/style_vectors.npy", "CO/SNNN/SNNN_e201_s11000.safetensors"],
97
- "teradakokoro/voice_models": ["CO/SRMY/config.json", "CO/SRMY/style_settings.json", "CO/SRMY/style_vectors.npy", "CO/SRMY/SRMY_e1000_s20000.safetensors"],
98
- "teradakokoro/voice_models": ["CO/TIS/config.json", "CO/TIS/style_settings.json", "CO/TIS/style_vectors.npy", "CO/TIS/TIS_e596_s28000.safetensors"],
99
- "teradakokoro/voice_models": ["CO/UDK/config.json", "CO/UDK/style_settings.json", "CO/UDK/style_vectors.npy", "CO/UDK/UDK_e472_s25000.safetensors"],
100
- "teradakokoro/voice_models": ["CO/VVAN/config.json", "CO/VVAN/style_settings.json", "CO/VVAN/style_vectors.npy", "CO/VVAN/VVAN_e728_s32000.safetensors"],
101
- "teradakokoro/voice_models": ["CO/YZY/config.json", "CO/YZY/style_settings.json", "CO/YZY/style_vectors.npy", "CO/YZY/YZY_e1000_s15000.safetensors"],
102
-
103
- "teradakokoro/voice_models": ["FN/FN1/config.json", "FN/FN1/style_settings.json", "FN/FN1/style_vectors.npy", "FN/FN1/FN1.safetensors"],
104
- "teradakokoro/voice_models": ["FN/FN10/config.json", "FN/FN10/style_settings.json", "FN/FN10/style_vectors.npy", "FN/FN10/FN10.safetensors"],
105
- "teradakokoro/voice_models": ["FN/FN2/config.json", "FN/FN2/style_settings.json", "FN/FN2/style_vectors.npy", "FN/FN2/FN2.safetensors"],
106
- "teradakokoro/voice_models": ["FN/FN3/config.json", "FN/FN3/style_settings.json", "FN/FN3/style_vectors.npy", "FN/FN3/FN3.safetensors"],
107
- "teradakokoro/voice_models": ["FN/FN4/config.json", "FN/FN4/style_settings.json", "FN/FN4/style_vectors.npy", "FN/FN4/FN4.safetensors"],
108
- "teradakokoro/voice_models": ["FN/FN5/config.json", "FN/FN5/style_settings.json", "FN/FN5/style_vectors.npy", "FN/FN5/FN5.safetensors"],
109
- "teradakokoro/voice_models": ["FN/FN6/config.json", "FN/FN6/style_settings.json", "FN/FN6/style_vectors.npy", "FN/FN6/FN6.safetensors"],
110
- "teradakokoro/voice_models": ["FN/FN7/config.json", "FN/FN7/style_settings.json", "FN/FN7/style_vectors.npy", "FN/FN7/FN7.safetensors"],
111
- "teradakokoro/voice_models": ["FN/FN8/config.json", "FN/FN8/style_settings.json", "FN/FN8/style_vectors.npy", "FN/FN8/FN8.safetensors"],
112
- "teradakokoro/voice_models": ["FN/FN9/config.json", "FN/FN9/style_settings.json", "FN/FN9/style_vectors.npy", "FN/FN9/FN9.safetensors"],
113
-
114
- "teradakokoro/voice_models/other": ["whisper/config.json", "whisper/style_vectors.npy", "whisper/whisper.safetensors"],
 
 
 
115
  }
116
 
117
  for repo_id, files_in_repo in models_to_link.items():
118
- for file_path in files_in_repo:
119
- # ここではファイル名だけでなくディレクトリ構造も含むパスを渡す
120
- create_symlink_if_not_exists(repo_id, file_path, "model_assets")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  def main(skip_default_models=False, only_infer=False):
123
  """
 
9
  logging.basicConfig(level=logging.INFO)
10
  logger = logging.getLogger(__name__)
11
 
12
+ def create_symlink_if_not_exists(repo_id, repo_filepath, local_subpath, link_dir):
13
  """
14
+ Hugging Face Hubからファイルをダウンロードし、シンボリックリンクを作成する。
15
+ リポジトリ上のパスとローカルのパスを分離して扱えるように修正。
16
  """
17
+ # リンクを配置したいローカルのフルパスを定義
18
+ # 例: link_dir="model_assets", local_subpath="ANNYUI/config.json" -> "model_assets/ANNYUI/config.json"
19
+ link_path = Path(link_dir) / local_subpath
20
 
21
  # リンクが既に存在する場合はスキップ
22
  if link_path.exists():
 
25
  # リンク先の親ディレクトリがなければ作成
26
  link_path.parent.mkdir(parents=True, exist_ok=True)
27
 
28
+ logger.info(f"Downloading {repo_id}/{repo_filepath}")
29
 
30
+ # Hugging Face Hubからファイルをダウンロード(キャッシュ優先)
31
  try:
32
+ # ダウンロードにはリポジトリ上のフルパス(repo_filepath)を使用
33
+ actual_file_path = hf_hub_download(repo_id=repo_id, filename=repo_filepath)
34
  except Exception as e:
35
+ logger.error(f"Failed to download {repo_filepath}: {e}")
36
  return
37
 
38
  # シンボリックリンクを作成
 
49
  # BERTモデルは 'bert/モデル名/' というサブディレクトリに配置
50
  link_dir = Path("bert") / model_name
51
  for file in model_info["files"]:
52
+ create_symlink_if_not_exists(repo_id, file, file, link_dir)
53
 
54
  def setup_slm_model():
55
  logger.info("Setting up SLM model...")
56
+ filename = "pytorch_model.bin"
57
+ link_dir = "slm/wavlm-base-plus/"
58
  # SLMモデルは 'slm/wavlm-base-plus/' というサブディレクトリに配置
59
  create_symlink_if_not_exists(
60
  repo_id="microsoft/wavlm-base-plus",
61
+ repo_filepath=filename,
62
+ local_subpath=filename,
63
+ link_dir=link_dir
64
  )
65
 
66
  def setup_pretrained_models():
 
68
  repo_id = "litagin/Style-Bert-VITS2-1.0-base"
69
  files = ["G_0.safetensors", "D_0.safetensors", "DUR_0.safetensors"]
70
  for file in files:
71
+ create_symlink_if_not_exists(repo_id, file, file, "pretrained")
72
 
73
  def setup_jp_extra_pretrained_models():
74
  logger.info("Setting up JP-Extra Pretrained models...")
75
  repo_id = "litagin/Style-Bert-VITS2-2.0-base-JP-Extra"
76
  files = ["G_0.safetensors", "D_0.safetensors", "WD_0.safetensors"]
77
  for file in files:
78
+ create_symlink_if_not_exists(repo_id, file, file, "pretrained_jp_extra")
79
 
80
  def setup_default_models():
81
  logger.info("Setting up default speaker models...")
82
+ # `models_to_link` 辞書を修正し、キーの重複をなくす
83
  models_to_link = {
84
  "litagin/style_bert_vits2_jvnv": [
85
  "jvnv-F1-jp/config.json", "jvnv-F1-jp/jvnv-F1-jp_e160_s14000.safetensors", "jvnv-F1-jp/style_vectors.npy",
 
86
  ],
87
+ "teradakokoro/voice_models": [
88
+ # CO Models
89
+ "CO/ANNYUI/config.json", "CO/ANNYUI/style_settings.json", "CO/ANNYUI/style_vectors.npy", "CO/ANNYUI/ANNYUI_e101_s21000.safetensors",
90
+ "CO/ASTK/config.json", "CO/ASTK/style_settings.json", "CO/ASTK/style_vectors.npy", "CO/ASTK/ASTK_e501_s28000.safetensors",
91
+ "CO/AZS/config.json", "CO/AZS/style_settings.json", "CO/AZS/style_vectors.npy", "CO/AZS/AZS_e442_s34000.safetensors",
92
+ "CO/BNKRG/config.json", "CO/BNKRG/style_settings.json", "CO/BNKRG/style_vectors.npy", "CO/BNKRG/BNKRG_e222_s31000.safetensors",
93
+ "CO/ESK/config.json", "CO/ESK/style_settings.json", "CO/ESK/style_vectors.npy", "CO/ESK/ESK_e42_s11000.safetensors",
94
+ "CO/HNS/config.json", "CO/HNS/style_settings.json", "CO/HNS/style_vectors.npy", "CO/HNS/HNS_e1000_s11000.safetensors",
95
+ "CO/HSI/config.json", "CO/HSI/style_settings.json", "CO/HSI/style_vectors.npy", "CO/HSI/HSI_e209_s26000.safetensors",
96
+ "CO/KNN/config.json", "CO/KNN/style_settings.json", "CO/KNN/style_vectors.npy", "CO/KNN/KNN_e68_s15000.safetensors",
97
+ "CO/MZ/config.json", "CO/MZ/style_settings.json", "CO/MZ/style_vectors.npy", "CO/MZ/MZ_e137_s14000.safetensors",
98
+ "CO/NEL/config.json", "CO/NEL/style_settings.json", "CO/NEL/style_vectors.npy", "CO/NEL/NEL_e1000_s16000.safetensors",
99
+ "CO/PSR/config.json", "CO/PSR/style_settings.json", "CO/PSR/style_vectors.npy", "CO/PSR/PSR_e142_s25000.safetensors",
100
+ "CO/RI/config.json", "CO/RI/style_settings.json", "CO/RI/style_vectors.npy", "CO/RI/RI_e94_s20000.safetensors",
101
+ "CO/SKRNBU/config.json", "CO/SKRNBU/style_settings.json", "CO/SKRNBU/style_vectors.npy", "CO/SKRNBU/SKRNBU_e135_s25000.safetensors",
102
+ "CO/SNNN/config.json", "CO/SNNN/style_settings.json", "CO/SNNN/style_vectors.npy", "CO/SNNN/SNNN_e201_s11000.safetensors",
103
+ "CO/SRMY/config.json", "CO/SRMY/style_settings.json", "CO/SRMY/style_vectors.npy", "CO/SRMY/SRMY_e1000_s20000.safetensors",
104
+ "CO/TIS/config.json", "CO/TIS/style_settings.json", "CO/TIS/style_vectors.npy", "CO/TIS/TIS_e596_s28000.safetensors",
105
+ "CO/UDK/config.json", "CO/UDK/style_settings.json", "CO/UDK/style_vectors.npy", "CO/UDK/UDK_e472_s25000.safetensors",
106
+ "CO/VVAN/config.json", "CO/VVAN/style_settings.json", "CO/VVAN/style_vectors.npy", "CO/VVAN/VVAN_e728_s32000.safetensors",
107
+ "CO/YZY/config.json", "CO/YZY/style_settings.json", "CO/YZY/style_vectors.npy", "CO/YZY/YZY_e1000_s15000.safetensors",
108
+ # FN Models
109
+ "FN/FN1/config.json", "FN/FN1/style_settings.json", "FN/FN1/style_vectors.npy", "FN/FN1/FN1.safetensors",
110
+ "FN/FN10/config.json", "FN/FN10/style_settings.json", "FN/FN10/style_vectors.npy", "FN/FN10/FN10.safetensors",
111
+ "FN/FN2/config.json", "FN/FN2/style_settings.json", "FN/FN2/style_vectors.npy", "FN/FN2/FN2.safetensors",
112
+ "FN/FN3/config.json", "FN/FN3/style_settings.json", "FN/FN3/style_vectors.npy", "FN/FN3/FN3.safetensors",
113
+ "FN/FN4/config.json", "FN/FN4/style_settings.json", "FN/FN4/style_vectors.npy", "FN/FN4/FN4.safetensors",
114
+ "FN/FN5/config.json", "FN/FN5/style_settings.json", "FN/FN5/style_vectors.npy", "FN/FN5/FN5.safetensors",
115
+ "FN/FN6/config.json", "FN/FN6/style_settings.json", "FN/FN6/style_vectors.npy", "FN/FN6/FN6.safetensors",
116
+ "FN/FN7/config.json", "FN/FN7/style_settings.json", "FN/FN7/style_vectors.npy", "FN/FN7/FN7.safetensors",
117
+ "FN/FN8/config.json", "FN/FN8/style_settings.json", "FN/FN8/style_vectors.npy", "FN/FN8/FN8.safetensors",
118
+ "FN/FN9/config.json", "FN/FN9/style_settings.json", "FN/FN9/style_vectors.npy", "FN/FN9/FN9.safetensors",
119
+ # other Models
120
+ "other/whisper/config.json", "other/whisper/style_vectors.npy", "other/whisper/whisper.safetensors",
121
+ ]
122
  }
123
 
124
  for repo_id, files_in_repo in models_to_link.items():
125
+ for repo_filepath in files_in_repo:
126
+ local_subpath = repo_filepath # デフォルトではリポジトリパスをそのままローカルパスとする
127
+
128
+ # teradakokoro/voice_models の場合のみ、パスの先頭部分を加工
129
+ if repo_id == "teradakokoro/voice_models":
130
+ path_parts = repo_filepath.split('/')
131
+ # パスの先頭が 'CO', 'FN', 'other' のいずれかなら、それを取り除く
132
+ if len(path_parts) > 1 and path_parts[0] in ["CO", "FN", "other"]:
133
+ local_subpath = '/'.join(path_parts[1:])
134
+
135
+ # 修正したヘルパー関数を呼び出す
136
+ create_symlink_if_not_exists(
137
+ repo_id=repo_id,
138
+ repo_filepath=repo_filepath, # ダウンロード用には元のフルパス
139
+ local_subpath=local_subpath, # リンク作成用には加工したパス
140
+ link_dir="model_assets"
141
+ )
142
 
143
  def main(skip_default_models=False, only_infer=False):
144
  """