Hev832 commited on
Commit
572dbf6
1 Parent(s): 7c53875

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -0
app.py CHANGED
@@ -10,6 +10,10 @@ os.system("aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hugging
10
  os.system("aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/sail-rvc/yoimiya-jp/resolve/main/model.pth -d ./weights/yoimiya -o yoimiya.pth")
11
  os.system("aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/sail-rvc/yoimiya-jp/resolve/main/model.index -d ./weights/yoimiya -o yoimiya.index")
12
 
 
 
 
 
13
 
14
 
15
  import edge_tts
@@ -232,6 +236,68 @@ def tts(
232
  return info, None, None
233
 
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  initial_md = """
236
  # RVC text-to-speech webui
237
 
@@ -326,5 +392,49 @@ with app:
326
  inputs=[tts_text, tts_voice],
327
  )
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
 
330
  app.launch()
 
10
  os.system("aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/sail-rvc/yoimiya-jp/resolve/main/model.pth -d ./weights/yoimiya -o yoimiya.pth")
11
  os.system("aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/sail-rvc/yoimiya-jp/resolve/main/model.index -d ./weights/yoimiya -o yoimiya.index")
12
 
13
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
14
+
15
+ rvc_models_dir = os.path.join(BASE_DIR, 'weights')
16
+
17
 
18
 
19
  import edge_tts
 
236
  return info, None, None
237
 
238
 
239
+
240
+ def extract_zip(extraction_folder, zip_name):
241
+ os.makedirs(extraction_folder)
242
+ with zipfile.ZipFile(zip_name, 'r') as zip_ref:
243
+ zip_ref.extractall(extraction_folder)
244
+ os.remove(zip_name)
245
+
246
+ index_filepath, model_filepath = None, None
247
+ for root, dirs, files in os.walk(extraction_folder):
248
+ for name in files:
249
+ if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
250
+ index_filepath = os.path.join(root, name)
251
+
252
+ if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
253
+ model_filepath = os.path.join(root, name)
254
+
255
+ if not model_filepath:
256
+ raise gr.Error(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
257
+
258
+ # move model and index file to extraction folder
259
+ os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
260
+ if index_filepath:
261
+ os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
262
+
263
+ # remove any unnecessary nested folders
264
+ for filepath in os.listdir(extraction_folder):
265
+ if os.path.isdir(os.path.join(extraction_folder, filepath)):
266
+ shutil.rmtree(os.path.join(extraction_folder, filepath))
267
+
268
+
269
+ def download_online_model(url, dir_name, progress=gr.Progress()):
270
+ try:
271
+ progress(0, desc=f'[~] Downloading voice model with name {dir_name}...')
272
+ zip_name = url.split('/')[-1]
273
+ extraction_folder = os.path.join(rvc_models_dir, dir_name)
274
+ if os.path.exists(extraction_folder):
275
+ raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
276
+
277
+ if 'huggingface.co' in url:
278
+ urllib.request.urlretrieve(url, zip_name)
279
+
280
+ if 'pixeldrain.com' in url:
281
+ zip_name = dir_name + '.zip'
282
+ url = f'https://pixeldrain.com/api/file/{zip_name}'
283
+ urllib.request.urlretrieve(url, zip_name)
284
+
285
+ elif 'drive.google.com' in url:
286
+ # Extract the Google Drive file ID
287
+ zip_name = dir_name + '.zip'
288
+ file_id = url.split('/')[-2]
289
+ output = os.path.join('.', f'{dir_name}.zip') # Adjust the output path if needed
290
+ gdown.download(id=file_id, output=output, quiet=False)
291
+
292
+ progress(0.5, desc='[~] Extracting zip...')
293
+ extract_zip(extraction_folder, zip_name)
294
+ return f'[+] {dir_name} Model successfully downloaded!'
295
+
296
+ except Exception as e:
297
+ raise gr.Error(str(e))
298
+
299
+
300
+
301
  initial_md = """
302
  # RVC text-to-speech webui
303
 
 
392
  inputs=[tts_text, tts_voice],
393
  )
394
 
395
+ with gr.Tab('Download model'):
396
+
397
+ with gr.Accordion('From HuggingFace/Pixeldrain URL', open=True):
398
+ with gr.Row():
399
+ 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.')
400
+ model_name = gr.Text(label='Name your model', info='Give your new model a unique name from your other voice models.')
401
+
402
+ with gr.Row():
403
+ download_btn = gr.Button('Download', variant='primary', scale=19)
404
+ dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
405
+
406
+ download_btn.click(download_online_model, inputs=[model_zip_link, model_name], outputs=dl_output_message)
407
+
408
+ gr.Markdown('## Input Examples',)
409
+ gr.Examples(
410
+ [
411
+ ['https://huggingface.co/phant0m4r/LiSA/resolve/main/LiSA.zip', 'Lisa'],
412
+ ['https://huggingface.co/Hev832/rvc/resolve/main/Sonic.zip?download=true', 'Sonic'],
413
+ ['https://huggingface.co/jkhgf/SLWooly/resolve/main/Jax.zip', 'Jax']
414
+ ],
415
+ [model_zip_link, model_name],
416
+ [],
417
+ download_online_model,
418
+ )
419
+
420
+ with gr.Accordion('From Public Index', open=False):
421
+
422
+ gr.Markdown('## How to use')
423
+ gr.Markdown('- Click Initialize public models table')
424
+ gr.Markdown('- Filter models using tags or search bar')
425
+ gr.Markdown('- Select a row to autofill the download link and model name')
426
+ gr.Markdown('- Click Download')
427
+
428
+ with gr.Row():
429
+ pub_zip_link = gr.Text(label='Download link to model')
430
+ pub_model_name = gr.Text(label='Model name')
431
+
432
+ with gr.Row():
433
+ download_pub_btn = gr.Button('Download', variant='primary', scale=19)
434
+ pub_dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
435
+
436
+
437
+
438
+
439
 
440
  app.launch()