Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import os
|
2 |
import sys
|
3 |
# to avoid the modified user.pth file
|
4 |
-
cnhubert_base_path = "GPT_SoVITS
|
5 |
-
bert_path = "GPT_SoVITS
|
6 |
os.environ["version"] = 'v2'
|
7 |
now_dir = os.path.dirname(os.path.abspath(__file__)) # 当前脚本所在目录
|
8 |
sys.path.insert(0, now_dir)
|
@@ -44,26 +44,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
44 |
#device = "cpu"
|
45 |
is_half = False
|
46 |
|
47 |
-
|
48 |
-
bert_model=AutoModelForMaskedLM.from_pretrained(bert_path)
|
49 |
-
if(is_half==True):bert_model=bert_model.half().to(device)
|
50 |
-
else:bert_model=bert_model.to(device)
|
51 |
-
# bert_model=bert_model.to(device)
|
52 |
-
def get_bert_feature(text, word2ph): # Bert(不是HuBERT的特征计算)
|
53 |
-
with torch.no_grad():
|
54 |
-
inputs = tokenizer(text, return_tensors="pt")
|
55 |
-
for i in inputs:
|
56 |
-
inputs[i] = inputs[i].to(device)#####输入是long不用管精度问题,精度随bert_model
|
57 |
-
res = bert_model(**inputs, output_hidden_states=True)
|
58 |
-
res = torch.cat(res["hidden_states"][-3:-2], -1)[0].cpu()[1:-1]
|
59 |
-
assert len(word2ph) == len(text)
|
60 |
-
phone_level_feature = []
|
61 |
-
for i in range(len(word2ph)):
|
62 |
-
repeat_feature = res[i].repeat(word2ph[i], 1)
|
63 |
-
phone_level_feature.append(repeat_feature)
|
64 |
-
phone_level_feature = torch.cat(phone_level_feature, dim=0)
|
65 |
-
# if(is_half==True):phone_level_feature=phone_level_feature.half()
|
66 |
-
return phone_level_feature.T
|
67 |
|
68 |
loaded_sovits_model = [] # [(path, dict, model)]
|
69 |
loaded_gpt_model = []
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
# to avoid the modified user.pth file
|
4 |
+
cnhubert_base_path = "GPT_SoVITS/pretrained_models/chinese-hubert-base"
|
5 |
+
bert_path = "GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large"
|
6 |
os.environ["version"] = 'v2'
|
7 |
now_dir = os.path.dirname(os.path.abspath(__file__)) # 当前脚本所在目录
|
8 |
sys.path.insert(0, now_dir)
|
|
|
44 |
#device = "cpu"
|
45 |
is_half = False
|
46 |
|
47 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
loaded_sovits_model = [] # [(path, dict, model)]
|
50 |
loaded_gpt_model = []
|