Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ import numpy as np
|
|
| 13 |
import librosa
|
| 14 |
import re_matching
|
| 15 |
from tools.sentence import split_by_language
|
| 16 |
-
from huggingface_hub import hf_hub_download
|
| 17 |
|
| 18 |
from clap_wrapper import get_clap_audio_feature, get_clap_text_feature
|
| 19 |
from models import SynthesizerTrn
|
|
@@ -121,8 +121,27 @@ if __name__ == "__main__":
|
|
| 121 |
if not info['enable']:
|
| 122 |
continue
|
| 123 |
name, title, repid, example, filename = info['name'], info['title'], info['repid'], info['example'], info['filename']
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
hps = utils.get_hparams_from_file(config_path)
|
| 127 |
version = hps.version if hasattr(hps, "version") else "v2"
|
| 128 |
net_g = get_net_g(model_path, version, device, hps)
|
|
|
|
| 13 |
import librosa
|
| 14 |
import re_matching
|
| 15 |
from tools.sentence import split_by_language
|
| 16 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
| 17 |
|
| 18 |
from clap_wrapper import get_clap_audio_feature, get_clap_text_feature
|
| 19 |
from models import SynthesizerTrn
|
|
|
|
| 121 |
if not info['enable']:
|
| 122 |
continue
|
| 123 |
name, title, repid, example, filename = info['name'], info['title'], info['repid'], info['example'], info['filename']
|
| 124 |
+
|
| 125 |
+
# 1. ลิสต์ไฟล์ใน repo ทั้งหมด
|
| 126 |
+
files = list_repo_files(repo_id=repid)
|
| 127 |
+
|
| 128 |
+
# 2. หา subfolder ที่มี model file อยู่
|
| 129 |
+
model_subfolder = None
|
| 130 |
+
for f in files:
|
| 131 |
+
if f.endswith(filename):
|
| 132 |
+
# แยก path ออกมาเพื่อดูว่าอยู่ใน subfolder ไหม
|
| 133 |
+
parts = f.split("/")
|
| 134 |
+
if len(parts) > 1:
|
| 135 |
+
model_subfolder = "/".join(parts[:-1])
|
| 136 |
+
break # เอาอันแรกที่เจอก็พอ
|
| 137 |
+
|
| 138 |
+
# 3. โหลดไฟล์ตาม path ที่ได้
|
| 139 |
+
if model_subfolder:
|
| 140 |
+
model_path = hf_hub_download(repo_id=repid, filename=filename, subfolder=model_subfolder)
|
| 141 |
+
config_path = hf_hub_download(repo_id=repid, filename="config.json", subfolder=model_subfolder)
|
| 142 |
+
else:
|
| 143 |
+
model_path = hf_hub_download(repo_id=repid, filename=filename)
|
| 144 |
+
config_path = hf_hub_download(repo_id=repid, filename="config.json")
|
| 145 |
hps = utils.get_hparams_from_file(config_path)
|
| 146 |
version = hps.version if hasattr(hps, "version") else "v2"
|
| 147 |
net_g = get_net_g(model_path, version, device, hps)
|