Blane187 commited on
Commit
b217fda
1 Parent(s): b339717

Create demo.py

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