Hev832 commited on
Commit
3ee5544
·
verified ·
1 Parent(s): f708340

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -104
app.py CHANGED
@@ -242,64 +242,7 @@ def tts(
242
 
243
 
244
 
245
- def extract_zip(extraction_folder, zip_name):
246
- os.makedirs(extraction_folder)
247
- with zipfile.ZipFile(zip_name, 'r') as zip_ref:
248
- zip_ref.extractall(extraction_folder)
249
- os.remove(zip_name)
250
 
251
- index_filepath, model_filepath = None, None
252
- for root, dirs, files in os.walk(extraction_folder):
253
- for name in files:
254
- if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
255
- index_filepath = os.path.join(root, name)
256
-
257
- if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
258
- model_filepath = os.path.join(root, name)
259
-
260
- if not model_filepath:
261
- raise gr.Error(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
262
-
263
- # move model and index file to extraction folder
264
- os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
265
- if index_filepath:
266
- os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
267
-
268
- # remove any unnecessary nested folders
269
- for filepath in os.listdir(extraction_folder):
270
- if os.path.isdir(os.path.join(extraction_folder, filepath)):
271
- shutil.rmtree(os.path.join(extraction_folder, filepath))
272
-
273
-
274
- def download_online_model(url, dir_name, progress=gr.Progress()):
275
- try:
276
- progress(0, desc=f'[~] Downloading voice model with name {dir_name}...')
277
- zip_name = url.split('/')[-1]
278
- extraction_folder = os.path.join(rvc_models_dir, dir_name)
279
- if os.path.exists(extraction_folder):
280
- raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
281
-
282
- if 'huggingface.co' in url:
283
- urllib.request.urlretrieve(url, zip_name)
284
-
285
- if 'pixeldrain.com' in url:
286
- zip_name = dir_name + '.zip'
287
- url = f'https://pixeldrain.com/api/file/{zip_name}'
288
- urllib.request.urlretrieve(url, zip_name)
289
-
290
- elif 'drive.google.com' in url:
291
- # Extract the Google Drive file ID
292
- zip_name = dir_name + '.zip'
293
- file_id = url.split('/')[-2]
294
- output = os.path.join('.', f'{dir_name}.zip') # Adjust the output path if needed
295
- gdown.download(id=file_id, output=output, quiet=False)
296
-
297
- progress(0.5, desc='[~] Extracting zip...')
298
- extract_zip(extraction_folder, zip_name)
299
- return f'[+] {dir_name} Model successfully downloaded!'
300
-
301
- except Exception as e:
302
- raise gr.Error(str(e))
303
 
304
 
305
 
@@ -315,9 +258,16 @@ This is a text-to-speech webui of RVC models.
315
  Input text ➡[(edge-tts)](https://github.com/rany2/edge-tts)➡ Speech mp3 file ➡[(RVC)](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI)➡ Final output
316
  """
317
 
 
 
 
 
 
 
318
  app = gr.Blocks(theme="Hev832/emerald", title="RVC-TTS")
319
  with app:
320
  gr.Markdown(initial_md)
 
321
 
322
  with gr.Row():
323
  with gr.Column():
@@ -398,50 +348,4 @@ with app:
398
  inputs=[tts_text, tts_voice],
399
  )
400
 
401
- with gr.Row():
402
- with gr.Tab('Download model'):
403
-
404
- with gr.Accordion('From HuggingFace/Pixeldrain URL', open=True):
405
- with gr.Row():
406
- 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.')
407
- model_name = gr.Text(label='Name your model', info='Give your new model a unique name from your other voice models.')
408
-
409
- with gr.Row():
410
- download_btn = gr.Button('Download', variant='primary', scale=19)
411
- dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
412
-
413
- download_btn.click(download_online_model, inputs=[model_zip_link, model_name], outputs=dl_output_message)
414
-
415
- gr.Markdown('## Input Examples',)
416
- gr.Examples(
417
- [
418
- ['https://huggingface.co/phant0m4r/LiSA/resolve/main/LiSA.zip', 'Lisa'],
419
- ['https://huggingface.co/Hev832/rvc/resolve/main/Sonic.zip?download=true', 'Sonic'],
420
- ['https://huggingface.co/jkhgf/SLWooly/resolve/main/Jax.zip', 'Jax']
421
- ],
422
- [model_zip_link, model_name],
423
- [],
424
- download_online_model,
425
- )
426
-
427
- with gr.Accordion('From Public Index', open=False):
428
-
429
- gr.Markdown('## How to use')
430
- gr.Markdown('- Click Initialize public models table')
431
- gr.Markdown('- Filter models using tags or search bar')
432
- gr.Markdown('- Select a row to autofill the download link and model name')
433
- gr.Markdown('- Click Download')
434
-
435
- with gr.Row():
436
- pub_zip_link = gr.Text(label='Download link to model')
437
- pub_model_name = gr.Text(label='Model name')
438
-
439
- with gr.Row():
440
- download_pub_btn = gr.Button('Download', variant='primary', scale=19)
441
- pub_dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
442
-
443
-
444
-
445
-
446
-
447
- app.launch()
 
242
 
243
 
244
 
 
 
 
 
 
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
 
248
 
 
258
  Input text ➡[(edge-tts)](https://github.com/rany2/edge-tts)➡ Speech mp3 file ➡[(RVC)](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI)➡ Final output
259
  """
260
 
261
+ Another_md = """"
262
+
263
+ RVC TTS = [🌐 Github](https://github.com/Blane187/rvc-tts.git)
264
+
265
+ """
266
+
267
  app = gr.Blocks(theme="Hev832/emerald", title="RVC-TTS")
268
  with app:
269
  gr.Markdown(initial_md)
270
+ gr.Markdown(Another_md)
271
 
272
  with gr.Row():
273
  with gr.Column():
 
348
  inputs=[tts_text, tts_voice],
349
  )
350
 
351
+ app.launch()