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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from original import *
|
2 |
+
|
3 |
+
import shutil, glob, subprocess
|
4 |
+
|
5 |
+
from easyfuncs import download_from_url, CachedModels, whisperspeak, whisperspeak_on, stereo_process, sr_process
|
6 |
+
|
7 |
+
os.makedirs("dataset",exist_ok=True)
|
8 |
+
|
9 |
+
os.makedirs("audios",exist_ok=True)
|
10 |
+
|
11 |
+
model_library = CachedModels()
|
12 |
+
|
13 |
+
subprocess.run(["python", "download_files.py"]) #in case you need the models still
|
14 |
+
|
15 |
+
with gr.Blocks(title="🔊 Nex RVC Mobile",theme=gr.themes.Base()) as app:
|
16 |
+
|
17 |
+
gr.Markdown("# Nex RVC MOBILE GUI")
|
18 |
+
with gr.Tabs():
|
19 |
+
voice_model = gr.Dropdown(label="AI Voice", choices=sorted(names), value=lambda:sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True)
|
20 |
+
|
21 |
+
refresh_button = gr.Button("Search Again", variant="primary")
|
22 |
+
|
23 |
+
|
24 |
+
with gr.TabItem("Inference"):
|
25 |
+
|
26 |
+
with gr.Row():
|
27 |
+
|
28 |
+
|
29 |
+
spk_item = gr.Slider(
|
30 |
+
|
31 |
+
minimum=0,
|
32 |
+
|
33 |
+
maximum=2333,
|
34 |
+
|
35 |
+
step=1,
|
36 |
+
|
37 |
+
label="Speaker ID",
|
38 |
+
|
39 |
+
value=0,
|
40 |
+
|
41 |
+
visible=False,
|
42 |
+
|
43 |
+
interactive=True,
|
44 |
+
|
45 |
+
)
|
46 |
+
|
47 |
+
vc_transform0 = gr.Number(
|
48 |
+
|
49 |
+
label="Pitch",
|
50 |
+
|
51 |
+
value=0
|
52 |
+
|
53 |
+
)
|
54 |
+
|
55 |
+
but0 = gr.Button(value="Convert", variant="primary")
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
|
59 |
+
with gr.Column():
|
60 |
+
|
61 |
+
with gr.Tabs():
|
62 |
+
|
63 |
+
with gr.TabItem("Upload"):
|
64 |
+
|
65 |
+
dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
|
66 |
+
|
67 |
+
with gr.TabItem("Record"):
|
68 |
+
|
69 |
+
record_button=gr.Microphone(label="OR Record audio.", type="filepath")
|
70 |
+
|
71 |
+
with gr.TabItem("TTS (experimental)", visible=False):
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
|
75 |
+
tts_text = gr.Textbox(label="Text to Speech", placeholder="Enter text to convert to speech")
|
76 |
+
|
77 |
+
with gr.Row():
|
78 |
+
|
79 |
+
tts_lang = gr.Radio(choices=["en","es","it","pt"],label="",value="en")
|
80 |
+
|
81 |
+
with gr.Row():
|
82 |
+
|
83 |
+
tts_button = gr.Button(value="Speak", variant="primary")
|
84 |
+
|
85 |
+
with gr.Row():
|
86 |
+
|
87 |
+
paths_for_files = lambda path:[os.path.abspath(os.path.join(path, f)) for f in os.listdir(path) if os.path.splitext(f)[1].lower() in ('.mp3', '.wav', '.flac', '.ogg')]
|
88 |
+
|
89 |
+
input_audio0 = gr.Dropdown(
|
90 |
+
|
91 |
+
label="Input Path",
|
92 |
+
|
93 |
+
value=paths_for_files('audios')[0] if len(paths_for_files('audios')) > 0 else '',
|
94 |
+
|
95 |
+
choices=paths_for_files('audios'), # Only show absolute paths for audio files ending in .mp3, .wav, .flac or .ogg
|
96 |
+
|
97 |
+
allow_custom_value=True
|
98 |
+
|
99 |
+
)
|
100 |
+
|
101 |
+
with gr.Row():
|
102 |
+
|
103 |
+
input_player = gr.Audio(label="Input",type="numpy",interactive=False)
|
104 |
+
|
105 |
+
input_audio0.change(
|
106 |
+
|
107 |
+
inputs=[input_audio0],
|
108 |
+
|
109 |
+
outputs=[input_player],
|
110 |
+
|
111 |
+
fn=lambda path: {"value":path,"__type__":"update"} if os.path.exists(path) else None
|
112 |
+
|
113 |
+
)
|
114 |
+
|
115 |
+
record_button.stop_recording(
|
116 |
+
|
117 |
+
fn=lambda audio:audio, #TODO save wav lambda
|
118 |
+
|
119 |
+
inputs=[record_button],
|
120 |
+
|
121 |
+
outputs=[input_audio0])
|
122 |
+
|
123 |
+
dropbox.upload(
|
124 |
+
|
125 |
+
fn=lambda audio:audio.name,
|
126 |
+
|
127 |
+
inputs=[dropbox],
|
128 |
+
|
129 |
+
outputs=[input_audio0])
|
130 |
+
|
131 |
+
tts_button.click(
|
132 |
+
|
133 |
+
fn=whisperspeak,
|
134 |
+
|
135 |
+
inputs=[tts_text,tts_lang],
|
136 |
+
|
137 |
+
outputs=[input_audio0],
|
138 |
+
|
139 |
+
show_progress=True)
|
140 |
+
|
141 |
+
tts_button.click(
|
142 |
+
|
143 |
+
fn=lambda: {"choices":paths_for_files('audios'),"__type__":"update"},
|
144 |
+
|
145 |
+
inputs=[],
|
146 |
+
|
147 |
+
outputs=[input_audio0])
|
148 |
+
|
149 |
+
with gr.Column():
|
150 |
+
|
151 |
+
with gr.Accordion("Change Index", open=False):
|
152 |
+
|
153 |
+
file_index2 = gr.Dropdown(
|
154 |
+
|
155 |
+
label="Change Index",
|
156 |
+
|
157 |
+
choices=sorted(index_paths),
|
158 |
+
|
159 |
+
interactive=True,
|
160 |
+
|
161 |
+
value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else ''
|
162 |
+
|
163 |
+
)
|
164 |
+
|
165 |
+
index_rate1 = gr.Slider(
|
166 |
+
|
167 |
+
minimum=0,
|
168 |
+
|
169 |
+
maximum=1,
|
170 |
+
|
171 |
+
label="Index Strength",
|
172 |
+
|
173 |
+
value=0.5,
|
174 |
+
|
175 |
+
interactive=True,
|
176 |
+
|
177 |
+
)
|
178 |
+
|
179 |
+
output_player = gr.Audio(label="Output",interactive=False)
|
180 |
+
|
181 |
+
with gr.Accordion("General Settings", open=False):
|
182 |
+
|
183 |
+
f0method0 = gr.Radio(
|
184 |
+
|
185 |
+
label="Method",
|
186 |
+
|
187 |
+
choices=["pm"],
|
188 |
+
|
189 |
+
value="pm",
|
190 |
+
|
191 |
+
interactive=False,
|
192 |
+
|
193 |
+
visible=False,
|
194 |
+
|
195 |
+
)
|
196 |
+
|
197 |
+
filter_radius0 = gr.Slider(
|
198 |
+
|
199 |
+
minimum=0,
|
200 |
+
|
201 |
+
maximum=7,
|
202 |
+
|
203 |
+
label="Breathiness Reduction (Harvest only)",
|
204 |
+
|
205 |
+
value=3,
|
206 |
+
|
207 |
+
step=1,
|
208 |
+
|
209 |
+
interactive=True,
|
210 |
+
|
211 |
+
)
|
212 |
+
|
213 |
+
resample_sr0 = gr.Slider(
|
214 |
+
|
215 |
+
minimum=0,
|
216 |
+
|
217 |
+
maximum=48000,
|
218 |
+
|
219 |
+
label="Resample",
|
220 |
+
|
221 |
+
value=0,
|
222 |
+
|
223 |
+
step=1,
|
224 |
+
|
225 |
+
interactive=True,
|
226 |
+
|
227 |
+
visible=False
|
228 |
+
|
229 |
+
)
|
230 |
+
|
231 |
+
rms_mix_rate0 = gr.Slider(
|
232 |
+
|
233 |
+
minimum=0,
|
234 |
+
|
235 |
+
maximum=1,
|
236 |
+
|
237 |
+
label="Volume Normalization",
|
238 |
+
|
239 |
+
value=0,
|
240 |
+
|
241 |
+
interactive=True,
|
242 |
+
|
243 |
+
)
|
244 |
+
|
245 |
+
protect0 = gr.Slider(
|
246 |
+
|
247 |
+
minimum=0,
|
248 |
+
|
249 |
+
maximum=0.5,
|
250 |
+
|
251 |
+
label="Breathiness Protection (0 is enabled, 0.5 is disabled)",
|
252 |
+
|
253 |
+
value=0.33,
|
254 |
+
|
255 |
+
step=0.01,
|
256 |
+
|
257 |
+
interactive=True,
|
258 |
+
|
259 |
+
)
|
260 |
+
|
261 |
+
if voice_model != None:
|
262 |
+
|
263 |
+
try: vc.get_vc(voice_model.value,protect0,protect0) #load the model immediately for faster inference
|
264 |
+
|
265 |
+
except: pass
|
266 |
+
|
267 |
+
with gr.Accordion("Processing Tools (Experimental)", open=True, visible=False):
|
268 |
+
|
269 |
+
audio_choice = gr.Radio(choices=["Input", "Output"], value="Output", label="Source",interactive=True)
|
270 |
+
|
271 |
+
with gr.Column():
|
272 |
+
|
273 |
+
stereo_button = gr.Button(value="Stereo", variant="primary")
|
274 |
+
|
275 |
+
stereo_button.click(
|
276 |
+
|
277 |
+
fn=stereo_process,
|
278 |
+
|
279 |
+
inputs=[input_player,output_player,audio_choice],
|
280 |
+
|
281 |
+
outputs=[output_player],
|
282 |
+
|
283 |
+
preprocess=True,
|
284 |
+
|
285 |
+
)
|
286 |
+
|
287 |
+
with gr.Column():
|
288 |
+
|
289 |
+
sr_button = gr.Button(value="SuperResolution", variant="primary", visible=False)
|
290 |
+
|
291 |
+
sr_button.click(
|
292 |
+
|
293 |
+
fn=sr_process,
|
294 |
+
|
295 |
+
inputs=[input_player,output_player,audio_choice],
|
296 |
+
|
297 |
+
outputs=[output_player],
|
298 |
+
|
299 |
+
preprocess=True,
|
300 |
+
|
301 |
+
)
|
302 |
+
|
303 |
+
file_index1 = gr.Textbox(
|
304 |
+
|
305 |
+
label="Index Path",
|
306 |
+
|
307 |
+
interactive=True,
|
308 |
+
|
309 |
+
visible=False#Not used here
|
310 |
+
|
311 |
+
)
|
312 |
+
|
313 |
+
refresh_button.click(
|
314 |
+
|
315 |
+
fn=change_choices,
|
316 |
+
|
317 |
+
inputs=[],
|
318 |
+
|
319 |
+
outputs=[voice_model, file_index2],
|
320 |
+
|
321 |
+
api_name="infer_refresh",
|
322 |
+
|
323 |
+
)
|
324 |
+
|
325 |
+
refresh_button.click(
|
326 |
+
|
327 |
+
fn=lambda:{"choices":paths_for_files('audios'),"__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
|
328 |
+
|
329 |
+
inputs=[],
|
330 |
+
|
331 |
+
outputs = [input_audio0],
|
332 |
+
|
333 |
+
)
|
334 |
+
|
335 |
+
refresh_button.click(
|
336 |
+
|
337 |
+
fn=lambda:{"value":paths_for_files('audios')[0],"__type__":"update"} if len(paths_for_files('audios')) > 0 else {"value":"","__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
|
338 |
+
|
339 |
+
inputs=[],
|
340 |
+
|
341 |
+
outputs = [input_audio0],
|
342 |
+
|
343 |
+
)
|
344 |
+
|
345 |
+
with gr.Row():
|
346 |
+
|
347 |
+
f0_file = gr.File(label="F0 Path", visible=False)
|
348 |
+
|
349 |
+
with gr.Row():
|
350 |
+
|
351 |
+
vc_output1 = gr.Textbox(label="Information", placeholder="Welcome!",visible=False)
|
352 |
+
|
353 |
+
but0.click(
|
354 |
+
|
355 |
+
vc.vc_single,
|
356 |
+
|
357 |
+
[
|
358 |
+
|
359 |
+
spk_item,
|
360 |
+
|
361 |
+
input_audio0,
|
362 |
+
|
363 |
+
vc_transform0,
|
364 |
+
|
365 |
+
f0_file,
|
366 |
+
|
367 |
+
f0method0,
|
368 |
+
|
369 |
+
file_index1,
|
370 |
+
|
371 |
+
file_index2,
|
372 |
+
|
373 |
+
index_rate1,
|
374 |
+
|
375 |
+
filter_radius0,
|
376 |
+
|
377 |
+
resample_sr0,
|
378 |
+
|
379 |
+
rms_mix_rate0,
|
380 |
+
|
381 |
+
protect0,
|
382 |
+
|
383 |
+
],
|
384 |
+
|
385 |
+
[vc_output1, output_player],
|
386 |
+
|
387 |
+
api_name="infer_convert",
|
388 |
+
|
389 |
+
)
|
390 |
+
|
391 |
+
voice_model.change(
|
392 |
+
|
393 |
+
fn=vc.get_vc,
|
394 |
+
|
395 |
+
inputs=[voice_model, protect0, protect0],
|
396 |
+
|
397 |
+
outputs=[spk_item, protect0, protect0, file_index2, file_index2],
|
398 |
+
|
399 |
+
api_name="infer_change_voice",
|
400 |
+
|
401 |
+
)
|
402 |
+
|
403 |
+
with gr.TabItem("Download Models"):
|
404 |
+
|
405 |
+
with gr.Row():
|
406 |
+
|
407 |
+
url_input = gr.Textbox(label="URL to model (i.e. from huggingface)", value="",placeholder="https://...", scale=6)
|
408 |
+
|
409 |
+
name_output = gr.Textbox(label="Save as (if from hf, you may leave it blank)", value="",placeholder="MyModel",scale=2)
|
410 |
+
|
411 |
+
url_download = gr.Button(value="Download Model",scale=2)
|
412 |
+
|
413 |
+
url_download.click(
|
414 |
+
|
415 |
+
inputs=[url_input,name_output],
|
416 |
+
|
417 |
+
outputs=[url_input],
|
418 |
+
|
419 |
+
fn=download_from_url,
|
420 |
+
|
421 |
+
)
|
422 |
+
|
423 |
+
with gr.Row():
|
424 |
+
|
425 |
+
model_browser = gr.Dropdown(choices=list(model_library.models.keys()),label="OR Search Models (Quality UNKNOWN)",scale=5)
|
426 |
+
|
427 |
+
download_from_browser = gr.Button(value="Get",scale=2)
|
428 |
+
|
429 |
+
download_from_browser.click(
|
430 |
+
|
431 |
+
inputs=[model_browser],
|
432 |
+
|
433 |
+
outputs=[model_browser],
|
434 |
+
|
435 |
+
fn=lambda model: download_from_url(model_library.models[model],model),
|
436 |
+
|
437 |
+
)
|
438 |
+
|
439 |
+
with gr.TabItem("Train"):
|
440 |
+
|
441 |
+
with gr.Row():
|
442 |
+
|
443 |
+
with gr.Column():
|
444 |
+
|
445 |
+
training_name = gr.Textbox(label="Name your model", value="My-Voice",placeholder="My-Voice")
|
446 |
+
|
447 |
+
np7 = gr.Slider(
|
448 |
+
|
449 |
+
minimum=0,
|
450 |
+
|
451 |
+
maximum=config.n_cpu,
|
452 |
+
|
453 |
+
step=1,
|
454 |
+
|
455 |
+
label="Number of CPU processes used to extract pitch features",
|
456 |
+
|
457 |
+
value=1,
|
458 |
+
|
459 |
+
interactive=False,
|
460 |
+
|
461 |
+
visible=False
|
462 |
+
|
463 |
+
)
|
464 |
+
|
465 |
+
sr2 = gr.Radio(
|
466 |
+
|
467 |
+
label="Sampling Rate",
|
468 |
+
|
469 |
+
choices=["40k", "32k"],
|
470 |
+
|
471 |
+
value="32k",
|
472 |
+
|
473 |
+
interactive=True,
|
474 |
+
|
475 |
+
visible=False
|
476 |
+
|
477 |
+
)
|
478 |
+
|
479 |
+
if_f0_3 = gr.Radio(
|
480 |
+
|
481 |
+
label="Will your model be used for singing? If not, you can ignore this.",
|
482 |
+
|
483 |
+
choices=[True, False],
|
484 |
+
|
485 |
+
value=True,
|
486 |
+
|
487 |
+
interactive=True,
|
488 |
+
|
489 |
+
visible=False
|
490 |
+
|
491 |
+
)
|
492 |
+
|
493 |
+
version19 = gr.Radio(
|
494 |
+
|
495 |
+
label="Version",
|
496 |
+
|
497 |
+
choices=["v1", "v2"],
|
498 |
+
|
499 |
+
value="v2",
|
500 |
+
|
501 |
+
interactive=True,
|
502 |
+
|
503 |
+
visible=False,
|
504 |
+
|
505 |
+
)
|
506 |
+
|
507 |
+
dataset_folder = gr.Textbox(
|
508 |
+
|
509 |
+
label="dataset folder", value='dataset'
|
510 |
+
|
511 |
+
)
|
512 |
+
|
513 |
+
easy_uploader = gr.Files(label="Drop your audio files here",file_types=['audio'])
|
514 |
+
|
515 |
+
but1 = gr.Button("1. Process", variant="primary")
|
516 |
+
|
517 |
+
info1 = gr.Textbox(label="Information", value="",visible=True)
|
518 |
+
|
519 |
+
easy_uploader.upload(inputs=[dataset_folder],outputs=[],fn=lambda folder:os.makedirs(folder,exist_ok=True))
|
520 |
+
|
521 |
+
easy_uploader.upload(
|
522 |
+
|
523 |
+
fn=lambda files,folder: [shutil.copy2(f.name,os.path.join(folder,os.path.split(f.name)[1])) for f in files] if folder != "" else gr.Warning('Please enter a folder name for your dataset'),
|
524 |
+
|
525 |
+
inputs=[easy_uploader, dataset_folder],
|
526 |
+
|
527 |
+
outputs=[])
|
528 |
+
|
529 |
+
gpus6 = gr.Textbox(
|
530 |
+
|
531 |
+
label="Enter the GPU numbers to use separated by -, (e.g. 0-1-2)",
|
532 |
+
|
533 |
+
value="",
|
534 |
+
|
535 |
+
interactive=True,
|
536 |
+
|
537 |
+
visible=False,
|
538 |
+
|
539 |
+
)
|
540 |
+
|
541 |
+
gpu_info9 = gr.Textbox(
|
542 |
+
|
543 |
+
label="GPU Info", value=gpu_info, visible=False
|
544 |
+
|
545 |
+
)
|
546 |
+
|
547 |
+
spk_id5 = gr.Slider(
|
548 |
+
|
549 |
+
minimum=0,
|
550 |
+
|
551 |
+
maximum=4,
|
552 |
+
|
553 |
+
step=1,
|
554 |
+
|
555 |
+
label="Speaker ID",
|
556 |
+
|
557 |
+
value=0,
|
558 |
+
|
559 |
+
interactive=True,
|
560 |
+
|
561 |
+
visible=False
|
562 |
+
|
563 |
+
)
|
564 |
+
|
565 |
+
but1.click(
|
566 |
+
|
567 |
+
preprocess_dataset,
|
568 |
+
|
569 |
+
[dataset_folder, training_name, sr2, np7],
|
570 |
+
|
571 |
+
[info1],
|
572 |
+
|
573 |
+
api_name="train_preprocess",
|
574 |
+
|
575 |
+
)
|
576 |
+
|
577 |
+
with gr.Column():
|
578 |
+
|
579 |
+
f0method8 = gr.Radio(
|
580 |
+
|
581 |
+
label="F0 extraction method",
|
582 |
+
|
583 |
+
choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
|
584 |
+
|
585 |
+
value="pm",
|
586 |
+
|
587 |
+
interactive=False,
|
588 |
+
|
589 |
+
visible=False
|
590 |
+
|
591 |
+
)
|
592 |
+
|
593 |
+
gpus_rmvpe = gr.Textbox(
|
594 |
+
|
595 |
+
label="GPU numbers to use separated by -, (e.g. 0-1-2)",
|
596 |
+
|
597 |
+
value="",
|
598 |
+
|
599 |
+
interactive=False,
|
600 |
+
|
601 |
+
visible=False,
|
602 |
+
|
603 |
+
)
|
604 |
+
|
605 |
+
but2 = gr.Button("2. Extract Features", variant="primary")
|
606 |
+
|
607 |
+
info2 = gr.Textbox(label="Information", value="", max_lines=8)
|
608 |
+
|
609 |
+
f0method8.change(
|
610 |
+
|
611 |
+
fn=change_f0_method,
|
612 |
+
|
613 |
+
inputs=[f0method8],
|
614 |
+
|
615 |
+
outputs=[gpus_rmvpe],
|
616 |
+
|
617 |
+
)
|
618 |
+
|
619 |
+
but2.click(
|
620 |
+
|
621 |
+
extract_f0_feature,
|
622 |
+
|
623 |
+
[
|
624 |
+
|
625 |
+
gpus6,
|
626 |
+
|
627 |
+
np7,
|
628 |
+
|
629 |
+
f0method8,
|
630 |
+
|
631 |
+
if_f0_3,
|
632 |
+
|
633 |
+
training_name,
|
634 |
+
|
635 |
+
version19,
|
636 |
+
|
637 |
+
gpus_rmvpe,
|
638 |
+
|
639 |
+
],
|
640 |
+
|
641 |
+
[info2],
|
642 |
+
|
643 |
+
api_name="train_extract_f0_feature",
|
644 |
+
|
645 |
+
)
|
646 |
+
|
647 |
+
with gr.Column():
|
648 |
+
|
649 |
+
total_epoch11 = gr.Slider(
|
650 |
+
|
651 |
+
minimum=5,
|
652 |
+
|
653 |
+
maximum=1000,
|
654 |
+
|
655 |
+
step=5,
|
656 |
+
|
657 |
+
label="Epochs (more epochs may improve quality but takes longer)",
|
658 |
+
|
659 |
+
value=100,
|
660 |
+
|
661 |
+
interactive=True,
|
662 |
+
|
663 |
+
)
|
664 |
+
|
665 |
+
but4 = gr.Button("3. Train Index", variant="primary")
|
666 |
+
|
667 |
+
but3 = gr.Button("4. Train Model", variant="primary")
|
668 |
+
|
669 |
+
info3 = gr.Textbox(label="Information", value="", max_lines=10)
|
670 |
+
|
671 |
+
with gr.Accordion(label="General Settings", open=False):
|
672 |
+
|
673 |
+
gpus16 = gr.Textbox(
|
674 |
+
|
675 |
+
label="GPUs separated by -, (e.g. 0-1-2)",
|
676 |
+
|
677 |
+
value="0",
|
678 |
+
|
679 |
+
interactive=True,
|
680 |
+
|
681 |
+
visible=False,
|
682 |
+
|
683 |
+
)
|
684 |
+
|
685 |
+
save_epoch10 = gr.Slider(
|
686 |
+
|
687 |
+
minimum=1,
|
688 |
+
|
689 |
+
maximum=50,
|
690 |
+
|
691 |
+
step=1,
|
692 |
+
|
693 |
+
label="Weight Saving Frequency",
|
694 |
+
|
695 |
+
value=25,
|
696 |
+
|
697 |
+
interactive=True,
|
698 |
+
|
699 |
+
visible=False
|
700 |
+
|
701 |
+
)
|
702 |
+
|
703 |
+
batch_size12 = gr.Slider(
|
704 |
+
|
705 |
+
minimum=1,
|
706 |
+
|
707 |
+
maximum=40,
|
708 |
+
|
709 |
+
step=1,
|
710 |
+
|
711 |
+
label="Batch Size",
|
712 |
+
|
713 |
+
value=1,
|
714 |
+
|
715 |
+
interactive=True,
|
716 |
+
|
717 |
+
visible=False
|
718 |
+
|
719 |
+
)
|
720 |
+
|
721 |
+
if_save_latest13 = gr.Radio(
|
722 |
+
|
723 |
+
label="Only save the latest model",
|
724 |
+
|
725 |
+
choices=["yes", "no"],
|
726 |
+
|
727 |
+
value="yes",
|
728 |
+
|
729 |
+
interactive=True,
|
730 |
+
|
731 |
+
visible=False
|
732 |
+
|
733 |
+
)
|
734 |
+
|
735 |
+
if_cache_gpu17 = gr.Radio(
|
736 |
+
|
737 |
+
label="If your dataset is UNDER 10 minutes, cache it to train faster",
|
738 |
+
|
739 |
+
choices=["yes", "no"],
|
740 |
+
|
741 |
+
value="no",
|
742 |
+
|
743 |
+
interactive=True,
|
744 |
+
|
745 |
+
visible=False
|
746 |
+
|
747 |
+
)
|
748 |
+
|
749 |
+
if_save_every_weights18 = gr.Radio(
|
750 |
+
|
751 |
+
label="Save small model at every save point",
|
752 |
+
|
753 |
+
choices=["yes", "no"],
|
754 |
+
|
755 |
+
value="yes",
|
756 |
+
|
757 |
+
interactive=False,
|
758 |
+
|
759 |
+
visible=False
|
760 |
+
|
761 |
+
)
|
762 |
+
|
763 |
+
with gr.Accordion(label="Change pretrains", open=False):
|
764 |
+
|
765 |
+
pretrained = lambda sr, letter: [os.path.abspath(os.path.join('assets/pretrained_v2', file)) for file in os.listdir('assets/pretrained_v2') if file.endswith('.pth') and sr in file and letter in file]
|
766 |
+
|
767 |
+
pretrained_G14 = gr.Dropdown(
|
768 |
+
|
769 |
+
label="pretrained G",
|
770 |
+
|
771 |
+
# Get a list of all pretrained G model files in assets/pretrained_v2 that end with .pth
|
772 |
+
|
773 |
+
choices = pretrained(sr2.value, 'G'),
|
774 |
+
|
775 |
+
value=pretrained(sr2.value, 'G')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
|
776 |
+
|
777 |
+
interactive=True,
|
778 |
+
|
779 |
+
visible=True
|
780 |
+
|
781 |
+
)
|
782 |
+
|
783 |
+
pretrained_D15 = gr.Dropdown(
|
784 |
+
|
785 |
+
label="pretrained D",
|
786 |
+
|
787 |
+
choices = pretrained(sr2.value, 'D'),
|
788 |
+
|
789 |
+
value= pretrained(sr2.value, 'D')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
|
790 |
+
|
791 |
+
visible=True,
|
792 |
+
|
793 |
+
interactive=True
|
794 |
+
|
795 |
+
)
|
796 |
+
|
797 |
+
with gr.Row():
|
798 |
+
|
799 |
+
download_model = gr.Button('5.Download Model')
|
800 |
+
|
801 |
+
with gr.Row():
|
802 |
+
|
803 |
+
model_files = gr.Files(label='Your Model and Index file can be downloaded here:')
|
804 |
+
|
805 |
+
download_model.click(
|
806 |
+
|
807 |
+
fn=lambda name: os.listdir(f'assets/weights/{name}') + glob.glob(f'logs/{name.split(".")[0]}/added_*.index'),
|
808 |
+
|
809 |
+
inputs=[training_name],
|
810 |
+
|
811 |
+
outputs=[model_files, info3])
|
812 |
+
|
813 |
+
with gr.Row():
|
814 |
+
|
815 |
+
sr2.change(
|
816 |
+
|
817 |
+
change_sr2,
|
818 |
+
|
819 |
+
[sr2, if_f0_3, version19],
|
820 |
+
|
821 |
+
[pretrained_G14, pretrained_D15],
|
822 |
+
|
823 |
+
)
|
824 |
+
|
825 |
+
version19.change(
|
826 |
+
|
827 |
+
change_version19,
|
828 |
+
|
829 |
+
[sr2, if_f0_3, version19],
|
830 |
+
|
831 |
+
[pretrained_G14, pretrained_D15, sr2],
|
832 |
+
|
833 |
+
)
|
834 |
+
|
835 |
+
if_f0_3.change(
|
836 |
+
|
837 |
+
change_f0,
|
838 |
+
|
839 |
+
[if_f0_3, sr2, version19],
|
840 |
+
|
841 |
+
[f0method8, pretrained_G14, pretrained_D15],
|
842 |
+
|
843 |
+
)
|
844 |
+
|
845 |
+
with gr.Row():
|
846 |
+
|
847 |
+
but5 = gr.Button("1 Click Training", variant="primary", visible=False)
|
848 |
+
|
849 |
+
but3.click(
|
850 |
+
|
851 |
+
click_train,
|
852 |
+
|
853 |
+
[
|
854 |
+
|
855 |
+
training_name,
|
856 |
+
|
857 |
+
sr2,
|
858 |
+
|
859 |
+
if_f0_3,
|
860 |
+
|
861 |
+
spk_id5,
|
862 |
+
|
863 |
+
save_epoch10,
|
864 |
+
|
865 |
+
total_epoch11,
|
866 |
+
|
867 |
+
batch_size12,
|
868 |
+
|
869 |
+
if_save_latest13,
|
870 |
+
|
871 |
+
pretrained_G14,
|
872 |
+
|
873 |
+
pretrained_D15,
|
874 |
+
|
875 |
+
gpus16,
|
876 |
+
|
877 |
+
if_cache_gpu17,
|
878 |
+
|
879 |
+
if_save_every_weights18,
|
880 |
+
|
881 |
+
version19,
|
882 |
+
|
883 |
+
],
|
884 |
+
|
885 |
+
info3,
|
886 |
+
|
887 |
+
api_name="train_start",
|
888 |
+
|
889 |
+
)
|
890 |
+
|
891 |
+
but4.click(train_index, [training_name, version19], info3)
|
892 |
+
|
893 |
+
but5.click(
|
894 |
+
|
895 |
+
train1key,
|
896 |
+
|
897 |
+
[
|
898 |
+
|
899 |
+
training_name,
|
900 |
+
|
901 |
+
sr2,
|
902 |
+
|
903 |
+
if_f0_3,
|
904 |
+
|
905 |
+
dataset_folder,
|
906 |
+
|
907 |
+
spk_id5,
|
908 |
+
|
909 |
+
np7,
|
910 |
+
|
911 |
+
f0method8,
|
912 |
+
|
913 |
+
save_epoch10,
|
914 |
+
|
915 |
+
total_epoch11,
|
916 |
+
|
917 |
+
batch_size12,
|
918 |
+
|
919 |
+
if_save_latest13,
|
920 |
+
|
921 |
+
pretrained_G14,
|
922 |
+
|
923 |
+
pretrained_D15,
|
924 |
+
|
925 |
+
gpus16,
|
926 |
+
|
927 |
+
if_cache_gpu17,
|
928 |
+
|
929 |
+
if_save_every_weights18,
|
930 |
+
|
931 |
+
version19,
|
932 |
+
|
933 |
+
gpus_rmvpe,
|
934 |
+
|
935 |
+
],
|
936 |
+
|
937 |
+
info3,
|
938 |
+
|
939 |
+
api_name="train_start_all",
|
940 |
+
|
941 |
+
)
|
942 |
+
|
943 |
+
|
944 |
+
|
945 |
+
if config.iscolab:
|
946 |
+
|
947 |
+
app.queue(max_size=20).launch(share=True,allowed_paths=["a.png"],show_error=True)
|
948 |
+
|
949 |
+
else:
|
950 |
+
|
951 |
+
app.queue(max_size=1022).launch(
|
952 |
+
|
953 |
+
server_name="0.0.0.0",
|
954 |
+
|
955 |
+
inbrowser=not config.noautoopen,
|
956 |
+
|
957 |
+
server_port=config.listen_port,
|
958 |
+
|
959 |
+
quiet=True,
|
960 |
+
|
961 |
+
)
|