Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,20 @@ from lib.infer import infer_audio
|
|
| 13 |
import edge_tts
|
| 14 |
import tempfile
|
| 15 |
import anyio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
language_dict = {
|
|
@@ -363,6 +377,60 @@ async def text_to_speech_edge(text, language_code):
|
|
| 363 |
|
| 364 |
|
| 365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
# Gradio Blocks Interface with Tabs
|
| 367 |
with gr.Blocks(title="Hex RVC") as app:
|
| 368 |
gr.Markdown("# Hex RVC")
|
|
@@ -419,6 +487,11 @@ with gr.Blocks(title="Hex RVC") as app:
|
|
| 419 |
outputs=output_audio
|
| 420 |
)
|
| 421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
with gr.Tab("Audio Separation"):
|
| 423 |
with gr.Row():
|
| 424 |
input_audio = gr.Audio(source="upload", type="filepath", label="Upload Audio File")
|
|
|
|
| 13 |
import edge_tts
|
| 14 |
import tempfile
|
| 15 |
import anyio
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
import os
|
| 18 |
+
import zipfile
|
| 19 |
+
import shutil
|
| 20 |
+
import urllib.request
|
| 21 |
+
import gdown
|
| 22 |
+
import subprocess
|
| 23 |
+
|
| 24 |
+
main_dir = Path().resolve()
|
| 25 |
+
print(main_dir)
|
| 26 |
+
|
| 27 |
+
os.chdir(main_dir)
|
| 28 |
+
models_dir = "models"
|
| 29 |
+
|
| 30 |
|
| 31 |
|
| 32 |
language_dict = {
|
|
|
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
+
|
| 381 |
+
def extract_zip(extraction_folder, zip_name):
|
| 382 |
+
os.makedirs(extraction_folder)
|
| 383 |
+
with zipfile.ZipFile(zip_name, 'r') as zip_ref:
|
| 384 |
+
zip_ref.extractall(extraction_folder)
|
| 385 |
+
os.remove(zip_name)
|
| 386 |
+
|
| 387 |
+
index_filepath, model_filepath = None, None
|
| 388 |
+
for root, dirs, files in os.walk(extraction_folder):
|
| 389 |
+
for name in files:
|
| 390 |
+
if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
|
| 391 |
+
index_filepath = os.path.join(root, name)
|
| 392 |
+
|
| 393 |
+
if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
|
| 394 |
+
model_filepath = os.path.join(root, name)
|
| 395 |
+
|
| 396 |
+
if not model_filepath:
|
| 397 |
+
raise Exception(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
|
| 398 |
+
|
| 399 |
+
# move model and index file to extraction folder
|
| 400 |
+
os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
|
| 401 |
+
if index_filepath:
|
| 402 |
+
os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
|
| 403 |
+
|
| 404 |
+
# remove any unnecessary nested folders
|
| 405 |
+
for filepath in os.listdir(extraction_folder):
|
| 406 |
+
if os.path.isdir(os.path.join(extraction_folder, filepath)):
|
| 407 |
+
shutil.rmtree(os.path.join(extraction_folder, filepath))
|
| 408 |
+
|
| 409 |
+
def download_online_model(url, dir_name):
|
| 410 |
+
try:
|
| 411 |
+
print(f'[~] Downloading voice model with name {dir_name}...')
|
| 412 |
+
zip_name = url.split('/')[-1]
|
| 413 |
+
extraction_folder = os.path.join(models_dir, dir_name)
|
| 414 |
+
if os.path.exists(extraction_folder):
|
| 415 |
+
raise Exception(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
|
| 416 |
+
|
| 417 |
+
if 'pixeldrain.com' in url:
|
| 418 |
+
url = f'https://pixeldrain.com/api/file/{zip_name}'
|
| 419 |
+
if 'drive.google.com' in url:
|
| 420 |
+
zip_name = dir_name + ".zip"
|
| 421 |
+
gdown.download(url, output=zip_name, use_cookies=True, quiet=True, fuzzy=True)
|
| 422 |
+
else:
|
| 423 |
+
urllib.request.urlretrieve(url, zip_name)
|
| 424 |
+
|
| 425 |
+
print(f'[~] Extracting zip file...')
|
| 426 |
+
extract_zip(extraction_folder, zip_name)
|
| 427 |
+
print(f'[+] {dir_name} Model successfully downloaded!')
|
| 428 |
+
|
| 429 |
+
except Exception as e:
|
| 430 |
+
raise Exception(str(e))
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
|
| 434 |
# Gradio Blocks Interface with Tabs
|
| 435 |
with gr.Blocks(title="Hex RVC") as app:
|
| 436 |
gr.Markdown("# Hex RVC")
|
|
|
|
| 487 |
outputs=output_audio
|
| 488 |
)
|
| 489 |
|
| 490 |
+
with gr.Tqb("Download RVC Model"):
|
| 491 |
+
url = gr.Textbox(label="Your model URL")
|
| 492 |
+
dirname = gr.Textbox(label="Your Model name")
|
| 493 |
+
button_model = gr.Button("Download model")
|
| 494 |
+
button_model.click(fn=download_online_model, inputs=url, dirname, output=dirname)
|
| 495 |
with gr.Tab("Audio Separation"):
|
| 496 |
with gr.Row():
|
| 497 |
input_audio = gr.Audio(source="upload", type="filepath", label="Upload Audio File")
|