Spaces:
Sleeping
Sleeping
File size: 7,104 Bytes
c69a03e 2d8248e cc77a88 2d8248e fcce4bb c69a03e fcce4bb c69a03e 2d8248e 4490b3f 2d8248e c69a03e 2d8248e c69a03e fcce4bb 2d8248e c69a03e fcce4bb c69a03e fcce4bb c69a03e fcce4bb fc903d0 fcce4bb 7999e78 fcce4bb 2d8248e fcce4bb c69a03e fcce4bb 2d8248e 4490b3f 7999e78 4490b3f fc903d0 4490b3f fcce4bb 2d8248e c69a03e fcce4bb c69a03e fcce4bb 2d8248e c69a03e 2d8248e c69a03e fcce4bb 2d8248e fcce4bb 4490b3f fc903d0 fcce4bb 7999e78 4490b3f 7999e78 4490b3f 7999e78 2d8248e fc903d0 4490b3f fc903d0 7999e78 4490b3f fc903d0 4490b3f 7999e78 4490b3f 7999e78 fc903d0 4490b3f 7999e78 4490b3f fcce4bb 2d8248e fc903d0 7999e78 fc903d0 2d8248e c69a03e 4490b3f fcce4bb c69a03e fcce4bb c69a03e fc903d0 fcce4bb 2d8248e fcce4bb fc903d0 fcce4bb 2d8248e fcce4bb 2d8248e fcce4bb e45c809 2d8248e c69a03e fcce4bb c69a03e fcce4bb c69a03e fcce4bb c69a03e cc77a88 | 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | /*
* 获取已加载模型信息
* */
$(document).ready(function () {
get_models_info();
get_model_to_load();
$("#save-current-model").click(function () {
save_current_model();
});
}
);
function get_models_info() {
$.ajax({
url: '/admin/get_models_info',
type: 'GET',
dataType: 'json',
contentType: 'application/json',
success: function (response) {
var model_list = response;
show_model(model_list);
}
});
}
var modelTypes = {
'VITS': $('#VITS'),
'HUBERT-VITS': $('#HUBERT-VITS'),
'W2V2-VITS': $('#W2V2-VITS'),
'BERT-VITS2': $('#BERT-VITS2'),
'GPT-SOVITS': $('#GPT-SOVITS')
};
function show_model(model_list) {
for (var modelType in modelTypes) {
modelTypes[modelType].empty();
modelTypes[modelType].prev('label').remove();
}
for (var model_type in model_list) {
if (model_list[model_type].length > 0) {
var model_datas = model_list[model_type];
var label = $('<label></label>').text(model_type);
modelTypes[model_type].before(label);
$.each(model_datas, function (key, model_data) {
renderModelCard(model_data, model_type);
});
}
}
}
function renderModelCard(model_data, model_type) {
var id = String(model_data["model_id"]);
var vits_path = String(model_data["vits_path"]);
var n_speakers = String(model_data["n_speakers"]);
var t2s_path = String(model_data["t2s_path"]);
var card = $('<div></div>').addClass("card model-card " + model_type).attr({
"data-model-type": model_type,
"data-model-id": id
});
var wrap = $('<div></div>').addClass("wrap");
// $('<div></div>').text("id: " + id).appendTo(wrap);
if (model_type == "GPT-SOVITS") {
$('<div></div>').text(vits_path).addClass("model-card-info1").appendTo(wrap);
$('<div></div>').text(t2s_path).addClass("model-card-info3").appendTo(wrap);
$('<div></div>').text("x").addClass("unload-model").appendTo(wrap);
} else {
$('<div></div>').text(vits_path).addClass("model-card-info1").appendTo(wrap);
$('<div></div>').text("n_speakers: " + n_speakers).addClass("model-card-info2").appendTo(wrap);
$('<div></div>').text("x").addClass("unload-model").appendTo(wrap);
}
card.append(wrap);
modelTypes[model_type].append(card);
}
/*
* 获取项目模型目录下的模型与配置文件路径
* */
var modelLoadContent = $('.model-load-content');
var isRequestInProgress = false;
function get_model_to_load() {
$.get('/admin/get_path', function (response) {
var model_datas = response;
renderModelLoadCards(model_datas);
});
}
function renderModelLoadCards(data) {
modelLoadContent.empty();
$.each(data, function (index, model) {
var card = $('<div></div>').addClass('model-load-item flex');
var model_id = model.model_id;
var model_type = model.model_type;
var vits_path = model.vits_path;
var config_path = model.config_path;
var t2s_path = model.t2s_path;
var folder = null;
var vits_name = null;
var config_name = null;
var t2s_name = null;
$('<div></div>').text(model_id.toString()).addClass("unload-model-id").appendTo(card);
$('<div></div>').text(model_type).addClass("unload-model-type").appendTo(card);
if (vits_path != null && config_path != null) {
folder = vits_path.split("/")[0];
vits_name = vits_path.split("/")[1];
config_name = config_path.split("/")[1];
$('<div></div>').text(folder).addClass("unload-model-folder").appendTo(card);
$('<div></div>').text(vits_name).addClass("unload-vits-path model1").appendTo(card);
$('<div></div>').text(config_name).addClass("unload-vits-config model2").appendTo(card);
} else {
folder = vits_path.split("/")[0];
vits_name = vits_path.split("/")[1];
t2s_name = t2s_path.split("/")[1];
$('<div></div>').text(folder).addClass("unload-model-folder").appendTo(card);
$('<div></div>').text(vits_name).addClass("unload-vits-path model1").appendTo(card);
$('<div></div>').text(t2s_name).addClass("unload-t2s-config model2").appendTo(card);
}
card.on('click', function () {
if (!isRequestInProgress) {
isRequestInProgress = true;
let tts_model = {};
if (model_type == "GPT-SOVITS") {
tts_model = {
model_type: model_type,
t2s_path: t2s_path,
vits_path: vits_path
}
} else {
tts_model = {
model_type: model_type,
vits_path: vits_path,
config_path: config_path
}
}
loadModel(card, tts_model);
}
});
modelLoadContent.append(card);
});
}
/*
* 加载模型
* */
function loadModel(card, tts_model) {
var csrftoken = $('meta[name="csrf-token"]').attr('content');
$.ajax({
url: '/admin/load_model',
type: 'POST',
contentType: 'application/json',
headers: {
'X-CSRFToken': csrftoken
},
data: JSON.stringify(tts_model),
success: function (response) {
card.fadeOut();
get_models_info();
isRequestInProgress = false;
},
error: function (response) {
alert("Model loading failed!");
isRequestInProgress = false;
}
});
}
/*
* 卸载模型
* */
$('#model-data').on('click', '.unload-model', function (event) {
var cardElement = $(event.target).closest('.card');
var modelType = cardElement.attr('data-model-type');
var modelId = cardElement.attr('data-model-id');
var params = {
"model_type": modelType,
"model_id": modelId
};
$.ajax({
url: '/admin/unload_model',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(params),
headers: {
'X-CSRFToken': $('meta[name="csrf-token"]').attr('content')
},
success: function (response) {
get_models_info();
},
error: function (response) {
alert("Unload model failed!");
}
});
});
function save_current_model() {
$.ajax({
url: '/admin/save_current_model',
type: 'POST',
headers: {
'X-CSRFToken': $('meta[name="csrf-token"]').attr('content')
},
success: function (response) {
alert("当前已加载的模型已保存,下次启动将自动加载。");
},
error: function (response) {
alert("保存失败!");
}
});
}
|