Blane187 commited on
Commit
a3ce2d5
·
verified ·
1 Parent(s): d8c69b9

Rename demo.py to app.py

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