Update core.py
Browse files
core.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import sys
|
3 |
import json
|
4 |
import argparse
|
@@ -50,6 +51,7 @@ def get_config():
|
|
50 |
|
51 |
|
52 |
# Infer
|
|
|
53 |
def run_infer_script(
|
54 |
pitch: int,
|
55 |
filter_radius: int,
|
@@ -101,6 +103,7 @@ def run_infer_script(
|
|
101 |
|
102 |
|
103 |
# Batch infer
|
|
|
104 |
def run_batch_infer_script(
|
105 |
pitch: int,
|
106 |
filter_radius: int,
|
@@ -167,6 +170,7 @@ def run_batch_infer_script(
|
|
167 |
|
168 |
|
169 |
# TTS
|
|
|
170 |
def run_tts_script(
|
171 |
tts_text: str,
|
172 |
tts_voice: str,
|
@@ -242,6 +246,7 @@ def run_tts_script(
|
|
242 |
|
243 |
|
244 |
# Preprocess
|
|
|
245 |
def run_preprocess_script(
|
246 |
model_name: str, dataset_path: str, sample_rate: int, cpu_cores: int
|
247 |
):
|
@@ -268,6 +273,7 @@ def run_preprocess_script(
|
|
268 |
|
269 |
|
270 |
# Extract
|
|
|
271 |
def run_extract_script(
|
272 |
model_name: str,
|
273 |
rvc_version: str,
|
@@ -280,13 +286,16 @@ def run_extract_script(
|
|
280 |
embedder_model: str,
|
281 |
embedder_model_custom: str = None,
|
282 |
):
|
283 |
-
|
284 |
model_path = os.path.join(logs_path, model_name)
|
285 |
-
|
|
|
|
|
|
|
286 |
|
287 |
command_1 = [
|
288 |
python,
|
289 |
-
|
290 |
*map(
|
291 |
str,
|
292 |
[
|
@@ -295,14 +304,26 @@ def run_extract_script(
|
|
295 |
hop_length,
|
296 |
cpu_cores,
|
297 |
gpu,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
rvc_version,
|
|
|
299 |
embedder_model,
|
300 |
embedder_model_custom,
|
301 |
],
|
302 |
),
|
303 |
]
|
304 |
-
|
305 |
subprocess.run(command_1)
|
|
|
306 |
|
307 |
generate_config(rvc_version, sample_rate, model_path)
|
308 |
generate_filelist(pitch_guidance, model_path, rvc_version, sample_rate)
|
@@ -310,6 +331,7 @@ def run_extract_script(
|
|
310 |
|
311 |
|
312 |
# Train
|
|
|
313 |
def run_train_script(
|
314 |
model_name: str,
|
315 |
rvc_version: str,
|
@@ -325,7 +347,6 @@ def run_train_script(
|
|
325 |
overtraining_threshold: int,
|
326 |
pretrained: bool,
|
327 |
sync_graph: bool,
|
328 |
-
index_algorithm: str,
|
329 |
cache_data_in_gpu: bool,
|
330 |
custom_pretrained: bool = False,
|
331 |
g_pretrained_path: str = None,
|
@@ -375,19 +396,19 @@ def run_train_script(
|
|
375 |
),
|
376 |
]
|
377 |
subprocess.run(command)
|
378 |
-
run_index_script(model_name, rvc_version
|
379 |
return f"Model {model_name} trained successfully."
|
380 |
|
381 |
|
382 |
# Index
|
383 |
-
|
|
|
384 |
index_script_path = os.path.join("rvc", "train", "process", "extract_index.py")
|
385 |
command = [
|
386 |
python,
|
387 |
index_script_path,
|
388 |
os.path.join(logs_path, model_name),
|
389 |
rvc_version,
|
390 |
-
index_algorithm,
|
391 |
]
|
392 |
|
393 |
subprocess.run(command)
|
@@ -395,6 +416,7 @@ def run_index_script(model_name: str, rvc_version: str, index_algorithm: str):
|
|
395 |
|
396 |
|
397 |
# Model extract
|
|
|
398 |
def run_model_extract_script(
|
399 |
pth_path: str,
|
400 |
model_name: str,
|
@@ -411,6 +433,7 @@ def run_model_extract_script(
|
|
411 |
|
412 |
|
413 |
# Model information
|
|
|
414 |
def run_model_information_script(pth_path: str):
|
415 |
print(model_information(pth_path))
|
416 |
|
@@ -424,6 +447,7 @@ def run_model_blender_script(
|
|
424 |
|
425 |
|
426 |
# Tensorboard
|
|
|
427 |
def run_tensorboard_script():
|
428 |
launch_tensorboard_pipeline()
|
429 |
|
@@ -1193,14 +1217,6 @@ def parse_arguments():
|
|
1193 |
choices=["v1", "v2"],
|
1194 |
default="v2",
|
1195 |
)
|
1196 |
-
index_parser.add_argument(
|
1197 |
-
"--index_algorithm",
|
1198 |
-
type=str,
|
1199 |
-
choices=["Auto", "Faiss", "KMeans"],
|
1200 |
-
help="Choose the method for generating the index file.",
|
1201 |
-
default="Auto",
|
1202 |
-
required=False,
|
1203 |
-
)
|
1204 |
|
1205 |
# Parser for 'model_extract' mode
|
1206 |
model_extract_parser = subparsers.add_parser(
|
@@ -1473,7 +1489,6 @@ def main():
|
|
1473 |
run_index_script(
|
1474 |
model_name=args.model_name,
|
1475 |
rvc_version=args.rvc_version,
|
1476 |
-
index_algorithm=args.index_algorithm,
|
1477 |
)
|
1478 |
elif args.mode == "model_extract":
|
1479 |
run_model_extract_script(
|
@@ -1527,4 +1542,4 @@ def main():
|
|
1527 |
|
1528 |
|
1529 |
if __name__ == "__main__":
|
1530 |
-
main()
|
|
|
1 |
import os
|
2 |
+
import spaces
|
3 |
import sys
|
4 |
import json
|
5 |
import argparse
|
|
|
51 |
|
52 |
|
53 |
# Infer
|
54 |
+
@spaces.GPU(duration=120)
|
55 |
def run_infer_script(
|
56 |
pitch: int,
|
57 |
filter_radius: int,
|
|
|
103 |
|
104 |
|
105 |
# Batch infer
|
106 |
+
@spaces.GPU(duration=200)
|
107 |
def run_batch_infer_script(
|
108 |
pitch: int,
|
109 |
filter_radius: int,
|
|
|
170 |
|
171 |
|
172 |
# TTS
|
173 |
+
@spaces.GPU(duration=120)
|
174 |
def run_tts_script(
|
175 |
tts_text: str,
|
176 |
tts_voice: str,
|
|
|
246 |
|
247 |
|
248 |
# Preprocess
|
249 |
+
@spaces.GPU(duration=360)
|
250 |
def run_preprocess_script(
|
251 |
model_name: str, dataset_path: str, sample_rate: int, cpu_cores: int
|
252 |
):
|
|
|
273 |
|
274 |
|
275 |
# Extract
|
276 |
+
@spaces.GPU(duration=360)
|
277 |
def run_extract_script(
|
278 |
model_name: str,
|
279 |
rvc_version: str,
|
|
|
286 |
embedder_model: str,
|
287 |
embedder_model_custom: str = None,
|
288 |
):
|
289 |
+
config = get_config()
|
290 |
model_path = os.path.join(logs_path, model_name)
|
291 |
+
pitch_extractor = os.path.join("rvc", "train", "extract", "pitch_extractor.py")
|
292 |
+
embedding_extractor = os.path.join(
|
293 |
+
"rvc", "train", "extract", "embedding_extractor.py"
|
294 |
+
)
|
295 |
|
296 |
command_1 = [
|
297 |
python,
|
298 |
+
pitch_extractor,
|
299 |
*map(
|
300 |
str,
|
301 |
[
|
|
|
304 |
hop_length,
|
305 |
cpu_cores,
|
306 |
gpu,
|
307 |
+
],
|
308 |
+
),
|
309 |
+
]
|
310 |
+
|
311 |
+
command_2 = [
|
312 |
+
python,
|
313 |
+
embedding_extractor,
|
314 |
+
*map(
|
315 |
+
str,
|
316 |
+
[
|
317 |
+
model_path,
|
318 |
rvc_version,
|
319 |
+
gpu,
|
320 |
embedder_model,
|
321 |
embedder_model_custom,
|
322 |
],
|
323 |
),
|
324 |
]
|
|
|
325 |
subprocess.run(command_1)
|
326 |
+
subprocess.run(command_2)
|
327 |
|
328 |
generate_config(rvc_version, sample_rate, model_path)
|
329 |
generate_filelist(pitch_guidance, model_path, rvc_version, sample_rate)
|
|
|
331 |
|
332 |
|
333 |
# Train
|
334 |
+
@spaces.GPU(duration=360)
|
335 |
def run_train_script(
|
336 |
model_name: str,
|
337 |
rvc_version: str,
|
|
|
347 |
overtraining_threshold: int,
|
348 |
pretrained: bool,
|
349 |
sync_graph: bool,
|
|
|
350 |
cache_data_in_gpu: bool,
|
351 |
custom_pretrained: bool = False,
|
352 |
g_pretrained_path: str = None,
|
|
|
396 |
),
|
397 |
]
|
398 |
subprocess.run(command)
|
399 |
+
run_index_script(model_name, rvc_version)
|
400 |
return f"Model {model_name} trained successfully."
|
401 |
|
402 |
|
403 |
# Index
|
404 |
+
@spaces.GPU
|
405 |
+
def run_index_script(model_name: str, rvc_version: str):
|
406 |
index_script_path = os.path.join("rvc", "train", "process", "extract_index.py")
|
407 |
command = [
|
408 |
python,
|
409 |
index_script_path,
|
410 |
os.path.join(logs_path, model_name),
|
411 |
rvc_version,
|
|
|
412 |
]
|
413 |
|
414 |
subprocess.run(command)
|
|
|
416 |
|
417 |
|
418 |
# Model extract
|
419 |
+
@spaces.GPU
|
420 |
def run_model_extract_script(
|
421 |
pth_path: str,
|
422 |
model_name: str,
|
|
|
433 |
|
434 |
|
435 |
# Model information
|
436 |
+
@spaces.GPU
|
437 |
def run_model_information_script(pth_path: str):
|
438 |
print(model_information(pth_path))
|
439 |
|
|
|
447 |
|
448 |
|
449 |
# Tensorboard
|
450 |
+
@spaces.GPU
|
451 |
def run_tensorboard_script():
|
452 |
launch_tensorboard_pipeline()
|
453 |
|
|
|
1217 |
choices=["v1", "v2"],
|
1218 |
default="v2",
|
1219 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1220 |
|
1221 |
# Parser for 'model_extract' mode
|
1222 |
model_extract_parser = subparsers.add_parser(
|
|
|
1489 |
run_index_script(
|
1490 |
model_name=args.model_name,
|
1491 |
rvc_version=args.rvc_version,
|
|
|
1492 |
)
|
1493 |
elif args.mode == "model_extract":
|
1494 |
run_model_extract_script(
|
|
|
1542 |
|
1543 |
|
1544 |
if __name__ == "__main__":
|
1545 |
+
main()
|