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
 
 
 
 
 
 
 
 
1
+ from original import *
2
+ import shutil, glob
3
+ import yt_dlp
4
+ import hopsworks
5
+ import subprocess
6
+
7
+ from easyfuncs import download_from_url, CachedModels
8
+ os.makedirs("dataset",exist_ok=True)
9
+ model_library = CachedModels()
10
+
11
+
12
+ def download_audio(url, audio_name):
13
+ ydl_opts = {
14
+ 'format': 'bestaudio/best',
15
+ 'postprocessors': [{
16
+ 'key': 'FFmpegExtractAudio',
17
+ 'preferredcodec': 'mp3',
18
+ 'preferredquality': '192',
19
+ }],
20
+ 'outtmpl': f'audios/{audio_name}',
21
+ }
22
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
23
+ ydl.download([url])
24
+ return "outtmpl"
25
+
26
+
27
+
28
+
29
+
30
+ with gr.Blocks(title="🔊",theme=gr.themes.Base(primary_hue="emerald",neutral_hue="zinc")) as app:
31
+ with gr.Row():
32
+ gr.HTML("<img src='file/a.png' alt='image'>")
33
+ with gr.Tabs():
34
+ with gr.TabItem("Inference"):
35
+ with gr.Row():
36
+ voice_model = gr.Dropdown(label="Model Voice", choices=sorted(names), value=lambda:sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True)
37
+ refresh_button = gr.Button("Refresh", variant="primary")
38
+ spk_item = gr.Slider(
39
+ minimum=0,
40
+ maximum=2333,
41
+ step=1,
42
+ label="Speaker ID",
43
+ value=0,
44
+ visible=False,
45
+ interactive=True,
46
+ )
47
+ vc_transform0 = gr.Number(
48
+ label="Pitch",
49
+ value=0
50
+ )
51
+ but0 = gr.Button(value="Convert", variant="primary")
52
+ with gr.Row():
53
+ with gr.Column():
54
+ with gr.Row():
55
+ url = gr.Textbox(label="url to yotube link.")
56
+ audio_name = gr.Textbox(label="file name.")
57
+ dwnl_button = gr.Button("Download")
58
+ dwnl_button.click(fn=download_audio,inputs=[audio_name],outputs=[url])
59
+
60
+ with gr.Row():
61
+ 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')]
62
+ input_audio0 = gr.Dropdown(
63
+ label="Input Path",
64
+ value=paths_for_files('audios')[0] if len(paths_for_files('audios')) > 0 else '',
65
+ choices=paths_for_files('audios'), # Only show absolute paths for audio files ending in .mp3, .wav, .flac or .ogg
66
+ allow_custom_value=True
67
+ )
68
+ with gr.Row():
69
+ audio_player = gr.Audio()
70
+ input_audio0.change(
71
+ inputs=[input_audio0],
72
+ outputs=[audio_player],
73
+ fn=lambda path: {"value":path,"__type__":"update"} if os.path.exists(path) else None,
74
+ dwnl_button = gr.Button("vocal_remove"),
75
+ dwnl_button.click(fn=vocal_remove,inputs=[input_audio0],outputs=[url])
76
+ )
77
+ with gr.Column():
78
+ with gr.Accordion("Change Index", open=False):
79
+ file_index2 = gr.Dropdown(
80
+ label="Change Index",
81
+ choices=sorted(index_paths),
82
+ interactive=True,
83
+ value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else ''
84
+ )
85
+ index_rate1 = gr.Slider(
86
+ minimum=0,
87
+ maximum=1,
88
+ label="Index Strength",
89
+ value=0.5,
90
+ interactive=True,
91
+ )
92
+ vc_output2 = gr.Audio(label="Output")
93
+ with gr.Accordion("General Settings", open=False):
94
+ f0method0 = gr.Radio(
95
+ label="Method",
96
+ choices=["crepe", "rmvpe"]
97
+ if config.dml == False
98
+ else [ "rmvpe"],
99
+ value="rmvpe",
100
+ interactive=True,
101
+ )
102
+ filter_radius0 = gr.Slider(
103
+ minimum=0,
104
+ maximum=7,
105
+ label="Breathiness Reduction (Harvest only)",
106
+ value=3,
107
+ step=1,
108
+ interactive=True,
109
+ )
110
+ resample_sr0 = gr.Slider(
111
+ minimum=0,
112
+ maximum=48000,
113
+ label="Resample",
114
+ value=0,
115
+ step=1,
116
+ interactive=True,
117
+ visible=False
118
+ )
119
+ rms_mix_rate0 = gr.Slider(
120
+ minimum=0,
121
+ maximum=1,
122
+ label="Volume Normalization",
123
+ value=0,
124
+ interactive=True,
125
+ )
126
+ protect0 = gr.Slider(
127
+ minimum=0,
128
+ maximum=0.5,
129
+ label="Breathiness Protection (0 is enabled, 0.5 is disabled)",
130
+ value=0.33,
131
+ step=0.01,
132
+ interactive=True,
133
+ )
134
+ if voice_model != None: vc.get_vc(voice_model.value,protect0,protect0)
135
+ file_index1 = gr.Textbox(
136
+ label="Index Path",
137
+ interactive=True,
138
+ visible=False#Not used here
139
+ )
140
+ refresh_button.click(
141
+ fn=change_choices,
142
+ inputs=[],
143
+ outputs=[voice_model, file_index2],
144
+ api_name="infer_refresh",
145
+ )
146
+ refresh_button.click(
147
+ 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'
148
+ inputs=[],
149
+ outputs = [input_audio0],
150
+ )
151
+ refresh_button.click(
152
+ 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'
153
+ inputs=[],
154
+ outputs = [input_audio0],
155
+ )
156
+ with gr.Row():
157
+ f0_file = gr.File(label="F0 Path") #, visible=False
158
+ with gr.Row():
159
+ vc_output1 = gr.Textbox(label="Information", placeholder="Welcome!",visible=False)
160
+ but0.click(
161
+ vc.vc_single,
162
+ [
163
+ spk_item,
164
+ input_audio0,
165
+ vc_transform0,
166
+ f0_file,
167
+ f0method0,
168
+ file_index1,
169
+ file_index2,
170
+ index_rate1,
171
+ filter_radius0,
172
+ resample_sr0,
173
+ rms_mix_rate0,
174
+ protect0,
175
+ ],
176
+ [vc_output1, vc_output2],
177
+ api_name="infer_convert",
178
+ )
179
+ voice_model.change(
180
+ fn=vc.get_vc,
181
+ inputs=[voice_model, protect0, protect0],
182
+ outputs=[spk_item, protect0, protect0, file_index2, file_index2],
183
+ api_name="infer_change_voice",
184
+ )
185
+ with gr.TabItem("Download song"):
186
+ with gr.Row():
187
+ url = gr.Textbox(label="url to yotube link.")
188
+ audio_name = gr.Textbox(label="file name.")
189
+ output_audio2 = gr.Audio(label="output")
190
+ dwnl_button = gr.Button("Download")
191
+ dwnl_button.click(fn=download_audio,inputs=[url,audio_name],outputs=[output_audio2])
192
+
193
+ with gr.TabItem("Download Models"):
194
+ with gr.Row():
195
+ url_input = gr.Textbox(label="URL to model", value="",placeholder="https://...", scale=6)
196
+ name_output = gr.Textbox(label="Save as", value="",placeholder="MyModel",scale=2)
197
+ url_download = gr.Button(value="Download Model",scale=2)
198
+ url_download.click(
199
+ inputs=[url_input,name_output],
200
+ outputs=[url_input],
201
+ fn=download_from_url,
202
+ )
203
+ with gr.Row():
204
+ model_browser = gr.Dropdown(choices=list(model_library.models.keys()),label="OR Search Models (Quality UNKNOWN)",scale=5)
205
+ download_from_browser = gr.Button(value="Get",scale=2)
206
+ download_from_browser.click(
207
+ inputs=[model_browser],
208
+ outputs=[model_browser],
209
+ fn=lambda model: download_from_url(model_library.models[model],model),
210
+ )
211
+ with gr.TabItem("Train"):
212
+ with gr.Row():
213
+ with gr.Column():
214
+ training_name = gr.Textbox(label="Name your model", value="My-Voice",placeholder="My-Voice")
215
+ np7 = gr.Slider(
216
+ minimum=0,
217
+ maximum=config.n_cpu,
218
+ step=1,
219
+ label="Number of CPU processes used to extract pitch features",
220
+ value=int(np.ceil(config.n_cpu / 1.5)),
221
+ interactive=True,
222
+ )
223
+ sr2 = gr.Radio(
224
+ label="Sampling Rate",
225
+ choices=["40k", "32k"],
226
+ value="32k",
227
+ interactive=True,
228
+ visible=False
229
+ )
230
+ if_f0_3 = gr.Radio(
231
+ label="Will your model be used for singing? If not, you can ignore this.",
232
+ choices=[True, False],
233
+ value=True,
234
+ interactive=True,
235
+ visible=False
236
+ )
237
+ version19 = gr.Radio(
238
+ label="Version",
239
+ choices=["v1", "v2"],
240
+ value="v2",
241
+ interactive=True,
242
+ visible=False,
243
+ )
244
+ dataset_folder = gr.Textbox(
245
+ label="dataset folder", value='dataset'
246
+ )
247
+ easy_uploader = gr.Files(label="Drop your audio files here",file_types=['audio'])
248
+ but1 = gr.Button("1. Process", variant="primary")
249
+ info1 = gr.Textbox(label="Information", value="",visible=True)
250
+ easy_uploader.upload(inputs=[dataset_folder],outputs=[],fn=lambda folder:os.makedirs(folder,exist_ok=True))
251
+ easy_uploader.upload(
252
+ 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'),
253
+ inputs=[easy_uploader, dataset_folder],
254
+ outputs=[])
255
+ gpus6 = gr.Textbox(
256
+ label="Enter the GPU numbers to use separated by -, (e.g. 0-1-2)",
257
+ value=gpus,
258
+ interactive=True,
259
+ visible=F0GPUVisible,
260
+ )
261
+ gpu_info9 = gr.Textbox(
262
+ label="GPU Info", value=gpu_info, visible=F0GPUVisible
263
+ )
264
+ spk_id5 = gr.Slider(
265
+ minimum=0,
266
+ maximum=4,
267
+ step=1,
268
+ label="Speaker ID",
269
+ value=0,
270
+ interactive=True,
271
+ visible=False
272
+ )
273
+ but1.click(
274
+ preprocess_dataset,
275
+ [dataset_folder, training_name, sr2, np7],
276
+ [info1],
277
+ api_name="train_preprocess",
278
+ )
279
+ with gr.Column():
280
+ f0method8 = gr.Radio(
281
+ label="F0 extraction method",
282
+ choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
283
+ value="rmvpe_gpu",
284
+ interactive=True,
285
+ )
286
+ gpus_rmvpe = gr.Textbox(
287
+ label="GPU numbers to use separated by -, (e.g. 0-1-2)",
288
+ value="%s-%s" % (gpus, gpus),
289
+ interactive=True,
290
+ visible=F0GPUVisible,
291
+ )
292
+ but2 = gr.Button("2. Extract Features", variant="primary")
293
+ info2 = gr.Textbox(label="Information", value="", max_lines=8)
294
+ f0method8.change(
295
+ fn=change_f0_method,
296
+ inputs=[f0method8],
297
+ outputs=[gpus_rmvpe],
298
+ )
299
+ but2.click(
300
+ extract_f0_feature,
301
+ [
302
+ gpus6,
303
+ np7,
304
+ f0method8,
305
+ if_f0_3,
306
+ training_name,
307
+ version19,
308
+ gpus_rmvpe,
309
+ ],
310
+ [info2],
311
+ api_name="train_extract_f0_feature",
312
+ )
313
+ with gr.Column():
314
+ total_epoch11 = gr.Slider(
315
+ minimum=2,
316
+ maximum=1000,
317
+ step=1,
318
+ label="Epochs (more epochs may improve quality but takes longer)",
319
+ value=150,
320
+ interactive=True,
321
+ )
322
+ but4 = gr.Button("3. Train Index", variant="primary")
323
+ but3 = gr.Button("4. Train Model", variant="primary")
324
+ info3 = gr.Textbox(label="Information", value="", max_lines=10)
325
+ with gr.Accordion(label="General Settings", open=False):
326
+ gpus16 = gr.Textbox(
327
+ label="GPUs separated by -, (e.g. 0-1-2)",
328
+ value="0",
329
+ interactive=True,
330
+ visible=True
331
+ )
332
+ save_epoch10 = gr.Slider(
333
+ minimum=1,
334
+ maximum=50,
335
+ step=1,
336
+ label="Weight Saving Frequency",
337
+ value=25,
338
+ interactive=True,
339
+ )
340
+ batch_size12 = gr.Slider(
341
+ minimum=1,
342
+ maximum=40,
343
+ step=1,
344
+ label="Batch Size",
345
+ value=default_batch_size,
346
+ interactive=True,
347
+ )
348
+ if_save_latest13 = gr.Radio(
349
+ label="Only save the latest model",
350
+ choices=["yes", "no"],
351
+ value="yes",
352
+ interactive=True,
353
+ visible=False
354
+ )
355
+ if_cache_gpu17 = gr.Radio(
356
+ label="If your dataset is UNDER 10 minutes, cache it to train faster",
357
+ choices=["yes", "no"],
358
+ value="no",
359
+ interactive=True,
360
+ )
361
+ if_save_every_weights18 = gr.Radio(
362
+ label="Save small model at every save point",
363
+ choices=["yes", "no"],
364
+ value="yes",
365
+ interactive=True,
366
+ )
367
+ with gr.Accordion(label="Change pretrains", open=False):
368
+ 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]
369
+ pretrained_G14 = gr.Dropdown(
370
+ label="pretrained G",
371
+ # Get a list of all pretrained G model files in assets/pretrained_v2 that end with .pth
372
+ choices = pretrained(sr2.value, 'G'),
373
+ value=pretrained(sr2.value, 'G')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
374
+ interactive=True,
375
+ visible=True
376
+ )
377
+ pretrained_D15 = gr.Dropdown(
378
+ label="pretrained D",
379
+ choices = pretrained(sr2.value, 'D'),
380
+ value= pretrained(sr2.value, 'D')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
381
+ visible=True,
382
+ interactive=True
383
+ )
384
+ with gr.Row():
385
+ download_model = gr.Button('5.Download Model')
386
+ with gr.Row():
387
+ model_files = gr.Files(label='Your Model and Index file can be downloaded here:')
388
+ download_model.click(
389
+ fn=lambda name: os.listdir(f'assets/weights/{name}') + glob.glob(f'logs/{name.split(".")[0]}/added_*.index'),
390
+ inputs=[training_name],
391
+ outputs=[model_files, info3])
392
+ with gr.Row():
393
+ sr2.change(
394
+ change_sr2,
395
+ [sr2, if_f0_3, version19],
396
+ [pretrained_G14, pretrained_D15],
397
+ )
398
+ version19.change(
399
+ change_version19,
400
+ [sr2, if_f0_3, version19],
401
+ [pretrained_G14, pretrained_D15, sr2],
402
+ )
403
+ if_f0_3.change(
404
+ change_f0,
405
+ [if_f0_3, sr2, version19],
406
+ [f0method8, pretrained_G14, pretrained_D15],
407
+ )
408
+ with gr.Row():
409
+ but5 = gr.Button("1 Click Training", variant="primary", visible=False)
410
+ but3.click(
411
+ click_train,
412
+ [
413
+ training_name,
414
+ sr2,
415
+ if_f0_3,
416
+ spk_id5,
417
+ save_epoch10,
418
+ total_epoch11,
419
+ batch_size12,
420
+ if_save_latest13,
421
+ pretrained_G14,
422
+ pretrained_D15,
423
+ gpus16,
424
+ if_cache_gpu17,
425
+ if_save_every_weights18,
426
+ version19,
427
+ ],
428
+ info3,
429
+ api_name="train_start",
430
+ )
431
+ but4.click(train_index, [training_name, version19], info3)
432
+ but5.click(
433
+ train1key,
434
+ [
435
+ training_name,
436
+ sr2,
437
+ if_f0_3,
438
+ dataset_folder,
439
+ spk_id5,
440
+ np7,
441
+ f0method8,
442
+ save_epoch10,
443
+ total_epoch11,
444
+ batch_size12,
445
+ if_save_latest13,
446
+ pretrained_G14,
447
+ pretrained_D15,
448
+ gpus16,
449
+ if_cache_gpu17,
450
+ if_save_every_weights18,
451
+ version19,
452
+ gpus_rmvpe,
453
+ ],
454
+ info3,
455
+ api_name="train_start_all",
456
+ )
457
+
458
+ if config.iscolab:
459
+ app.queue(concurrency_count=511, max_size=1022).launch(share=True)
460
+ else:
461
+ app.queue(concurrency_count=511, max_size=1022).launch(
462
+ server_name="0.0.0.0",
463
+ inbrowser=not config.noautoopen,
464
+ server_port=config.listen_port,
465
+ quiet=True,
466
+ )