Rename app.py to demo.py
Browse files- app.py → demo.py +126 -2
app.py → demo.py
RENAMED
|
@@ -1,12 +1,136 @@
|
|
| 1 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import shutil, glob
|
| 3 |
from easyfuncs import download_from_url, CachedModels
|
| 4 |
os.makedirs("dataset",exist_ok=True)
|
| 5 |
model_library = CachedModels()
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
with gr.Blocks(title="🔊",theme=gr.themes.Base(primary_hue="rose",neutral_hue="zinc")) as app:
|
| 8 |
with gr.Row():
|
| 9 |
-
gr.
|
| 10 |
with gr.Tabs():
|
| 11 |
with gr.TabItem("Inference"):
|
| 12 |
with gr.Row():
|
|
|
|
| 1 |
+
from i18n.i18n import I18nAuto
|
| 2 |
+
from configs.config import Config
|
| 3 |
+
from sklearn.cluster import MiniBatchKMeans
|
| 4 |
+
import torch, platform
|
| 5 |
+
import numpy as np
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import faiss
|
| 8 |
+
import fairseq
|
| 9 |
+
import pathlib
|
| 10 |
+
import json
|
| 11 |
+
from time import sleep
|
| 12 |
+
from subprocess import Popen
|
| 13 |
+
from random import shuffle
|
| 14 |
+
import warnings
|
| 15 |
+
import traceback
|
| 16 |
+
import threading
|
| 17 |
+
import shutil
|
| 18 |
+
import logging
|
| 19 |
+
import sys
|
| 20 |
+
from dotenv import load_dotenv
|
| 21 |
+
from infer.modules.vc.modules import VC
|
| 22 |
import shutil, glob
|
| 23 |
from easyfuncs import download_from_url, CachedModels
|
| 24 |
os.makedirs("dataset",exist_ok=True)
|
| 25 |
model_library = CachedModels()
|
| 26 |
|
| 27 |
+
|
| 28 |
+
logging.getLogger("numba").setLevel(logging.WARNING)
|
| 29 |
+
logging.getLogger("httpx").setLevel(logging.WARNING)
|
| 30 |
+
|
| 31 |
+
logger = logging.getLogger(__name__)
|
| 32 |
+
|
| 33 |
+
tmp = os.path.join(now_dir, "TEMP")
|
| 34 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 35 |
+
shutil.rmtree("%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True)
|
| 36 |
+
shutil.rmtree("%s/runtime/Lib/site-packages/uvr5_pack" % (now_dir), ignore_errors=True)
|
| 37 |
+
os.makedirs(tmp, exist_ok=True)
|
| 38 |
+
os.makedirs(os.path.join(now_dir, "logs"), exist_ok=True)
|
| 39 |
+
os.makedirs(os.path.join(now_dir, "assets/weights"), exist_ok=True)
|
| 40 |
+
os.environ["TEMP"] = tmp
|
| 41 |
+
warnings.filterwarnings("ignore")
|
| 42 |
+
torch.manual_seed(114514)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
config = Config()
|
| 46 |
+
vc = VC(config)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ToolButton(gr.Button, gr.components.FormComponent):
|
| 50 |
+
"""Small button with single emoji as text, fits inside gradio forms"""
|
| 51 |
+
|
| 52 |
+
def __init__(self, **kwargs):
|
| 53 |
+
super().__init__(variant="tool", **kwargs)
|
| 54 |
+
|
| 55 |
+
def get_block_name(self):
|
| 56 |
+
return "button"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
weight_root = os.getenv("weight_root")
|
| 60 |
+
index_root = os.getenv("index_root")
|
| 61 |
+
outside_index_root = os.getenv("outside_index_root")
|
| 62 |
+
|
| 63 |
+
names = []
|
| 64 |
+
for name in os.listdir(weight_root):
|
| 65 |
+
if name.endswith(".pth"):
|
| 66 |
+
names.append(name)
|
| 67 |
+
index_paths = []
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def lookup_indices(index_root):
|
| 72 |
+
global index_paths
|
| 73 |
+
for root, dirs, files in os.walk(index_root, topdown=False):
|
| 74 |
+
for name in files:
|
| 75 |
+
if name.endswith(".index") and "trained" not in name:
|
| 76 |
+
index_paths.append("%s/%s" % (root, name))
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
lookup_indices(index_root)
|
| 80 |
+
lookup_indices(outside_index_root)
|
| 81 |
+
uvr5_names = []
|
| 82 |
+
for name in os.listdir(weight_uvr5_root):
|
| 83 |
+
if name.endswith(".pth") or "onnx" in name:
|
| 84 |
+
uvr5_names.append(name.replace(".pth", ""))
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def change_choices():
|
| 88 |
+
names = []
|
| 89 |
+
for name in os.listdir(weight_root):
|
| 90 |
+
if name.endswith(".pth"):
|
| 91 |
+
names.append(name)
|
| 92 |
+
index_paths = []
|
| 93 |
+
for root, dirs, files in os.walk(index_root, topdown=False):
|
| 94 |
+
for name in files:
|
| 95 |
+
if name.endswith(".index") and "trained" not in name:
|
| 96 |
+
index_paths.append("%s/%s" % (root, name))
|
| 97 |
+
return {"choices": sorted(names), "__type__": "update"}, {
|
| 98 |
+
"choices": sorted(index_paths),
|
| 99 |
+
"__type__": "update",
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def clean():
|
| 104 |
+
return {"value": "", "__type__": "update"}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def if_done(done, p):
|
| 108 |
+
while 1:
|
| 109 |
+
if p.poll() is None:
|
| 110 |
+
sleep(0.5)
|
| 111 |
+
else:
|
| 112 |
+
break
|
| 113 |
+
done[0] = True
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def if_done_multi(done, ps):
|
| 117 |
+
while 1:
|
| 118 |
+
# poll==None代表进程未结束
|
| 119 |
+
# 只要有一个进程未结束都不停
|
| 120 |
+
flag = 1
|
| 121 |
+
for p in ps:
|
| 122 |
+
if p.poll() is None:
|
| 123 |
+
flag = 0
|
| 124 |
+
sleep(0.5)
|
| 125 |
+
break
|
| 126 |
+
if flag == 1:
|
| 127 |
+
break
|
| 128 |
+
done[0] = True
|
| 129 |
+
|
| 130 |
+
|
| 131 |
with gr.Blocks(title="🔊",theme=gr.themes.Base(primary_hue="rose",neutral_hue="zinc")) as app:
|
| 132 |
with gr.Row():
|
| 133 |
+
gr.Markdown("<center><h1> RVC V2 - EASY GUI")
|
| 134 |
with gr.Tabs():
|
| 135 |
with gr.TabItem("Inference"):
|
| 136 |
with gr.Row():
|