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
|
8 |
+
with gr.Tabs():
|
9 |
+
with gr.Tab(label=translations["downloads"], visible=configs.get("downloads_tab", True)):
|
10 |
+
gr.Markdown(translations["download_markdown"])
|
11 |
+
with gr.Row():
|
12 |
+
gr.Markdown(translations["download_markdown_2"])
|
13 |
+
with gr.Row():
|
14 |
+
with gr.Accordion(translations["model_download"], open=True):
|
15 |
+
with gr.Row():
|
16 |
+
downloadmodel = gr.Radio(label=translations["model_download_select"], choices=[translations["download_url"], translations["download_from_csv"], translations["search_models"], translations["upload"]], interactive=True, value=translations["download_url"])
|
17 |
+
with gr.Row():
|
18 |
+
gr.Markdown("___")
|
19 |
+
with gr.Column():
|
20 |
+
with gr.Row():
|
21 |
+
url_input = gr.Textbox(label=translations["model_url"], value="", placeholder="https://...", scale=6)
|
22 |
+
download_model_name = gr.Textbox(label=translations["modelname"], value="", placeholder=translations["modelname"], scale=2)
|
23 |
+
url_download = gr.Button(value=translations["downloads"], scale=2)
|
24 |
+
with gr.Column():
|
25 |
+
model_browser = gr.Dropdown(choices=models.keys(), label=translations["model_warehouse"], scale=8, allow_custom_value=True, visible=False)
|
26 |
+
download_from_browser = gr.Button(value=translations["get_model"], scale=2, variant="primary", visible=False)
|
27 |
+
with gr.Column():
|
28 |
+
search_name = gr.Textbox(label=translations["name_to_search"], placeholder=translations["modelname"], interactive=True, scale=8, visible=False)
|
29 |
+
search = gr.Button(translations["search_2"], scale=2, visible=False)
|
30 |
+
search_dropdown = gr.Dropdown(label=translations["select_download_model"], value="", choices=[], allow_custom_value=True, interactive=False, visible=False)
|
31 |
+
download = gr.Button(translations["downloads"], variant="primary", visible=False)
|
32 |
+
with gr.Column():
|
33 |
+
model_upload = gr.File(label=translations["drop_model"], file_types=[".pth", ".onnx", ".index", ".zip"], visible=False)
|
34 |
+
with gr.Row():
|
35 |
+
with gr.Accordion(translations["download_pretrained_2"], open=False):
|
36 |
+
with gr.Row():
|
37 |
+
pretrain_download_choices = gr.Radio(label=translations["model_download_select"], choices=[translations["download_url"], translations["list_model"], translations["upload"]], value=translations["download_url"], interactive=True)
|
38 |
+
with gr.Row():
|
39 |
+
gr.Markdown("___")
|
40 |
+
with gr.Column():
|
41 |
+
with gr.Row():
|
42 |
+
pretrainD = gr.Textbox(label=translations["pretrained_url"].format(dg="D"), value="", info=translations["only_huggingface"], placeholder="https://...", interactive=True, scale=4)
|
43 |
+
pretrainG = gr.Textbox(label=translations["pretrained_url"].format(dg="G"), value="", info=translations["only_huggingface"], placeholder="https://...", interactive=True, scale=4)
|
44 |
+
download_pretrain_button = gr.Button(translations["downloads"], scale=2)
|
45 |
+
with gr.Column():
|
46 |
+
with gr.Row():
|
47 |
+
pretrain_choices = gr.Dropdown(label=translations["select_pretrain"], info=translations["select_pretrain_info"], choices=list(fetch_pretrained_data().keys()), value="Titan_Medium", allow_custom_value=True, interactive=True, scale=6, visible=False)
|
48 |
+
sample_rate_pretrain = gr.Dropdown(label=translations["pretrain_sr"], info=translations["pretrain_sr"], choices=["48k", "40k", "32k"], value="48k", interactive=True, visible=False)
|
49 |
+
download_pretrain_choices_button = gr.Button(translations["downloads"], scale=2, variant="primary", visible=False)
|
50 |
+
with gr.Row():
|
51 |
+
pretrain_upload_g = gr.File(label=translations["drop_pretrain"].format(dg="G"), file_types=[".pth"], visible=False)
|
52 |
+
pretrain_upload_d = gr.File(label=translations["drop_pretrain"].format(dg="D"), file_types=[".pth"], visible=False)
|
53 |
+
with gr.Row():
|
54 |
+
url_download.click(
|
55 |
+
fn=download_model,
|
56 |
+
inputs=[
|
57 |
+
url_input,
|
58 |
+
download_model_name
|
59 |
+
],
|
60 |
+
outputs=[url_input],
|
61 |
+
api_name="download_model"
|
62 |
+
)
|
63 |
+
download_from_browser.click(
|
64 |
+
fn=lambda model: download_model(models[model], model),
|
65 |
+
inputs=[model_browser],
|
66 |
+
outputs=[model_browser],
|
67 |
+
api_name="download_browser"
|
68 |
+
)
|
69 |
+
with gr.Row():
|
70 |
+
downloadmodel.change(fn=change_download_choices, inputs=[downloadmodel], outputs=[url_input, download_model_name, url_download, model_browser, download_from_browser, search_name, search, search_dropdown, download, model_upload])
|
71 |
+
search.click(fn=search_models, inputs=[search_name], outputs=[search_dropdown, download])
|
72 |
+
model_upload.upload(fn=save_drop_model, inputs=[model_upload], outputs=[model_upload])
|
73 |
+
download.click(
|
74 |
+
fn=lambda model: download_model(model_options[model], model),
|
75 |
+
inputs=[search_dropdown],
|
76 |
+
outputs=[search_dropdown],
|
77 |
+
api_name="search_models"
|
78 |
+
)
|
79 |
+
with gr.Row():
|
80 |
+
pretrain_download_choices.change(fn=change_download_pretrained_choices, inputs=[pretrain_download_choices], outputs=[pretrainD, pretrainG, download_pretrain_button, pretrain_choices, sample_rate_pretrain, download_pretrain_choices_button, pretrain_upload_d, pretrain_upload_g])
|
81 |
+
pretrain_choices.change(fn=update_sample_rate_dropdown, inputs=[pretrain_choices], outputs=[sample_rate_pretrain])
|
82 |
+
with gr.Row():
|
83 |
+
download_pretrain_button.click(
|
84 |
+
fn=download_pretrained_model,
|
85 |
+
inputs=[
|
86 |
+
pretrain_download_choices,
|
87 |
+
pretrainD,
|
88 |
+
pretrainG
|
89 |
+
],
|
90 |
+
outputs=[pretrainD],
|
91 |
+
api_name="download_pretrain_link"
|
92 |
+
)
|
93 |
+
download_pretrain_choices_button.click(
|
94 |
+
fn=download_pretrained_model,
|
95 |
+
inputs=[
|
96 |
+
pretrain_download_choices,
|
97 |
+
pretrain_choices,
|
98 |
+
sample_rate_pretrain
|
99 |
+
],
|
100 |
+
outputs=[pretrain_choices],
|
101 |
+
api_name="download_pretrain_choices"
|
102 |
+
)
|
103 |
+
pretrain_upload_g.upload(
|
104 |
+
fn=lambda pretrain_upload_g: shutil.move(pretrain_upload_g.name, os.path.join("assets", "models", "pretrained_custom")),
|
105 |
+
inputs=[pretrain_upload_g],
|
106 |
+
outputs=[],
|
107 |
+
api_name="upload_pretrain_g"
|
108 |
+
)
|
109 |
+
pretrain_upload_d.upload(
|
110 |
+
fn=lambda pretrain_upload_d: shutil.move(pretrain_upload_d.name, os.path.join("assets", "models", "pretrained_custom")),
|
111 |
+
inputs=[pretrain_upload_d],
|
112 |
+
outputs=[],
|
113 |
+
api_name="upload_pretrain_d"
|
114 |
+
)
|
115 |
+
|
116 |
+
with gr.Tab(label=translations["createdataset"], visible=configs.get("create_dataset_tab", True)):
|
117 |
+
gr.Markdown(translations["create_dataset_markdown"])
|
118 |
+
with gr.Row():
|
119 |
+
gr.Markdown(translations["create_dataset_markdown_2"])
|
120 |
+
with gr.Row():
|
121 |
+
dataset_url = gr.Textbox(label=translations["url_audio"], info=translations["create_dataset_url"], value="", placeholder="https://www.youtube.com/...", interactive=True)
|
122 |
+
output_dataset = gr.Textbox(label=translations["output_data"], info=translations["output_data_info"], value="dataset", placeholder="dataset", interactive=True)
|
123 |
+
with gr.Row():
|
124 |
+
with gr.Column():
|
125 |
+
with gr.Group():
|
126 |
+
with gr.Row():
|
127 |
+
separator_reverb = gr.Checkbox(label=translations["dereveb_audio"], value=False, interactive=True)
|
128 |
+
denoise_mdx = gr.Checkbox(label=translations["denoise"], value=False, interactive=True)
|
129 |
+
with gr.Row():
|
130 |
+
kim_vocal_version = gr.Radio(label=translations["model_ver"], info=translations["model_ver_info"], choices=["Version-1", "Version-2"], value="Version-2", interactive=True)
|
131 |
+
kim_vocal_overlap = gr.Radio(label=translations["overlap"], info=translations["overlap_info"], choices=["0.25", "0.5", "0.75", "0.99"], value="0.25", interactive=True)
|
132 |
+
with gr.Row():
|
133 |
+
kim_vocal_hop_length = gr.Slider(label="Hop length", info=translations["hop_length_info"], minimum=1, maximum=8192, value=1024, step=1, interactive=True)
|
134 |
+
kim_vocal_batch_size = gr.Slider(label=translations["batch_size"], info=translations["mdx_batch_size_info"], minimum=1, maximum=64, value=1, step=1, interactive=True)
|
135 |
+
with gr.Row():
|
136 |
+
kim_vocal_segments_size = gr.Slider(label=translations["segments_size"], info=translations["segments_size_info"], minimum=32, maximum=3072, value=256, step=32, interactive=True)
|
137 |
+
with gr.Row():
|
138 |
+
sample_rate0 = gr.Slider(minimum=8000, maximum=96000, step=1, value=44100, label=translations["sr"], info=translations["sr_info"], interactive=True)
|
139 |
+
with gr.Column():
|
140 |
+
create_button = gr.Button(translations["createdataset"], variant="primary", scale=2, min_width=4000)
|
141 |
+
with gr.Group():
|
142 |
+
with gr.Row():
|
143 |
+
clean_audio = gr.Checkbox(label=translations["clear_audio"], value=False, interactive=True)
|
144 |
+
skip = gr.Checkbox(label=translations["skip"], value=False, interactive=True)
|
145 |
+
with gr.Row():
|
146 |
+
dataset_clean_strength = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.5, label=translations["clean_strength"], info=translations["clean_strength_info"], interactive=True, visible=clean_audio.value)
|
147 |
+
with gr.Row():
|
148 |
+
skip_start = gr.Textbox(label=translations["skip_start"], info=translations["skip_start_info"], value="", placeholder="0,...", interactive=True, visible=skip.value)
|
149 |
+
skip_end = gr.Textbox(label=translations["skip_end"], info=translations["skip_end_info"], value="", placeholder="0,...", interactive=True, visible=skip.value)
|
150 |
+
create_dataset_info = gr.Textbox(label=translations["create_dataset_info"], value="", interactive=False)
|
151 |
+
with gr.Row():
|
152 |
+
clean_audio.change(fn=visible, inputs=[clean_audio], outputs=[dataset_clean_strength])
|
153 |
+
skip.change(fn=lambda a: [valueEmpty_visible1(a)]*2, inputs=[skip], outputs=[skip_start, skip_end])
|
154 |
+
with gr.Row():
|
155 |
+
create_button.click(
|
156 |
+
fn=create_dataset,
|
157 |
+
inputs=[
|
158 |
+
dataset_url,
|
159 |
+
output_dataset,
|
160 |
+
clean_audio,
|
161 |
+
dataset_clean_strength,
|
162 |
+
separator_reverb,
|
163 |
+
kim_vocal_version,
|
164 |
+
kim_vocal_overlap,
|
165 |
+
kim_vocal_segments_size,
|
166 |
+
denoise_mdx,
|
167 |
+
skip,
|
168 |
+
skip_start,
|
169 |
+
skip_end,
|
170 |
+
kim_vocal_hop_length,
|
171 |
+
kim_vocal_batch_size,
|
172 |
+
sample_rate0
|
173 |
+
],
|
174 |
+
outputs=[create_dataset_info],
|
175 |
+
api_name="create_dataset"
|
176 |
+
)
|
177 |
+
|
178 |
+
with gr.Tab(label=translations["training_model"], visible=configs.get("training_tab", True)):
|
179 |
+
gr.Markdown(f"## {translations['training_model']}")
|
180 |
+
with gr.Row():
|
181 |
+
gr.Markdown(translations["training_markdown"])
|
182 |
+
with gr.Row():
|
183 |
+
with gr.Column():
|
184 |
+
with gr.Row():
|
185 |
+
with gr.Column():
|
186 |
+
training_name = gr.Textbox(label=translations["modelname"], info=translations["training_model_name"], value="", placeholder=translations["modelname"], interactive=True)
|
187 |
+
training_sr = gr.Radio(label=translations["sample_rate"], info=translations["sample_rate_info"], choices=["32k", "40k", "48k"], value="48k", interactive=True)
|
188 |
+
training_ver = gr.Radio(label=translations["training_version"], info=translations["training_version_info"], choices=["v1", "v2"], value="v2", interactive=True)
|
189 |
+
with gr.Row():
|
190 |
+
clean_dataset = gr.Checkbox(label=translations["clear_dataset"], value=False, interactive=True)
|
191 |
+
preprocess_cut = gr.Checkbox(label=translations["split_audio"], value=True, interactive=True)
|
192 |
+
process_effects = gr.Checkbox(label=translations["preprocess_effect"], value=False, interactive=True)
|
193 |
+
checkpointing1 = gr.Checkbox(label=translations["memory_efficient_training"], value=False, interactive=True)
|
194 |
+
training_f0 = gr.Checkbox(label=translations["training_pitch"], value=True, interactive=True)
|
195 |
+
upload = gr.Checkbox(label=translations["upload_dataset"], value=False, interactive=True)
|
196 |
+
with gr.Row():
|
197 |
+
clean_dataset_strength = gr.Slider(label=translations["clean_strength"], info=translations["clean_strength_info"], minimum=0, maximum=1, value=0.7, step=0.1, interactive=True, visible=clean_dataset.value)
|
198 |
+
with gr.Column():
|
199 |
+
preprocess_button = gr.Button(translations["preprocess_button"], scale=2)
|
200 |
+
upload_dataset = gr.Files(label=translations["drop_audio"], file_types=[".wav", ".mp3", ".flac", ".ogg", ".opus", ".m4a", ".mp4", ".aac", ".alac", ".wma", ".aiff", ".webm", ".ac3"], visible=upload.value)
|
201 |
+
preprocess_info = gr.Textbox(label=translations["preprocess_info"], value="", interactive=False)
|
202 |
+
with gr.Column():
|
203 |
+
with gr.Row():
|
204 |
+
with gr.Column():
|
205 |
+
with gr.Accordion(label=translations["f0_method"], open=False):
|
206 |
+
with gr.Group():
|
207 |
+
with gr.Row():
|
208 |
+
onnx_f0_mode2 = gr.Checkbox(label=translations["f0_onnx_mode"], info=translations["f0_onnx_mode_info"], value=False, interactive=True)
|
209 |
+
unlock_full_method4 = gr.Checkbox(label=translations["f0_unlock"], info=translations["f0_unlock_info"], value=False, interactive=True)
|
210 |
+
extract_method = gr.Radio(label=translations["f0_method"], info=translations["f0_method_info"], choices=method_f0, value="rmvpe", interactive=True)
|
211 |
+
extract_hop_length = gr.Slider(label="Hop length", info=translations["hop_length_info"], minimum=1, maximum=512, value=128, step=1, interactive=True, visible=False)
|
212 |
+
with gr.Accordion(label=translations["hubert_model"], open=False):
|
213 |
+
with gr.Group():
|
214 |
+
embed_mode2 = gr.Radio(label=translations["embed_mode"], info=translations["embed_mode_info"], value="fairseq", choices=embedders_mode, interactive=True, visible=True)
|
215 |
+
extract_embedders = gr.Radio(label=translations["hubert_model"], info=translations["hubert_info"], choices=embedders_model, value="hubert_base", interactive=True)
|
216 |
+
with gr.Row():
|
217 |
+
extract_embedders_custom = gr.Textbox(label=translations["modelname"], info=translations["modelname_info"], value="", placeholder="hubert_base", interactive=True, visible=extract_embedders.value == "custom")
|
218 |
+
with gr.Column():
|
219 |
+
extract_button = gr.Button(translations["extract_button"], scale=2)
|
220 |
+
extract_info = gr.Textbox(label=translations["extract_info"], value="", interactive=False)
|
221 |
+
with gr.Column():
|
222 |
+
with gr.Row():
|
223 |
+
with gr.Column():
|
224 |
+
total_epochs = gr.Slider(label=translations["total_epoch"], info=translations["total_epoch_info"], minimum=1, maximum=10000, value=300, step=1, interactive=True)
|
225 |
+
save_epochs = gr.Slider(label=translations["save_epoch"], info=translations["save_epoch_info"], minimum=1, maximum=10000, value=50, step=1, interactive=True)
|
226 |
+
with gr.Column():
|
227 |
+
with gr.Row():
|
228 |
+
index_button = gr.Button(f"3. {translations['create_index']}", variant="primary", scale=2)
|
229 |
+
training_button = gr.Button(f"4. {translations['training_model']}", variant="primary", scale=2)
|
230 |
+
with gr.Row():
|
231 |
+
with gr.Accordion(label=translations["setting"], open=False):
|
232 |
+
with gr.Row():
|
233 |
+
index_algorithm = gr.Radio(label=translations["index_algorithm"], info=translations["index_algorithm_info"], choices=["Auto", "Faiss", "KMeans"], value="Auto", interactive=True)
|
234 |
+
with gr.Row():
|
235 |
+
custom_dataset = gr.Checkbox(label=translations["custom_dataset"], info=translations["custom_dataset_info"], value=False, interactive=True)
|
236 |
+
overtraining_detector = gr.Checkbox(label=translations["overtraining_detector"], info=translations["overtraining_detector_info"], value=False, interactive=True)
|
237 |
+
clean_up = gr.Checkbox(label=translations["cleanup_training"], info=translations["cleanup_training_info"], value=False, interactive=True)
|
238 |
+
cache_in_gpu = gr.Checkbox(label=translations["cache_in_gpu"], info=translations["cache_in_gpu_info"], value=False, interactive=True)
|
239 |
+
with gr.Column():
|
240 |
+
dataset_path = gr.Textbox(label=translations["dataset_folder"], value="dataset", interactive=True, visible=custom_dataset.value)
|
241 |
+
with gr.Column():
|
242 |
+
threshold = gr.Slider(minimum=1, maximum=100, value=50, step=1, label=translations["threshold"], interactive=True, visible=overtraining_detector.value)
|
243 |
+
with gr.Accordion(translations["setting_cpu_gpu"], open=False):
|
244 |
+
with gr.Column():
|
245 |
+
gpu_number = gr.Textbox(label=translations["gpu_number"], value=str("-".join(map(str, range(torch.cuda.device_count()))) if torch.cuda.is_available() else "-"), info=translations["gpu_number_info"], interactive=True)
|
246 |
+
gpu_info = gr.Textbox(label=translations["gpu_info"], value=get_gpu_info(), info=translations["gpu_info_2"], interactive=False)
|
247 |
+
cpu_core = gr.Slider(label=translations["cpu_core"], info=translations["cpu_core_info"], minimum=0, maximum=cpu_count(), value=cpu_count(), step=1, interactive=True)
|
248 |
+
train_batch_size = gr.Slider(label=translations["batch_size"], info=translations["batch_size_info"], minimum=1, maximum=64, value=8, step=1, interactive=True)
|
249 |
+
with gr.Row():
|
250 |
+
save_only_latest = gr.Checkbox(label=translations["save_only_latest"], info=translations["save_only_latest_info"], value=True, interactive=True)
|
251 |
+
save_every_weights = gr.Checkbox(label=translations["save_every_weights"], info=translations["save_every_weights_info"], value=True, interactive=True)
|
252 |
+
not_use_pretrain = gr.Checkbox(label=translations["not_use_pretrain_2"], info=translations["not_use_pretrain_info"], value=False, interactive=True)
|
253 |
+
custom_pretrain = gr.Checkbox(label=translations["custom_pretrain"], info=translations["custom_pretrain_info"], value=False, interactive=True)
|
254 |
+
with gr.Row():
|
255 |
+
vocoders = gr.Radio(label=translations["vocoder"], info=translations["vocoder_info"], choices=["Default", "MRF-HiFi-GAN", "RefineGAN"], value="Default", interactive=True)
|
256 |
+
with gr.Row():
|
257 |
+
deterministic = gr.Checkbox(label=translations["deterministic"], info=translations["deterministic_info"], value=False, interactive=True)
|
258 |
+
benchmark = gr.Checkbox(label=translations["benchmark"], info=translations["benchmark_info"], value=False, interactive=True)
|
259 |
+
with gr.Row():
|
260 |
+
model_author = gr.Textbox(label=translations["training_author"], info=translations["training_author_info"], value="", placeholder=translations["training_author"], interactive=True)
|
261 |
+
with gr.Row():
|
262 |
+
with gr.Column():
|
263 |
+
with gr.Accordion(translations["custom_pretrain_info"], open=False, visible=custom_pretrain.value and not not_use_pretrain.value) as pretrain_setting:
|
264 |
+
pretrained_D = gr.Dropdown(label=translations["pretrain_file"].format(dg="D"), choices=pretrainedD, value=pretrainedD[0] if len(pretrainedD) > 0 else '', interactive=True, allow_custom_value=True)
|
265 |
+
pretrained_G = gr.Dropdown(label=translations["pretrain_file"].format(dg="G"), choices=pretrainedG, value=pretrainedG[0] if len(pretrainedG) > 0 else '', interactive=True, allow_custom_value=True)
|
266 |
+
refesh_pretrain = gr.Button(translations["refesh"], scale=2)
|
267 |
+
with gr.Row():
|
268 |
+
training_info = gr.Textbox(label=translations["train_info"], value="", interactive=False)
|
269 |
+
with gr.Row():
|
270 |
+
with gr.Column():
|
271 |
+
with gr.Accordion(translations["export_model"], open=False):
|
272 |
+
with gr.Row():
|
273 |
+
model_file= gr.Dropdown(label=translations["model_name"], choices=model_name, value=model_name[0] if len(model_name) >= 1 else "", interactive=True, allow_custom_value=True)
|
274 |
+
index_file = gr.Dropdown(label=translations["index_path"], choices=index_path, value=index_path[0] if len(index_path) >= 1 else "", interactive=True, allow_custom_value=True)
|
275 |
+
with gr.Row():
|
276 |
+
refesh_file = gr.Button(f"1. {translations['refesh']}", scale=2)
|
277 |
+
zip_model = gr.Button(translations["zip_model"], variant="primary", scale=2)
|
278 |
+
with gr.Row():
|
279 |
+
zip_output = gr.File(label=translations["output_zip"], file_types=[".zip"], interactive=False, visible=False)
|
280 |
+
with gr.Row():
|
281 |
+
vocoders.change(fn=pitch_guidance_lock, inputs=[vocoders], outputs=[training_f0])
|
282 |
+
training_f0.change(fn=vocoders_lock, inputs=[training_f0, vocoders], outputs=[vocoders])
|
283 |
+
unlock_full_method4.change(fn=unlock_f0, inputs=[unlock_full_method4], outputs=[extract_method])
|
284 |
+
with gr.Row():
|
285 |
+
refesh_file.click(fn=change_models_choices, inputs=[], outputs=[model_file, index_file])
|
286 |
+
zip_model.click(fn=zip_file, inputs=[training_name, model_file, index_file], outputs=[zip_output])
|
287 |
+
dataset_path.change(fn=lambda folder: os.makedirs(folder, exist_ok=True), inputs=[dataset_path], outputs=[])
|
288 |
+
with gr.Row():
|
289 |
+
upload.change(fn=visible, inputs=[upload], outputs=[upload_dataset])
|
290 |
+
overtraining_detector.change(fn=visible, inputs=[overtraining_detector], outputs=[threshold])
|
291 |
+
clean_dataset.change(fn=visible, inputs=[clean_dataset], outputs=[clean_dataset_strength])
|
292 |
+
with gr.Row():
|
293 |
+
custom_dataset.change(fn=lambda custom_dataset: [visible(custom_dataset), "dataset"],inputs=[custom_dataset], outputs=[dataset_path, dataset_path])
|
294 |
+
training_ver.change(fn=unlock_vocoder, inputs=[training_ver, vocoders], outputs=[vocoders])
|
295 |
+
vocoders.change(fn=unlock_ver, inputs=[training_ver, vocoders], outputs=[training_ver])
|
296 |
+
upload_dataset.upload(
|
297 |
+
fn=lambda files, folder: [shutil.move(f.name, os.path.join(folder, os.path.split(f.name)[1])) for f in files] if folder != "" else gr_warning(translations["dataset_folder1"]),
|
298 |
+
inputs=[upload_dataset, dataset_path],
|
299 |
+
outputs=[],
|
300 |
+
api_name="upload_dataset"
|
301 |
+
)
|
302 |
+
with gr.Row():
|
303 |
+
not_use_pretrain.change(fn=lambda a, b: visible(a and not b), inputs=[custom_pretrain, not_use_pretrain], outputs=[pretrain_setting])
|
304 |
+
custom_pretrain.change(fn=lambda a, b: visible(a and not b), inputs=[custom_pretrain, not_use_pretrain], outputs=[pretrain_setting])
|
305 |
+
refesh_pretrain.click(fn=change_pretrained_choices, inputs=[], outputs=[pretrained_D, pretrained_G])
|
306 |
+
with gr.Row():
|
307 |
+
preprocess_button.click(
|
308 |
+
fn=preprocess,
|
309 |
+
inputs=[
|
310 |
+
training_name,
|
311 |
+
training_sr,
|
312 |
+
cpu_core,
|
313 |
+
preprocess_cut,
|
314 |
+
process_effects,
|
315 |
+
dataset_path,
|
316 |
+
clean_dataset,
|
317 |
+
clean_dataset_strength
|
318 |
+
],
|
319 |
+
outputs=[preprocess_info],
|
320 |
+
api_name="preprocess"
|
321 |
+
)
|
322 |
+
with gr.Row():
|
323 |
+
embed_mode2.change(fn=visible_embedders, inputs=[embed_mode2], outputs=[extract_embedders])
|
324 |
+
extract_method.change(fn=hoplength_show, inputs=[extract_method], outputs=[extract_hop_length])
|
325 |
+
extract_embedders.change(fn=lambda extract_embedders: visible(extract_embedders == "custom"), inputs=[extract_embedders], outputs=[extract_embedders_custom])
|
326 |
+
with gr.Row():
|
327 |
+
extract_button.click(
|
328 |
+
fn=extract,
|
329 |
+
inputs=[
|
330 |
+
training_name,
|
331 |
+
training_ver,
|
332 |
+
extract_method,
|
333 |
+
training_f0,
|
334 |
+
extract_hop_length,
|
335 |
+
cpu_core,
|
336 |
+
gpu_number,
|
337 |
+
training_sr,
|
338 |
+
extract_embedders,
|
339 |
+
extract_embedders_custom,
|
340 |
+
onnx_f0_mode2,
|
341 |
+
embed_mode2
|
342 |
+
],
|
343 |
+
outputs=[extract_info],
|
344 |
+
api_name="extract"
|
345 |
+
)
|
346 |
+
with gr.Row():
|
347 |
+
index_button.click(
|
348 |
+
fn=create_index,
|
349 |
+
inputs=[
|
350 |
+
training_name,
|
351 |
+
training_ver,
|
352 |
+
index_algorithm
|
353 |
+
],
|
354 |
+
outputs=[training_info],
|
355 |
+
api_name="create_index"
|
356 |
+
)
|
357 |
+
with gr.Row():
|
358 |
+
training_button.click(
|
359 |
+
fn=training,
|
360 |
+
inputs=[
|
361 |
+
training_name,
|
362 |
+
training_ver,
|
363 |
+
save_epochs,
|
364 |
+
save_only_latest,
|
365 |
+
save_every_weights,
|
366 |
+
total_epochs,
|
367 |
+
training_sr,
|
368 |
+
train_batch_size,
|
369 |
+
gpu_number,
|
370 |
+
training_f0,
|
371 |
+
not_use_pretrain,
|
372 |
+
custom_pretrain,
|
373 |
+
pretrained_G,
|
374 |
+
pretrained_D,
|
375 |
+
overtraining_detector,
|
376 |
+
threshold,
|
377 |
+
clean_up,
|
378 |
+
cache_in_gpu,
|
379 |
+
model_author,
|
380 |
+
vocoders,
|
381 |
+
checkpointing1,
|
382 |
+
deterministic,
|
383 |
+
benchmark
|
384 |
+
],
|
385 |
+
outputs=[training_info],
|
386 |
+
api_name="training_model"
|
387 |
+
)
|
388 |
+
|
389 |
+
with gr.Tab(label=translations["fushion"], visible=configs.get("fushion_tab", True)):
|
390 |
+
gr.Markdown(translations["fushion_markdown"])
|
391 |
+
with gr.Row():
|
392 |
+
gr.Markdown(translations["fushion_markdown_2"])
|
393 |
+
with gr.Row():
|
394 |
+
name_to_save = gr.Textbox(label=translations["modelname"], placeholder="Model.pth", value="", max_lines=1, interactive=True)
|
395 |
+
with gr.Row():
|
396 |
+
fushion_button = gr.Button(translations["fushion"], variant="primary", scale=4)
|
397 |
+
with gr.Column():
|
398 |
+
with gr.Row():
|
399 |
+
model_a = gr.File(label=f"{translations['model_name']} 1", file_types=[".pth", ".onnx"])
|
400 |
+
model_b = gr.File(label=f"{translations['model_name']} 2", file_types=[".pth", ".onnx"])
|
401 |
+
with gr.Row():
|
402 |
+
model_path_a = gr.Textbox(label=f"{translations['model_path']} 1", value="", placeholder="assets/weights/Model_1.pth")
|
403 |
+
model_path_b = gr.Textbox(label=f"{translations['model_path']} 2", value="", placeholder="assets/weights/Model_2.pth")
|
404 |
+
with gr.Row():
|
405 |
+
ratio = gr.Slider(minimum=0, maximum=1, label=translations["model_ratio"], info=translations["model_ratio_info"], value=0.5, interactive=True)
|
406 |
+
with gr.Row():
|
407 |
+
output_model = gr.File(label=translations["output_model_path"], file_types=[".pth", ".onnx"], interactive=False, visible=False)
|
408 |
+
with gr.Row():
|
409 |
+
model_a.upload(fn=lambda model: shutil.move(model.name, os.path.join("assets", "weights")), inputs=[model_a], outputs=[model_path_a])
|
410 |
+
model_b.upload(fn=lambda model: shutil.move(model.name, os.path.join("assets", "weights")), inputs=[model_b], outputs=[model_path_b])
|
411 |
+
with gr.Row():
|
412 |
+
fushion_button.click(
|
413 |
+
fn=fushion_model,
|
414 |
+
inputs=[
|
415 |
+
name_to_save,
|
416 |
+
model_path_a,
|
417 |
+
model_path_b,
|
418 |
+
ratio
|
419 |
+
],
|
420 |
+
outputs=[name_to_save, output_model],
|
421 |
+
api_name="fushion_model"
|
422 |
+
)
|
423 |
+
fushion_button.click(fn=lambda: visible(True), inputs=[], outputs=[output_model])
|
424 |
+
|
425 |
+
with gr.Tab(label=translations["read_model"], visible=configs.get("read_tab", True)):
|
426 |
+
gr.Markdown(translations["read_model_markdown"])
|
427 |
+
with gr.Row():
|
428 |
+
gr.Markdown(translations["read_model_markdown_2"])
|
429 |
+
with gr.Row():
|
430 |
+
model = gr.File(label=translations["drop_model"], file_types=[".pth", ".onnx"])
|
431 |
+
with gr.Row():
|
432 |
+
read_button = gr.Button(translations["readmodel"], variant="primary", scale=2)
|
433 |
+
with gr.Column():
|
434 |
+
model_path = gr.Textbox(label=translations["model_path"], value="", placeholder="assets/weights/Model.pth", info=translations["model_path_info"], interactive=True)
|
435 |
+
output_info = gr.Textbox(label=translations["modelinfo"], value="", interactive=False, scale=6)
|
436 |
+
with gr.Row():
|
437 |
+
model.upload(fn=lambda model: shutil.move(model.name, os.path.join("assets", "weights")), inputs=[model], outputs=[model_path])
|
438 |
+
read_button.click(
|
439 |
+
fn=model_info,
|
440 |
+
inputs=[model_path],
|
441 |
+
outputs=[output_info],
|
442 |
+
api_name="read_model"
|
443 |
+
)
|
444 |
+
|
445 |
+
with gr.Tab(label=translations["convert_model"], visible=configs.get("onnx_tab", True)):
|
446 |
+
gr.Markdown(translations["pytorch2onnx"])
|
447 |
+
with gr.Row():
|
448 |
+
gr.Markdown(translations["pytorch2onnx_markdown"])
|
449 |
+
with gr.Row():
|
450 |
+
model_pth_upload = gr.File(label=translations["drop_model"], file_types=[".pth"])
|
451 |
+
with gr.Row():
|
452 |
+
convert_onnx = gr.Button(translations["convert_model"], variant="primary", scale=2)
|
453 |
+
with gr.Row():
|
454 |
+
model_pth_path = gr.Textbox(label=translations["model_path"], value="", placeholder="assets/weights/Model.pth", info=translations["model_path_info"], interactive=True)
|
455 |
+
with gr.Row():
|
456 |
+
output_model2 = gr.File(label=translations["output_model_path"], file_types=[".pth", ".onnx"], interactive=False, visible=False)
|
457 |
+
with gr.Row():
|
458 |
+
model_pth_upload.upload(fn=lambda model_pth_upload: shutil.move(model_pth_upload.name, os.path.join("assets", "weights")), inputs=[model_pth_upload], outputs=[model_pth_path])
|
459 |
+
convert_onnx.click(
|
460 |
+
fn=onnx_export,
|
461 |
+
inputs=[model_pth_path],
|
462 |
+
outputs=[output_model2, output_info],
|
463 |
+
api_name="model_onnx_export"
|
464 |
+
)
|
465 |
+
convert_onnx.click(fn=lambda: visible(True), inputs=[], outputs=[output_model2])
|