R-Kentaren commited on
Commit
6367833
·
verified ·
1 Parent(s): e86b842

Update src/webui.py

Browse files
Files changed (1) hide show
  1. src/webui.py +449 -394
src/webui.py CHANGED
@@ -1,394 +1,449 @@
1
- import json
2
- import os
3
- import shutil
4
- import urllib.request
5
- import zipfile
6
- from argparse import ArgumentParser
7
- import spaces
8
- import gradio as gr
9
- import logging
10
- def configure_logging_libs(debug=False):
11
- modules = [
12
- "numba",
13
- "httpx",
14
- "markdown_it",
15
- "fairseq",
16
- "faiss",
17
- ]
18
- try:
19
- for module in modules:
20
- logging.getLogger(module).setLevel(logging.WARNING)
21
- os.environ['TF_CPP_MIN_LOG_LEVEL'] = "3" if not debug else "1"
22
-
23
- except Exception as error:
24
- pass
25
- configure_logging_libs()
26
-
27
- from main import song_cover_pipeline, yt_download
28
-
29
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
30
- IS_ZERO_GPU = os.getenv("SPACES_ZERO_GPU")
31
-
32
- mdxnet_models_dir = os.path.join(BASE_DIR, 'mdxnet_models')
33
- rvc_models_dir = os.path.join(BASE_DIR, 'rvc_models')
34
- output_dir = os.path.join(BASE_DIR, 'song_output')
35
-
36
-
37
- def get_current_models(models_dir):
38
- models_list = os.listdir(models_dir)
39
- items_to_remove = ['hubert_base.pt', 'MODELS.txt', 'public_models.json', 'rmvpe.pt']
40
- return [item for item in models_list if item not in items_to_remove]
41
-
42
-
43
- def update_models_list():
44
- models_l = get_current_models(rvc_models_dir)
45
- return gr.update(choices=models_l)
46
-
47
-
48
- def load_public_models():
49
- models_table = []
50
- for model in public_models['voice_models']:
51
- if not model['name'] in voice_models:
52
- model = [model['name'], model['description'], model['credit'], model['url'], ', '.join(model['tags'])]
53
- models_table.append(model)
54
-
55
- tags = list(public_models['tags'].keys())
56
- return gr.update(value=models_table), gr.update(choices=tags)
57
-
58
-
59
- def extract_zip(extraction_folder, zip_name):
60
- os.makedirs(extraction_folder)
61
- with zipfile.ZipFile(zip_name, 'r') as zip_ref:
62
- zip_ref.extractall(extraction_folder)
63
- os.remove(zip_name)
64
-
65
- index_filepath, model_filepath = None, None
66
- for root, dirs, files in os.walk(extraction_folder):
67
- for name in files:
68
- if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
69
- index_filepath = os.path.join(root, name)
70
-
71
- if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
72
- model_filepath = os.path.join(root, name)
73
-
74
- if not model_filepath:
75
- raise gr.Error(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
76
-
77
- # move model and index file to extraction folder
78
- os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
79
- if index_filepath:
80
- os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
81
-
82
- # remove any unnecessary nested folders
83
- for filepath in os.listdir(extraction_folder):
84
- if os.path.isdir(os.path.join(extraction_folder, filepath)):
85
- shutil.rmtree(os.path.join(extraction_folder, filepath))
86
-
87
-
88
- def download_online_model(url, dir_name, progress=gr.Progress()):
89
- try:
90
- progress(0, desc=f'[~] Downloading voice model with name {dir_name}...')
91
- zip_name = url.split('/')[-1]
92
- extraction_folder = os.path.join(rvc_models_dir, dir_name)
93
- if os.path.exists(extraction_folder):
94
- raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
95
-
96
- if 'pixeldrain.com' in url:
97
- url = f'https://pixeldrain.com/api/file/{zip_name}'
98
-
99
-
100
- if "," in url:
101
- urls = [u.strip() for u in url.split(",") if u.strip()]
102
- os.makedirs(extraction_folder, exist_ok=True)
103
- for u in urls:
104
- u = u.replace("?download=true", "")
105
- file_name = u.split('/')[-1]
106
- file_path = os.path.join(extraction_folder, file_name)
107
- if not os.path.exists(file_path): # avoid re-downloading
108
- urllib.request.urlretrieve(u, file_path)
109
- else:
110
- urllib.request.urlretrieve(url, zip_name)
111
-
112
- progress(0.5, desc='[~] Extracting zip...')
113
- extract_zip(extraction_folder, zip_name)
114
- return f'[+] {dir_name} Model successfully downloaded!'
115
-
116
- except Exception as e:
117
- raise gr.Error(str(e))
118
-
119
-
120
- def upload_local_model(zip_path, dir_name, progress=gr.Progress()):
121
- try:
122
- extraction_folder = os.path.join(rvc_models_dir, dir_name)
123
- if os.path.exists(extraction_folder):
124
- raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
125
-
126
- zip_name = zip_path.name
127
- progress(0.5, desc='[~] Extracting zip...')
128
- extract_zip(extraction_folder, zip_name)
129
- return f'[+] {dir_name} Model successfully uploaded!'
130
-
131
- except Exception as e:
132
- raise gr.Error(str(e))
133
-
134
-
135
- def filter_models(tags, query):
136
- models_table = []
137
-
138
- # no filter
139
- if len(tags) == 0 and len(query) == 0:
140
- for model in public_models['voice_models']:
141
- models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
142
-
143
- # filter based on tags and query
144
- elif len(tags) > 0 and len(query) > 0:
145
- for model in public_models['voice_models']:
146
- if all(tag in model['tags'] for tag in tags):
147
- model_attributes = f"{model['name']} {model['description']} {model['credit']} {' '.join(model['tags'])}".lower()
148
- if query.lower() in model_attributes:
149
- models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
150
-
151
- # filter based on only tags
152
- elif len(tags) > 0:
153
- for model in public_models['voice_models']:
154
- if all(tag in model['tags'] for tag in tags):
155
- models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
156
-
157
- # filter based on only query
158
- else:
159
- for model in public_models['voice_models']:
160
- model_attributes = f"{model['name']} {model['description']} {model['credit']} {' '.join(model['tags'])}".lower()
161
- if query.lower() in model_attributes:
162
- models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
163
-
164
- return gr.update(value=models_table)
165
-
166
-
167
- def pub_dl_autofill(pub_models, event: gr.SelectData):
168
- return gr.update(value=pub_models.loc[event.index[0], 'URL']), gr.update(value=pub_models.loc[event.index[0], 'Model Name'])
169
-
170
-
171
- def swap_visibility():
172
- return gr.update(visible=True), gr.update(visible=False), gr.update(value=''), gr.update(value=None)
173
-
174
-
175
- def process_file_upload(file):
176
- return file.name, gr.update(value=file.name)
177
-
178
-
179
- def show_hop_slider(pitch_detection_algo):
180
- if pitch_detection_algo == 'mangio-crepe':
181
- return gr.update(visible=True)
182
- else:
183
- return gr.update(visible=False)
184
-
185
-
186
-
187
-
188
-
189
-
190
- if __name__ == '__main__':
191
- parser = ArgumentParser(description='Generate a AI cover song in the song_output/id directory.', add_help=True)
192
- parser.add_argument("--share", action="store_true", dest="share_enabled", default=False, help="Enable sharing")
193
- parser.add_argument("--builtin-player", action="store_true", default=False, help="Use the builtin audio player")
194
- parser.add_argument("--listen", action="store_true", default=False, help="Make the WebUI reachable from your local network.")
195
- parser.add_argument('--listen-host', type=str, help='The hostname that the server will use.')
196
- parser.add_argument('--listen-port', type=int, help='The listening port that the server will use.')
197
- parser.add_argument('--theme', type=str, default="NoCrypt/miku", help='Set the theme (default: NoCrypt/miku)')
198
- parser.add_argument("--ssr", action="store_true", help="Enable SSR (Server-Side Rendering)")
199
- args = parser.parse_args()
200
-
201
- voice_models = get_current_models(rvc_models_dir)
202
- with open(os.path.join(rvc_models_dir, 'public_models.json'), encoding='utf8') as infile:
203
- public_models = json.load(infile)
204
-
205
- with gr.Blocks(title='AICoverGenWebUI', theme=args.theme, fill_width=True, fill_height=False) as app:
206
-
207
- gr.Label(f'AICoverGen WebUI {"ZeroGPU mode" if IS_ZERO_GPU else ""} created with ❤️', show_label=False)
208
- if IS_ZERO_GPU:
209
- gr.Markdown(
210
- """
211
- <details>
212
- <summary style="font-size: 1.5em;">⚠️ Important (click to expand)</summary>
213
- <ul>
214
- <li>🚀 This demo use a Zero GPU, which is available only for a limited time. It's recommended to use audio files that are no longer than 5 minutes. If you want to use it without time restrictions, you can duplicate the 'old CPU space'. ⏳</li>
215
- </ul>
216
- </details>
217
- """
218
- )
219
- gr.Markdown("Duplicate the old CPU space for use in private: [![Duplicate this Space](https://huggingface.co/datasets/huggingface/badges/raw/main/duplicate-this-space-sm-dark.svg)](https://huggingface.co/spaces/r3gm/AICoverGen_old_stable_cpu?duplicate=true)\n\n")
220
-
221
- # main tab
222
- with gr.Tab("Generate"):
223
-
224
- with gr.Accordion('Main Options'):
225
- with gr.Row():
226
- with gr.Column():
227
- rvc_model = gr.Dropdown(voice_models, label='Voice Models', info='Models folder "AICoverGen --> rvc_models". After new models are added into this folder, click the refresh button')
228
- ref_btn = gr.Button('Refresh Models 🔁', variant='primary')
229
-
230
- with gr.Column(visible=False) as yt_link_col:
231
- song_input = gr.Text(label='Song input', info='Link to a song on YouTube or full path to a local file. For file upload, click the button below.')
232
- show_file_upload_button = gr.Button('Upload file instead')
233
-
234
- with gr.Column(visible=True) as file_upload_col:
235
- audio_extensions = ['.mp3', '.m4a', '.flac', '.wav', '.aac', '.ogg', '.wma', '.alac', '.aiff', '.opus', 'amr']
236
- local_file = gr.File(label='Audio file', interactive=True, type="filepath", file_types=audio_extensions, height=150)
237
- if not IS_ZERO_GPU:
238
- with gr.Row():
239
- with gr.Row(scale=2):
240
- url_media_gui = gr.Textbox(value="", label="Enter URL", placeholder="www.youtube.com/watch?v=g_9rPvbENUw", lines=1)
241
- with gr.Row(scale=1):
242
- url_button_gui = gr.Button("Process URL", variant="secondary")
243
- url_button_gui.click(yt_download, [url_media_gui], [local_file])
244
- song_input_file = gr.UploadButton('Upload 📂', file_types=['audio'], variant='primary', visible=False)
245
- show_yt_link_button = gr.Button('Paste YouTube link/Path to local file instead', visible=False)
246
- song_input_file.upload(process_file_upload, inputs=[song_input_file], outputs=[local_file, song_input])
247
-
248
- with gr.Column():
249
- pitch = gr.Slider(-3, 3, value=0, step=1, label='Pitch Change (Vocals ONLY)', info='Generally, use 1 for male to female conversions and -1 for vice-versa. (Octaves)')
250
- pitch_all = gr.Slider(-12, 12, value=0, step=1, label='Overall Pitch Change', info='Changes pitch/key of vocals and instrumentals together. Altering this slightly reduces sound quality. (Semitones)')
251
- show_file_upload_button.click(swap_visibility, outputs=[file_upload_col, yt_link_col, song_input, local_file])
252
- show_yt_link_button.click(swap_visibility, outputs=[yt_link_col, file_upload_col, song_input, local_file])
253
-
254
- with gr.Accordion('Voice conversion options', open=False):
255
- with gr.Row():
256
- index_rate = gr.Slider(0, 1, value=0.5, label='Index Rate', info="Controls how much of the AI voice's accent to keep in the vocals")
257
- filter_radius = gr.Slider(0, 7, value=3, step=1, label='Filter radius', info='If >=3: apply median filtering median filtering to the harvested pitch results. Can reduce breathiness')
258
- rms_mix_rate = gr.Slider(0, 1, value=0.25, label='RMS mix rate', info="Control how much to mimic the original vocal's loudness (0) or a fixed loudness (1)")
259
- protect = gr.Slider(0, 0.5, value=0.33, label='Protect rate', info='Protect voiceless consonants and breath sounds. Set to 0.5 to disable.')
260
- with gr.Column():
261
- f0_method = gr.Dropdown(['rmvpe+', 'rmvpe', 'mangio-crepe'], value='rmvpe+', label='Pitch detection algorithm', info='Best option is rmvpe (clarity in vocals), then mangio-crepe (smoother vocals), rmvpe+ use a minimum and maximum allowed pitch values.')
262
- crepe_hop_length = gr.Slider(32, 320, value=128, step=1, visible=False, label='Crepe hop length', info='Lower values leads to longer conversions and higher risk of voice cracks, but better pitch accuracy.')
263
- f0_method.change(show_hop_slider, inputs=f0_method, outputs=crepe_hop_length)
264
- with gr.Row():
265
- with gr.Row():
266
- steps = gr.Slider(minimum=1, maximum=3, label="Steps", value=1, step=1, interactive=True)
267
- with gr.Row():
268
- extra_denoise = gr.Checkbox(True, label='Denoise', info='Apply an additional noise reduction step to clean up the audio further.')
269
- keep_files = gr.Checkbox((False if IS_ZERO_GPU else True), label='Keep intermediate files', info='Keep all audio files generated in the song_output/id directory, e.g. Isolated Vocals/Instrumentals. Leave unchecked to save space', interactive=(False if IS_ZERO_GPU else True))
270
-
271
- with gr.Accordion('Audio mixing options', open=False):
272
- gr.Markdown('### Volume Change (decibels)')
273
- with gr.Row():
274
- main_gain = gr.Slider(-20, 20, value=0, step=1, label='Main Vocals')
275
- backup_gain = gr.Slider(-20, 20, value=0, step=1, label='Backup Vocals')
276
- inst_gain = gr.Slider(-20, 20, value=0, step=1, label='Music')
277
-
278
- gr.Markdown('### Reverb Control on AI Vocals')
279
- with gr.Row():
280
- reverb_rm_size = gr.Slider(0, 1, value=0.15, label='Room size', info='The larger the room, the longer the reverb time')
281
- reverb_wet = gr.Slider(0, 1, value=0.2, label='Wetness level', info='Level of AI vocals with reverb')
282
- reverb_dry = gr.Slider(0, 1, value=0.8, label='Dryness level', info='Level of AI vocals without reverb')
283
- reverb_damping = gr.Slider(0, 1, value=0.7, label='Damping level', info='Absorption of high frequencies in the reverb')
284
-
285
- gr.Markdown('### Audio Output Format')
286
- output_format = gr.Dropdown(['mp3', 'wav'], value='mp3', label='Output file type', info='mp3: small file size, decent quality. wav: Large file size, best quality')
287
-
288
- with gr.Row():
289
- clear_btn = gr.ClearButton(value='Clear', components=[song_input, rvc_model, keep_files, local_file])
290
- generate_btn = gr.Button("Generate", variant='primary')
291
- ai_cover = (
292
- gr.Audio(label='AI Cover', show_share_button=True)
293
- if args.builtin_player else
294
- gr.File(label="AI Cover", interactive=False)
295
- )
296
- gr.Markdown("- You can also try `AICoverGen❤️` in Colab’s free tier, which provides free GPU [link](https://github.com/R3gm/AICoverGen?tab=readme-ov-file#aicovergen).")
297
-
298
- ref_btn.click(update_models_list, None, outputs=rvc_model)
299
- is_webui = gr.Number(value=1, visible=False)
300
- generate_btn.click(song_cover_pipeline,
301
- inputs=[local_file, rvc_model, pitch, keep_files, is_webui, main_gain, backup_gain,
302
- inst_gain, index_rate, filter_radius, rms_mix_rate, f0_method, crepe_hop_length,
303
- protect, pitch_all, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping,
304
- output_format, extra_denoise, steps],
305
- outputs=[ai_cover])
306
- clear_btn.click(lambda: [0, 0, 0, 0, 0.5, 3, 0.25, 0.33, 'rmvpe+', 128, 0, 0.15, 0.2, 0.8, 0.7, 'mp3', None, True, 1],
307
- outputs=[pitch, main_gain, backup_gain, inst_gain, index_rate, filter_radius, rms_mix_rate,
308
- protect, f0_method, crepe_hop_length, pitch_all, reverb_rm_size, reverb_wet,
309
- reverb_dry, reverb_damping, output_format, ai_cover, extra_denoise, steps])
310
-
311
- # Download tab
312
- with gr.Tab('Download model'):
313
-
314
- with gr.Tab('From HuggingFace/Pixeldrain URL'):
315
- with gr.Row():
316
- model_zip_link = gr.Text(label='Download link to model', info='Should be a zip file containing a .pth model file and an optional .index file.')
317
- model_name = gr.Text(label='Name your model', info='Give your new model a unique name from your other voice models.')
318
-
319
- with gr.Row():
320
- download_btn = gr.Button('Download 🌐', variant='primary', scale=19)
321
- dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
322
-
323
- download_btn.click(download_online_model, inputs=[model_zip_link, model_name], outputs=dl_output_message)
324
-
325
- gr.Markdown('## Input Examples')
326
- gr.Examples(
327
- [
328
- ['https://huggingface.co/MrDawg/ToothBrushing/resolve/main/ToothBrushing.zip?download=true', 'ToothBrushing'],
329
- ['https://huggingface.co/sail-rvc/Aldeano_Minecraft__RVC_V2_-_500_Epochs_/resolve/main/model.pth?download=true, https://huggingface.co/sail-rvc/Aldeano_Minecraft__RVC_V2_-_500_Epochs_/resolve/main/model.index?download=true', 'Minecraft_Villager'],
330
- ['https://huggingface.co/phant0m4r/LiSA/resolve/main/LiSA.zip', 'Lisa'],
331
- ['https://pixeldrain.com/u/3tJmABXA', 'Gura'],
332
- ['https://huggingface.co/Kit-Lemonfoot/kitlemonfoot_rvc_models/resolve/main/AZKi%20(Hybrid).zip', 'Azki']
333
- ],
334
- [model_zip_link, model_name],
335
- [],
336
- download_online_model,
337
- cache_examples=False,
338
- )
339
-
340
- with gr.Tab('From Public Index'):
341
-
342
- gr.Markdown('## How to use')
343
- gr.Markdown('- Click Initialize public models table')
344
- gr.Markdown('- Filter models using tags or search bar')
345
- gr.Markdown('- Select a row to autofill the download link and model name')
346
- gr.Markdown('- Click Download')
347
-
348
- with gr.Row():
349
- pub_zip_link = gr.Text(label='Download link to model')
350
- pub_model_name = gr.Text(label='Model name')
351
-
352
- with gr.Row():
353
- download_pub_btn = gr.Button('Download 🌐', variant='primary', scale=19)
354
- pub_dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
355
-
356
- filter_tags = gr.CheckboxGroup(value=[], label='Show voice models with tags', choices=[])
357
- search_query = gr.Text(label='Search')
358
- load_public_models_button = gr.Button(value='Initialize public models table', variant='primary')
359
-
360
- public_models_table = gr.DataFrame(value=[], headers=['Model Name', 'Description', 'Credit', 'URL', 'Tags'], label='Available Public Models', interactive=False)
361
- public_models_table.select(pub_dl_autofill, inputs=[public_models_table], outputs=[pub_zip_link, pub_model_name])
362
- load_public_models_button.click(load_public_models, outputs=[public_models_table, filter_tags])
363
- search_query.change(filter_models, inputs=[filter_tags, search_query], outputs=public_models_table)
364
- filter_tags.change(filter_models, inputs=[filter_tags, search_query], outputs=public_models_table)
365
- download_pub_btn.click(download_online_model, inputs=[pub_zip_link, pub_model_name], outputs=pub_dl_output_message)
366
-
367
- # Upload tab
368
- with gr.Tab('Upload model'):
369
- gr.Markdown('## Upload locally trained RVC v2 model and index file')
370
- gr.Markdown('- Find model file (weights folder) and optional index file (logs/[name] folder)')
371
- gr.Markdown('- Compress files into zip file')
372
- gr.Markdown('- Upload zip file and give unique name for voice')
373
- gr.Markdown('- Click Upload model')
374
-
375
- with gr.Row():
376
- with gr.Column():
377
- zip_file = gr.File(label='Zip file')
378
-
379
- local_model_name = gr.Text(label='Model name')
380
-
381
- with gr.Row():
382
- model_upload_button = gr.Button('Upload model', variant='primary', scale=19)
383
- local_upload_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
384
- model_upload_button.click(upload_local_model, inputs=[zip_file, local_model_name], outputs=local_upload_output_message)
385
-
386
- app.launch(
387
- share=args.share_enabled,
388
- debug=args.share_enabled,
389
- show_error=True,
390
- # enable_queue=True,
391
- server_name=None if not args.listen else (args.listen_host or '0.0.0.0'),
392
- server_port=args.listen_port,
393
- ssr_mode=args.ssr
394
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import shutil
4
+ import urllib.request
5
+ import zipfile
6
+ from argparse import ArgumentParser
7
+ import spaces
8
+ import gradio as gr
9
+ import logging
10
+ def configure_logging_libs(debug=False):
11
+ modules = [
12
+ "numba",
13
+ "httpx",
14
+ "markdown_it",
15
+ "fairseq",
16
+ "faiss",
17
+ ]
18
+ try:
19
+ for module in modules:
20
+ logging.getLogger(module).setLevel(logging.WARNING)
21
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = "3" if not debug else "1"
22
+
23
+ except Exception as error:
24
+ pass
25
+ configure_logging_libs()
26
+
27
+ from main import song_cover_pipeline, yt_download
28
+
29
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
30
+ IS_ZERO_GPU = os.getenv("SPACES_ZERO_GPU")
31
+
32
+ mdxnet_models_dir = os.path.join(BASE_DIR, 'mdxnet_models')
33
+ rvc_models_dir = os.path.join(BASE_DIR, 'rvc_models')
34
+ output_dir = os.path.join(BASE_DIR, 'song_output')
35
+
36
+
37
+ def get_current_models(models_dir):
38
+ models_list = os.listdir(models_dir)
39
+ items_to_remove = ['hubert_base.pt', 'MODELS.txt', 'public_models.json', 'rmvpe.pt']
40
+ return [item for item in models_list if item not in items_to_remove]
41
+
42
+
43
+ def update_models_list():
44
+ models_l = get_current_models(rvc_models_dir)
45
+ return gr.update(choices=models_l)
46
+
47
+
48
+ def load_public_models():
49
+ models_table = []
50
+ for model in public_models['voice_models']:
51
+ if not model['name'] in voice_models:
52
+ model = [model['name'], model['description'], model['credit'], model['url'], ', '.join(model['tags'])]
53
+ models_table.append(model)
54
+
55
+ tags = list(public_models['tags'].keys())
56
+ return gr.update(value=models_table), gr.update(choices=tags)
57
+
58
+
59
+ def extract_zip(extraction_folder, zip_name):
60
+ os.makedirs(extraction_folder)
61
+ with zipfile.ZipFile(zip_name, 'r') as zip_ref:
62
+ zip_ref.extractall(extraction_folder)
63
+ os.remove(zip_name)
64
+
65
+ index_filepath, model_filepath = None, None
66
+ for root, dirs, files in os.walk(extraction_folder):
67
+ for name in files:
68
+ if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
69
+ index_filepath = os.path.join(root, name)
70
+
71
+ if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
72
+ model_filepath = os.path.join(root, name)
73
+
74
+ if not model_filepath:
75
+ raise gr.Error(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
76
+
77
+ # move model and index file to extraction folder
78
+ os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
79
+ if index_filepath:
80
+ os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
81
+
82
+ # remove any unnecessary nested folders
83
+ for filepath in os.listdir(extraction_folder):
84
+ if os.path.isdir(os.path.join(extraction_folder, filepath)):
85
+ shutil.rmtree(os.path.join(extraction_folder, filepath))
86
+
87
+
88
+ def download_online_model(url, dir_name, progress=gr.Progress()):
89
+ try:
90
+ progress(0, desc=f'[~] Downloading voice model with name {dir_name}...')
91
+ zip_name = url.split('/')[-1]
92
+ extraction_folder = os.path.join(rvc_models_dir, dir_name)
93
+ if os.path.exists(extraction_folder):
94
+ raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
95
+
96
+ if 'pixeldrain.com' in url:
97
+ url = f'https://pixeldrain.com/api/file/{zip_name}'
98
+
99
+
100
+ if "," in url:
101
+ urls = [u.strip() for u in url.split(",") if u.strip()]
102
+ os.makedirs(extraction_folder, exist_ok=True)
103
+ for u in urls:
104
+ u = u.replace("?download=true", "")
105
+ file_name = u.split('/')[-1]
106
+ file_path = os.path.join(extraction_folder, file_name)
107
+ if not os.path.exists(file_path): # avoid re-downloading
108
+ urllib.request.urlretrieve(u, file_path)
109
+ else:
110
+ urllib.request.urlretrieve(url, zip_name)
111
+
112
+ progress(0.5, desc='[~] Extracting zip...')
113
+ extract_zip(extraction_folder, zip_name)
114
+ return f'[+] {dir_name} Model successfully downloaded!'
115
+
116
+ except Exception as e:
117
+ raise gr.Error(str(e))
118
+
119
+
120
+ def upload_local_model(zip_path, dir_name, progress=gr.Progress()):
121
+ try:
122
+ extraction_folder = os.path.join(rvc_models_dir, dir_name)
123
+ if os.path.exists(extraction_folder):
124
+ raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
125
+
126
+ zip_name = zip_path.name
127
+ progress(0.5, desc='[~] Extracting zip...')
128
+ extract_zip(extraction_folder, zip_name)
129
+ return f'[+] {dir_name} Model successfully uploaded!'
130
+
131
+ except Exception as e:
132
+ raise gr.Error(str(e))
133
+
134
+
135
+ def filter_models(tags, query):
136
+ models_table = []
137
+
138
+ # no filter
139
+ if len(tags) == 0 and len(query) == 0:
140
+ for model in public_models['voice_models']:
141
+ models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
142
+
143
+ # filter based on tags and query
144
+ elif len(tags) > 0 and len(query) > 0:
145
+ for model in public_models['voice_models']:
146
+ if all(tag in model['tags'] for tag in tags):
147
+ model_attributes = f"{model['name']} {model['description']} {model['credit']} {' '.join(model['tags'])}".lower()
148
+ if query.lower() in model_attributes:
149
+ models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
150
+
151
+ # filter based on only tags
152
+ elif len(tags) > 0:
153
+ for model in public_models['voice_models']:
154
+ if all(tag in model['tags'] for tag in tags):
155
+ models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
156
+
157
+ # filter based on only query
158
+ else:
159
+ for model in public_models['voice_models']:
160
+ model_attributes = f"{model['name']} {model['description']} {model['credit']} {' '.join(model['tags'])}".lower()
161
+ if query.lower() in model_attributes:
162
+ models_table.append([model['name'], model['description'], model['credit'], model['url'], model['tags']])
163
+
164
+ return gr.update(value=models_table)
165
+
166
+
167
+ def pub_dl_autofill(pub_models, event: gr.SelectData):
168
+ return gr.update(value=pub_models.loc[event.index[0], 'URL']), gr.update(value=pub_models.loc[event.index[0], 'Model Name'])
169
+
170
+
171
+ def swap_visibility():
172
+ return gr.update(visible=True), gr.update(visible=False), gr.update(value=''), gr.update(value=None)
173
+
174
+
175
+ def process_file_upload(file):
176
+ return file.name, gr.update(value=file.name)
177
+
178
+
179
+ def show_hop_slider(pitch_detection_algo):
180
+ if pitch_detection_algo == 'mangio-crepe':
181
+ return gr.update(visible=True)
182
+ else:
183
+ return gr.update(visible=False)
184
+
185
+
186
+ CSS = """
187
+ :root{color-scheme:dark;--paper:#111412;--panel:#181c19;--panel-2:#141815;--ink:#f3f4ef;--muted:#9ea8a0;--line:#303732;--signal:#2486ff;--signal-hover:#52a0ff;--signal-soft:#15263b}
188
+ html,body,.gradio-container,.dark{background:var(--paper)!important;color:var(--ink)!important;color-scheme:dark!important}
189
+ body,.gradio-container,.gradio-container button,.gradio-container input,.gradio-container textarea{font-family:Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif!important}
190
+ .gradio-container{width:min(100%,1640px)!important;max-width:none!important;margin:auto!important;padding:0 clamp(14px,2.2vw,34px) 54px!important;box-sizing:border-box!important}
191
+ .gradio-container>.main{padding:0!important}
192
+ .gradio-container *{box-sizing:border-box}
193
+ .hero-wrap,.hero-wrap.block,.hero-wrap>.wrap{padding:0!important;border:0!important;box-shadow:none!important;background:transparent!important}
194
+ .hero{padding:18px 2px 13px;border-bottom:1px solid var(--line);margin-bottom:2px}
195
+ .hero-top{display:flex;align-items:center;justify-content:space-between;gap:20px}
196
+ .eyebrow{color:var(--signal);font:700 11px/1 ui-monospace,SFMono-Regular,Consolas,monospace;letter-spacing:.13em;text-transform:uppercase}
197
+ .links{display:flex;align-items:center;gap:18px;font-size:12px;font-weight:700}
198
+ .links a{color:var(--muted)!important;text-decoration:none}.links a:hover{color:var(--ink)!important}
199
+ .hero h1{max-width:1040px;margin:15px 0 8px;color:var(--ink);font:650 clamp(40px,4.5vw,56px)/.96 Inter,ui-sans-serif,sans-serif;letter-spacing:-.055em}
200
+ .hero>p{max-width:1000px;margin:0;color:var(--muted)!important;font-size:13px;line-height:1.48}
201
+ .model-facts{display:flex;align-items:stretch;margin-top:13px;border-top:1px solid var(--line)}
202
+ .model-fact{flex:1;padding:8px 24px 0 0;color:var(--muted)!important;font-size:11px;line-height:1.3}
203
+ .model-fact+.model-fact{padding-left:20px;border-left:1px solid var(--line)}
204
+ .model-fact strong{display:block;margin-bottom:2px;color:var(--ink);font-size:14px;line-height:1.2}
205
+ .runtime-tabs{margin:14px 10px 0!important}
206
+ .runtime-tabs>.tab-container,.runtime-tabs .tab-container{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:0!important;height:auto!important;overflow:hidden!important;border:1px solid var(--line)!important;border-radius:2px!important;background:var(--panel-2)!important}
207
+ .runtime-tabs>.tab-container button,.runtime-tabs .tab-container button{display:flex!important;min-height:54px!important;padding:9px 14px!important;flex-direction:column!important;align-items:flex-start!important;justify-content:center!important;border:0!important;border-radius:0!important;background:transparent!important;color:var(--ink)!important;font-size:13px!important;font-weight:800!important;line-height:1.2!important;letter-spacing:.005em!important;transition:background .16s ease,color .16s ease!important}
208
+ .runtime-tabs>.tab-container button+button,.runtime-tabs .tab-container button+button{border-left:1px solid var(--line)!important}
209
+ .runtime-tabs>.tab-container button::after,.runtime-tabs .tab-container button::after{margin-top:3px;color:var(--muted);font-size:10px;font-weight:550;letter-spacing:.01em}
210
+ .runtime-tabs>.tab-container button:nth-child(1)::after,.runtime-tabs .tab-container button:nth-child(1)::after{content:"Hugging Face ZeroGPU"}
211
+ .runtime-tabs>.tab-container button:nth-child(2)::after,.runtime-tabs .tab-container button:nth-child(2)::after{content:"WebGPU / WASM · private"}
212
+ .runtime-tabs>.tab-container button:hover,.runtime-tabs .tab-container button:hover{background:#1b242d!important;color:var(--ink)!important}
213
+ .runtime-tabs>.tab-container button.selected,.runtime-tabs .tab-container button.selected{background:var(--signal-soft)!important;color:#fff!important;box-shadow:inset 0 -2px 0 var(--signal)!important}
214
+ .runtime-tabs>.tab-container button.selected::after,.runtime-tabs .tab-container button.selected::after{color:#a9c7e8!important}
215
+ .runtime-tabs>.tabitem,.runtime-tabs .tabitem{padding-top:0!important;border:0!important;background:transparent!important}
216
+ .mode-banner{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:16px;margin:10px 0;padding:9px 11px;border:1px solid var(--line);border-left:2px solid var(--signal);border-radius:2px;background:var(--panel-2)}
217
+ .mode-banner strong{display:block;margin-bottom:2px;color:var(--ink)!important;font-size:12px}
218
+ .mode-banner span{color:var(--muted)!important;font-size:11px;line-height:1.45}
219
+ .mode-badge{padding:5px 7px;border:1px solid #356ea8;border-radius:2px;color:#dceaff!important;font:750 9px/1 ui-monospace,SFMono-Regular,Consolas,monospace!important;letter-spacing:.08em;text-transform:uppercase;white-space:nowrap}
220
+ .browser-frame-shell{margin:0;padding:0;border:1px solid var(--line);border-radius:2px;background:var(--paper);overflow:hidden}
221
+ .browser-frame{display:block;width:100%;height:580px;border:0;background:var(--paper);transition:height .18s ease}
222
+ .browser-help{margin:9px 2px 0!important;color:var(--muted)!important;font-size:11px!important;line-height:1.5!important}
223
+ .workbench{padding:0 0 4px!important;border:0!important;background:transparent!important}
224
+ .workbench.block,.workbench>.wrap{border:0!important;box-shadow:none!important;background:transparent!important}
225
+ .control-row{align-items:stretch!important;gap:18px!important;margin-top:6px!important;padding:12px 14px 11px!important;border:1px solid var(--line)!important;border-radius:3px!important;background:var(--panel-2)!important}
226
+ .control-row>div{min-width:0!important}
227
+ .control-row .form{height:100%!important;border:0!important;background:transparent!important}
228
+ .control-row label>span:first-child{font-size:12px!important;font-weight:750!important;letter-spacing:.015em!important}
229
+ .model-switch .wrap{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:0!important;padding:0!important;overflow:hidden!important;border:1px solid var(--line)!important;border-radius:2px!important;background:#101411!important}
230
+ .model-switch .wrap label{min-height:46px!important;margin:0!important;padding:10px 12px!important;border:0!important;border-radius:0!important;background:transparent!important}
231
+ .model-switch .wrap label+label{border-left:1px solid var(--line)!important}
232
+ .model-switch .wrap label:has(input:checked){background:var(--signal-soft)!important;box-shadow:inset 0 -2px 0 var(--signal)!important}
233
+ .model-switch .wrap label span{font-size:12px!important;font-weight:750!important}
234
+ .action-row{justify-content:center!important;gap:12px!important;margin:12px auto 0!important;max-width:840px!important}
235
+ .action-row button{min-height:48px!important}
236
+ .comparison{margin-top:22px!important;padding-top:20px!important;border-top:1px solid var(--line)!important}
237
+ .comparison-title{margin-bottom:9px!important}
238
+ .gradio-container .block,.gradio-container .form{border-radius:3px!important;background:var(--panel-2)!important;border-color:var(--line)!important;color:var(--ink)!important}
239
+ .gradio-container .prose,.gradio-container .markdown-body,.gradio-container label,.gradio-container span,.gradio-container p,.gradio-container h1,.gradio-container h2,.gradio-container h3{color:var(--ink)!important}
240
+ .gradio-container label{background:transparent!important}
241
+ .gradio-container .wrap{background:var(--panel-2)!important}
242
+ .gradio-container select{min-height:48px!important;background:#101411!important;color:var(--ink)!important;border-color:var(--line)!important;text-align:left!important}
243
+ .gradio-container input,.gradio-container textarea{background:#101411!important;color:var(--ink)!important;border-color:var(--line)!important}
244
+ .prompt-input textarea{font-size:16px!important;line-height:1.55!important;min-height:104px!important;padding:15px!important}
245
+ .gradio-container button:not(.primary){background:var(--panel-2)!important;color:var(--ink)!important;border-color:var(--line)!important}
246
+ .gradio-container button:not(.primary):hover{border-color:#527aa6!important;background:#1b242d!important}
247
+ button.primary{min-height:46px!important;border:0!important;border-radius:1px!important;background:var(--signal)!important;color:#fff!important;font-weight:800!important}
248
+ button.primary *{color:#fff!important}button.primary:hover{background:var(--signal-hover)!important}
249
+ .advanced{margin:10px 0 3px!important;background:#131814!important;border-left:2px solid #344138!important}
250
+ .advanced>button{font-size:12px!important;font-weight:750!important;letter-spacing:.01em!important}
251
+ .output-audio{margin-top:8px!important}
252
+ .outputmeta{padding:11px 13px!important;background:var(--signal-soft)!important;border:1px solid #294e78!important}
253
+ .outputmeta *{color:#dceaff!important}
254
+ .helper-copy{margin:8px 2px 4px!important;color:var(--muted)!important;font-size:12px!important}
255
+ .fineprint{color:var(--muted)!important;font-size:12px;line-height:1.55;border-top:1px solid var(--line);padding-top:16px;margin-top:22px}
256
+ footer{display:none!important}
257
+ @media(max-width:760px){
258
+ html,body{overflow-x:hidden!important}.gradio-container{width:100%!important;min-width:0!important;padding:0 14px 38px!important}
259
+ .hero{padding-top:22px}.hero-top{align-items:flex-start;flex-direction:column;gap:12px}.links{gap:14px;font-size:11px}
260
+ .hero h1{margin-top:18px;font-size:42px}.model-facts{display:grid;grid-template-columns:1fr 1fr}.model-fact{padding:11px 10px 9px 0}.model-fact+.model-fact{padding-left:10px}.model-fact:nth-child(3){padding-left:0;border-left:0;border-top:1px solid var(--line)}.model-fact:nth-child(4){border-top:1px solid var(--line)}
261
+ .runtime-tabs{margin-left:0!important;margin-right:0!important}.runtime-tabs>.tab-container button,.runtime-tabs .tab-container button{min-height:54px!important;padding-inline:10px!important}.runtime-tabs>.tab-container button::after,.runtime-tabs .tab-container button::after{font-size:9px}.mode-banner{grid-template-columns:1fr}.mode-badge{justify-self:start}.browser-frame{height:980px}
262
+ .workbench{min-width:0!important;padding-top:18px!important}.control-row,.action-row,.comparison .row{flex-direction:column!important;min-width:0!important}
263
+ .control-row>*,.action-row>*,.comparison .row>*{width:100%!important;min-width:0!important}.gradio-container .wrap,.gradio-container .form,.gradio-container .block{min-width:0!important}
264
+ }
265
+ """
266
+
267
+
268
+
269
+
270
+
271
+ if __name__ == '__main__':
272
+
273
+ voice_models = get_current_models(rvc_models_dir)
274
+ with open(os.path.join(rvc_models_dir, 'public_models.json'), encoding='utf8') as infile:
275
+ public_models = json.load(infile)
276
+
277
+ with gr.Blocks(title='AICoverGenWebUI', css=CSS, fill_width=True, fill_height=False) as app:
278
+
279
+
280
+ # main tab
281
+ with gr.Tab("Generate"):
282
+
283
+ with gr.Accordion('Main Options'):
284
+ with gr.Row():
285
+ with gr.Column():
286
+ rvc_model = gr.Dropdown(voice_models, label='Voice Models', info='Models folder "AICoverGen --> rvc_models". After new models are added into this folder, click the refresh button')
287
+ ref_btn = gr.Button('Refresh Models 🔁', variant='primary')
288
+
289
+ with gr.Column(visible=False) as yt_link_col:
290
+ song_input = gr.Text(label='Song input', info='Link to a song on YouTube or full path to a local file. For file upload, click the button below.')
291
+ show_file_upload_button = gr.Button('Upload file instead')
292
+
293
+ with gr.Column(visible=True) as file_upload_col:
294
+ audio_extensions = ['.mp3', '.m4a', '.flac', '.wav', '.aac', '.ogg', '.wma', '.alac', '.aiff', '.opus', 'amr']
295
+ local_file = gr.Audio(label='Audio file', interactive=True, type="filepath", file_types=audio_extensions, height=150)
296
+ if not IS_ZERO_GPU:
297
+ with gr.Row():
298
+ with gr.Row(scale=2):
299
+ url_media_gui = gr.Textbox(value="", label="Enter URL", placeholder="www.youtube.com/watch?v=g_9rPvbENUw", lines=1)
300
+ with gr.Row(scale=1):
301
+ url_button_gui = gr.Button("Process URL", variant="secondary")
302
+ url_button_gui.click(yt_download, [url_media_gui], [local_file])
303
+ song_input_file = gr.UploadButton('Upload 📂', file_types=['audio'], variant='primary', visible=False)
304
+ show_yt_link_button = gr.Button('Paste YouTube link/Path to local file instead', visible=False)
305
+ song_input_file.upload(process_file_upload, inputs=[song_input_file], outputs=[local_file, song_input])
306
+
307
+ with gr.Column():
308
+ pitch = gr.Slider(-3, 3, value=0, step=1, label='Pitch Change (Vocals ONLY)', info='Generally, use 1 for male to female conversions and -1 for vice-versa. (Octaves)')
309
+ pitch_all = gr.Slider(-12, 12, value=0, step=1, label='Overall Pitch Change', info='Changes pitch/key of vocals and instrumentals together. Altering this slightly reduces sound quality. (Semitones)')
310
+ show_file_upload_button.click(swap_visibility, outputs=[file_upload_col, yt_link_col, song_input, local_file])
311
+ show_yt_link_button.click(swap_visibility, outputs=[yt_link_col, file_upload_col, song_input, local_file])
312
+
313
+ with gr.Accordion('Voice conversion options', open=False):
314
+ with gr.Row():
315
+ index_rate = gr.Slider(0, 1, value=0.5, label='Index Rate', info="Controls how much of the AI voice's accent to keep in the vocals")
316
+ filter_radius = gr.Slider(0, 7, value=3, step=1, label='Filter radius', info='If >=3: apply median filtering median filtering to the harvested pitch results. Can reduce breathiness')
317
+ rms_mix_rate = gr.Slider(0, 1, value=0.25, label='RMS mix rate', info="Control how much to mimic the original vocal's loudness (0) or a fixed loudness (1)")
318
+ protect = gr.Slider(0, 0.5, value=0.33, label='Protect rate', info='Protect voiceless consonants and breath sounds. Set to 0.5 to disable.')
319
+ with gr.Column():
320
+ f0_method = gr.Dropdown(['rmvpe+', 'rmvpe', 'mangio-crepe'], value='rmvpe+', label='Pitch detection algorithm', info='Best option is rmvpe (clarity in vocals), then mangio-crepe (smoother vocals), rmvpe+ use a minimum and maximum allowed pitch values.')
321
+ crepe_hop_length = gr.Slider(32, 320, value=128, step=1, visible=False, label='Crepe hop length', info='Lower values leads to longer conversions and higher risk of voice cracks, but better pitch accuracy.')
322
+ f0_method.change(show_hop_slider, inputs=f0_method, outputs=crepe_hop_length)
323
+ with gr.Row():
324
+ with gr.Row():
325
+ steps = gr.Slider(minimum=1, maximum=3, label="Steps", value=1, step=1, interactive=True)
326
+ with gr.Row():
327
+ extra_denoise = gr.Checkbox(True, label='Denoise', info='Apply an additional noise reduction step to clean up the audio further.')
328
+ keep_files = gr.Checkbox((False if IS_ZERO_GPU else True), label='Keep intermediate files', info='Keep all audio files generated in the song_output/id directory, e.g. Isolated Vocals/Instrumentals. Leave unchecked to save space', interactive=(False if IS_ZERO_GPU else True))
329
+
330
+ with gr.Accordion('Audio mixing options', open=False):
331
+ gr.Markdown('### Volume Change (decibels)')
332
+ with gr.Row():
333
+ main_gain = gr.Slider(-20, 20, value=0, step=1, label='Main Vocals')
334
+ backup_gain = gr.Slider(-20, 20, value=0, step=1, label='Backup Vocals')
335
+ inst_gain = gr.Slider(-20, 20, value=0, step=1, label='Music')
336
+
337
+ gr.Markdown('### Reverb Control on AI Vocals')
338
+ with gr.Row():
339
+ reverb_rm_size = gr.Slider(0, 1, value=0.15, label='Room size', info='The larger the room, the longer the reverb time')
340
+ reverb_wet = gr.Slider(0, 1, value=0.2, label='Wetness level', info='Level of AI vocals with reverb')
341
+ reverb_dry = gr.Slider(0, 1, value=0.8, label='Dryness level', info='Level of AI vocals without reverb')
342
+ reverb_damping = gr.Slider(0, 1, value=0.7, label='Damping level', info='Absorption of high frequencies in the reverb')
343
+
344
+ gr.Markdown('### Audio Output Format')
345
+ output_format = gr.Dropdown(['mp3', 'wav'], value='mp3', label='Output file type', info='mp3: small file size, decent quality. wav: Large file size, best quality')
346
+
347
+ with gr.Row():
348
+ clear_btn = gr.ClearButton(value='Clear', components=[song_input, rvc_model, keep_files, local_file])
349
+ generate_btn = gr.Button("Generate", variant='primary')
350
+ ai_cover = gr.File(label="AI Cover", interactive=False)
351
+
352
+
353
+ ref_btn.click(update_models_list, None, outputs=rvc_model)
354
+ is_webui = gr.Number(value=1, visible=False)
355
+ generate_btn.click(song_cover_pipeline,
356
+ inputs=[local_file, rvc_model, pitch, keep_files, is_webui, main_gain, backup_gain,
357
+ inst_gain, index_rate, filter_radius, rms_mix_rate, f0_method, crepe_hop_length,
358
+ protect, pitch_all, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping,
359
+ output_format, extra_denoise, steps],
360
+ outputs=[ai_cover])
361
+ clear_btn.click(lambda: [0, 0, 0, 0, 0.5, 3, 0.25, 0.33, 'rmvpe+', 128, 0, 0.15, 0.2, 0.8, 0.7, 'mp3', None, True, 1],
362
+ outputs=[pitch, main_gain, backup_gain, inst_gain, index_rate, filter_radius, rms_mix_rate,
363
+ protect, f0_method, crepe_hop_length, pitch_all, reverb_rm_size, reverb_wet,
364
+ reverb_dry, reverb_damping, output_format, ai_cover, extra_denoise, steps])
365
+
366
+ # Download tab
367
+ with gr.Tab('Download model'):
368
+
369
+ with gr.Tab('From HuggingFace/Pixeldrain URL'):
370
+ with gr.Row():
371
+ model_zip_link = gr.Text(label='Download link to model', info='Should be a zip file containing a .pth model file and an optional .index file.')
372
+ model_name = gr.Text(label='Name your model', info='Give your new model a unique name from your other voice models.')
373
+
374
+ with gr.Row():
375
+ download_btn = gr.Button('Download 🌐', variant='primary', scale=19)
376
+ dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
377
+
378
+ download_btn.click(download_online_model, inputs=[model_zip_link, model_name], outputs=dl_output_message)
379
+
380
+ gr.Markdown('## Input Examples')
381
+ gr.Examples(
382
+ [
383
+ ['https://huggingface.co/MrDawg/ToothBrushing/resolve/main/ToothBrushing.zip?download=true', 'ToothBrushing'],
384
+ ['https://huggingface.co/sail-rvc/Aldeano_Minecraft__RVC_V2_-_500_Epochs_/resolve/main/model.pth?download=true, https://huggingface.co/sail-rvc/Aldeano_Minecraft__RVC_V2_-_500_Epochs_/resolve/main/model.index?download=true', 'Minecraft_Villager'],
385
+ ['https://huggingface.co/phant0m4r/LiSA/resolve/main/LiSA.zip', 'Lisa'],
386
+ ['https://pixeldrain.com/u/3tJmABXA', 'Gura'],
387
+ ['https://huggingface.co/Kit-Lemonfoot/kitlemonfoot_rvc_models/resolve/main/AZKi%20(Hybrid).zip', 'Azki']
388
+ ],
389
+ [model_zip_link, model_name],
390
+ [],
391
+ download_online_model,
392
+ cache_examples=False,
393
+ )
394
+
395
+ with gr.Tab('From Public Index'):
396
+
397
+ gr.Markdown('## How to use')
398
+ gr.Markdown('- Click Initialize public models table')
399
+ gr.Markdown('- Filter models using tags or search bar')
400
+ gr.Markdown('- Select a row to autofill the download link and model name')
401
+ gr.Markdown('- Click Download')
402
+
403
+ with gr.Row():
404
+ pub_zip_link = gr.Text(label='Download link to model')
405
+ pub_model_name = gr.Text(label='Model name')
406
+
407
+ with gr.Row():
408
+ download_pub_btn = gr.Button('Download 🌐', variant='primary', scale=19)
409
+ pub_dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
410
+
411
+ filter_tags = gr.CheckboxGroup(value=[], label='Show voice models with tags', choices=[])
412
+ search_query = gr.Text(label='Search')
413
+ load_public_models_button = gr.Button(value='Initialize public models table', variant='primary')
414
+
415
+ public_models_table = gr.DataFrame(value=[], headers=['Model Name', 'Description', 'Credit', 'URL', 'Tags'], label='Available Public Models', interactive=False)
416
+ public_models_table.select(pub_dl_autofill, inputs=[public_models_table], outputs=[pub_zip_link, pub_model_name])
417
+ load_public_models_button.click(load_public_models, outputs=[public_models_table, filter_tags])
418
+ search_query.change(filter_models, inputs=[filter_tags, search_query], outputs=public_models_table)
419
+ filter_tags.change(filter_models, inputs=[filter_tags, search_query], outputs=public_models_table)
420
+ download_pub_btn.click(download_online_model, inputs=[pub_zip_link, pub_model_name], outputs=pub_dl_output_message)
421
+
422
+ # Upload tab
423
+ with gr.Tab('Upload model'):
424
+ gr.Markdown('## Upload locally trained RVC v2 model and index file')
425
+ gr.Markdown('- Find model file (weights folder) and optional index file (logs/[name] folder)')
426
+ gr.Markdown('- Compress files into zip file')
427
+ gr.Markdown('- Upload zip file and give unique name for voice')
428
+ gr.Markdown('- Click Upload model')
429
+
430
+ with gr.Row():
431
+ with gr.Column():
432
+ zip_file = gr.File(label='Zip file')
433
+
434
+ local_model_name = gr.Text(label='Model name')
435
+
436
+ with gr.Row():
437
+ model_upload_button = gr.Button('Upload model', variant='primary', scale=19)
438
+ local_upload_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
439
+ model_upload_button.click(upload_local_model, inputs=[zip_file, local_model_name], outputs=local_upload_output_message)
440
+
441
+ app.launch(
442
+ share=args.share_enabled,
443
+ debug=args.share_enabled,
444
+ show_error=True,
445
+ # enable_queue=True,
446
+ server_name=None if not args.listen else (args.listen_host or '0.0.0.0'),
447
+ server_port=args.listen_port,
448
+ ssr_mode=args.ssr
449
+ )