Spaces:
Runtime error
Runtime error
update gui and add yt video download
Browse files
app.py
CHANGED
@@ -17,6 +17,18 @@ os.environ["TEMP"] = tmp
|
|
17 |
warnings.filterwarnings("ignore")
|
18 |
torch.manual_seed(114514)
|
19 |
from i18n import I18nAuto
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
from utils import load_audio, CSVutil
|
22 |
|
@@ -25,11 +37,19 @@ Quefrency = 1.0
|
|
25 |
Timbre = 1.0
|
26 |
|
27 |
f0_method = 'rmvpe'
|
|
|
28 |
crepe_hop_length = 120
|
29 |
filter_radius = 3
|
30 |
resample_sr = 1
|
31 |
rms_mix_rate = 0.21
|
32 |
protect = 0.33
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# essa parte excluir dps
|
35 |
if not os.path.isdir('csvdb/'):
|
@@ -72,7 +92,34 @@ def download_models():
|
|
72 |
|
73 |
download_models()
|
74 |
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
i18n = I18nAuto()
|
78 |
ngpu = torch.cuda.device_count()
|
@@ -121,21 +168,8 @@ else:
|
|
121 |
gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
|
122 |
default_batch_size = 1
|
123 |
gpus = "-".join([i[0] for i in gpu_infos])
|
124 |
-
from lib.infer_pack.models import (
|
125 |
-
SynthesizerTrnMs256NSFsid,
|
126 |
-
SynthesizerTrnMs256NSFsid_nono,
|
127 |
-
SynthesizerTrnMs768NSFsid,
|
128 |
-
SynthesizerTrnMs768NSFsid_nono,
|
129 |
-
)
|
130 |
-
import soundfile as sf
|
131 |
-
from fairseq import checkpoint_utils
|
132 |
-
import gradio as gr
|
133 |
-
import logging
|
134 |
-
from vc_infer_pipeline import VC
|
135 |
-
from config import Config
|
136 |
|
137 |
config = Config()
|
138 |
-
# from trainset_preprocess_pipeline import PreProcess
|
139 |
logging.getLogger("numba").setLevel(logging.WARNING)
|
140 |
|
141 |
hubert_model = None
|
@@ -154,7 +188,6 @@ def load_hubert():
|
|
154 |
hubert_model = hubert_model.float()
|
155 |
hubert_model.eval()
|
156 |
|
157 |
-
|
158 |
weight_root = "weights"
|
159 |
index_root = "logs"
|
160 |
names = []
|
@@ -168,17 +201,11 @@ for root, dirs, files in os.walk(index_root, topdown=False):
|
|
168 |
index_paths.append("%s/%s" % (root, name))
|
169 |
|
170 |
def vc_single(
|
171 |
-
sid,
|
172 |
input_audio_path,
|
173 |
-
|
174 |
-
f0_file,
|
175 |
-
file_index,
|
176 |
-
index_rate,
|
177 |
-
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
|
178 |
global tgt_sr, net_g, vc, hubert_model, version
|
179 |
if input_audio_path is None:
|
180 |
return "You need to upload an audio", None
|
181 |
-
f0_up_key = int(f0_up_key)
|
182 |
try:
|
183 |
audio = load_audio(input_audio_path, 16000, DoFormant, Quefrency, Timbre)
|
184 |
audio_max = np.abs(audio).max() / 0.95
|
@@ -188,6 +215,7 @@ def vc_single(
|
|
188 |
if hubert_model == None:
|
189 |
load_hubert()
|
190 |
if_f0 = cpt.get("f0", 1)
|
|
|
191 |
file_index = (
|
192 |
(
|
193 |
file_index.strip(" ")
|
@@ -197,14 +225,11 @@ def vc_single(
|
|
197 |
.strip(" ")
|
198 |
.replace("trained", "added")
|
199 |
)
|
200 |
-
)
|
201 |
-
# file_big_npy = (
|
202 |
-
# file_big_npy.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
203 |
-
# )
|
204 |
audio_opt = vc.pipeline(
|
205 |
hubert_model,
|
206 |
net_g,
|
207 |
-
|
208 |
audio,
|
209 |
input_audio_path,
|
210 |
times,
|
@@ -220,7 +245,7 @@ def vc_single(
|
|
220 |
version,
|
221 |
protect,
|
222 |
crepe_hop_length,
|
223 |
-
f0_file=
|
224 |
)
|
225 |
if resample_sr >= 16000 and tgt_sr != resample_sr:
|
226 |
tgt_sr = resample_sr
|
@@ -298,7 +323,6 @@ def get_vc(sid):
|
|
298 |
net_g = net_g.float()
|
299 |
vc = VC(tgt_sr, config)
|
300 |
n_spk = cpt["config"][-3]
|
301 |
-
return {"visible": False, "maximum": n_spk, "__type__": "update"}
|
302 |
|
303 |
def change_choices():
|
304 |
names = []
|
@@ -312,125 +336,8 @@ def change_choices():
|
|
312 |
index_paths.append("%s/%s" % (root, name))
|
313 |
return {"choices": sorted(names), "__type__": "update"}
|
314 |
|
315 |
-
def
|
316 |
-
return
|
317 |
-
|
318 |
-
sr_dict = {
|
319 |
-
"32k": 32000,
|
320 |
-
"40k": 40000,
|
321 |
-
"48k": 48000,
|
322 |
-
}
|
323 |
-
|
324 |
-
def if_done(done, p):
|
325 |
-
while 1:
|
326 |
-
if p.poll() == None:
|
327 |
-
sleep(0.5)
|
328 |
-
else:
|
329 |
-
break
|
330 |
-
done[0] = True
|
331 |
-
|
332 |
-
def if_done_multi(done, ps):
|
333 |
-
while 1:
|
334 |
-
# poll==None代表进程未结束
|
335 |
-
# 只要有一个进程未结束都不停
|
336 |
-
flag = 1
|
337 |
-
for p in ps:
|
338 |
-
if p.poll() == None:
|
339 |
-
flag = 0
|
340 |
-
sleep(0.5)
|
341 |
-
break
|
342 |
-
if flag == 1:
|
343 |
-
break
|
344 |
-
done[0] = True
|
345 |
-
|
346 |
-
def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, echl):
|
347 |
-
gpus = gpus.split("-")
|
348 |
-
os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
|
349 |
-
f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
|
350 |
-
f.close()
|
351 |
-
if if_f0:
|
352 |
-
cmd = config.python_cmd + " extract_f0_print.py %s/logs/%s %s %s %s" % (
|
353 |
-
now_dir,
|
354 |
-
exp_dir,
|
355 |
-
n_p,
|
356 |
-
f0method,
|
357 |
-
echl,
|
358 |
-
)
|
359 |
-
print(cmd)
|
360 |
-
p = Popen(cmd, shell=True, cwd=now_dir) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
|
361 |
-
###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
|
362 |
-
done = [False]
|
363 |
-
threading.Thread(
|
364 |
-
target=if_done,
|
365 |
-
args=(
|
366 |
-
done,
|
367 |
-
p,
|
368 |
-
),
|
369 |
-
).start()
|
370 |
-
while 1:
|
371 |
-
with open(
|
372 |
-
"%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
|
373 |
-
) as f:
|
374 |
-
yield (f.read())
|
375 |
-
sleep(1)
|
376 |
-
if done[0] == True:
|
377 |
-
break
|
378 |
-
with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
|
379 |
-
log = f.read()
|
380 |
-
print(log)
|
381 |
-
yield log
|
382 |
-
####对不同part分别开多进程
|
383 |
-
"""
|
384 |
-
n_part=int(sys.argv[1])
|
385 |
-
i_part=int(sys.argv[2])
|
386 |
-
i_gpu=sys.argv[3]
|
387 |
-
exp_dir=sys.argv[4]
|
388 |
-
os.environ["CUDA_VISIBLE_DEVICES"]=str(i_gpu)
|
389 |
-
"""
|
390 |
-
leng = len(gpus)
|
391 |
-
ps = []
|
392 |
-
for idx, n_g in enumerate(gpus):
|
393 |
-
cmd = (
|
394 |
-
config.python_cmd
|
395 |
-
+ " extract_feature_print.py %s %s %s %s %s/logs/%s %s"
|
396 |
-
% (
|
397 |
-
config.device,
|
398 |
-
leng,
|
399 |
-
idx,
|
400 |
-
n_g,
|
401 |
-
now_dir,
|
402 |
-
exp_dir,
|
403 |
-
version19,
|
404 |
-
)
|
405 |
-
)
|
406 |
-
print(cmd)
|
407 |
-
p = Popen(
|
408 |
-
cmd, shell=True, cwd=now_dir
|
409 |
-
) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
|
410 |
-
ps.append(p)
|
411 |
-
###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
|
412 |
-
done = [False]
|
413 |
-
threading.Thread(
|
414 |
-
target=if_done_multi,
|
415 |
-
args=(
|
416 |
-
done,
|
417 |
-
ps,
|
418 |
-
),
|
419 |
-
).start()
|
420 |
-
while 1:
|
421 |
-
with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
|
422 |
-
yield (f.read())
|
423 |
-
sleep(1)
|
424 |
-
if done[0] == True:
|
425 |
-
break
|
426 |
-
with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
|
427 |
-
log = f.read()
|
428 |
-
print(log)
|
429 |
-
yield log
|
430 |
-
|
431 |
-
def whethercrepeornah(radio):
|
432 |
-
mango = True if radio == 'mangio-crepe' or radio == 'mangio-crepe-tiny' else False
|
433 |
-
return ({"visible": mango, "__type__": "update"})
|
434 |
|
435 |
#region RVC WebUI App
|
436 |
def change_choices2():
|
@@ -456,18 +363,8 @@ def get_index():
|
|
456 |
return ''
|
457 |
else:
|
458 |
return ''
|
459 |
-
|
460 |
-
|
461 |
-
indexes_list=[]
|
462 |
-
for dirpath, dirnames, filenames in os.walk("./logs/"):
|
463 |
-
for filename in filenames:
|
464 |
-
if filename.endswith(".index"):
|
465 |
-
indexes_list.append(os.path.join(dirpath,filename))
|
466 |
-
if len(indexes_list) > 0:
|
467 |
-
return indexes_list
|
468 |
-
else:
|
469 |
-
return ''
|
470 |
-
|
471 |
def save_to_wav(record_button):
|
472 |
if record_button is None:
|
473 |
pass
|
@@ -483,6 +380,19 @@ def save_to_wav2(dropbox):
|
|
483 |
shutil.move(file_path,'./audios')
|
484 |
return os.path.join('./audios',os.path.basename(file_path))
|
485 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
def match_index(sid0):
|
487 |
folder=sid0.split(".")[0]
|
488 |
parent_dir="./logs/"+folder
|
@@ -542,103 +452,79 @@ def download_from_url(url, model):
|
|
542 |
except:
|
543 |
return "There's been an error."
|
544 |
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
|
|
|
|
|
|
549 |
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
)
|
565 |
-
#clean_button.click(fn=clean, inputs=[], outputs=[sid0])
|
566 |
-
sid0.change(
|
567 |
-
fn=get_vc,
|
568 |
-
inputs=[sid0],
|
569 |
-
outputs=[spk_item],
|
570 |
-
)
|
571 |
-
but0 = gr.Button("Convert", variant="primary")
|
572 |
-
with gr.Row():
|
573 |
with gr.Column():
|
574 |
with gr.Row():
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
choices=audio_files
|
583 |
-
)
|
584 |
-
dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])
|
585 |
-
dropbox.upload(fn=change_choices2, inputs=[], outputs=[input_audio0])
|
586 |
-
refresh_button2 = gr.Button("Refresh", variant="primary", size='sm')
|
587 |
-
refresh_button2.click(fn=change_choices2, inputs=[], outputs=[input_audio0])
|
588 |
-
record_button.change(fn=save_to_wav, inputs=[record_button], outputs=[input_audio0])
|
589 |
-
record_button.change(fn=change_choices2, inputs=[], outputs=[input_audio0])
|
590 |
-
with gr.Column():
|
591 |
-
#antigo index
|
592 |
-
file_index1 = gr.Dropdown(
|
593 |
-
label="3. Path to your added.index file (if it didn't automatically find it.)",
|
594 |
-
choices=get_indexes(),
|
595 |
-
value=get_index(),
|
596 |
-
interactive=True,
|
597 |
-
visible=False,
|
598 |
)
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
|
|
|
|
|
|
|
|
608 |
)
|
609 |
-
|
610 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
label="Output Audio (Click on the Three Dots in the Right Corner to Download)",
|
612 |
type='filepath',
|
613 |
interactive=False,
|
614 |
)
|
615 |
-
|
616 |
-
|
617 |
-
with gr.Row():
|
618 |
-
f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
|
619 |
-
|
620 |
-
but0.click(
|
621 |
-
vc_single,
|
622 |
-
[
|
623 |
-
spk_item,
|
624 |
-
input_audio0,
|
625 |
-
vc_transform0,
|
626 |
-
f0_file,
|
627 |
-
file_index1,
|
628 |
-
index_rate1,
|
629 |
-
],
|
630 |
-
[vc_output1, vc_output2],
|
631 |
-
)
|
632 |
|
633 |
-
with gr.TabItem("
|
634 |
-
with gr.
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
status_bar=gr.Textbox(label="")
|
641 |
-
download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
|
642 |
with gr.Row():
|
643 |
gr.Markdown(
|
644 |
"""
|
@@ -648,6 +534,9 @@ with gr.Blocks(theme=gr.themes.Base(), title='Mangio-RVC-Web 💻') as app:
|
|
648 |
Made with ❤️ by [Alice Oliveira](https://github.com/aliceoq) | Hosted with ❤️ by [Mateus Elias](https://github.com/mateuseap)
|
649 |
"""
|
650 |
)
|
651 |
-
|
652 |
-
|
|
|
|
|
|
|
653 |
#endregion
|
|
|
17 |
warnings.filterwarnings("ignore")
|
18 |
torch.manual_seed(114514)
|
19 |
from i18n import I18nAuto
|
20 |
+
from lib.infer_pack.models import (
|
21 |
+
SynthesizerTrnMs256NSFsid,
|
22 |
+
SynthesizerTrnMs256NSFsid_nono,
|
23 |
+
SynthesizerTrnMs768NSFsid,
|
24 |
+
SynthesizerTrnMs768NSFsid_nono,
|
25 |
+
)
|
26 |
+
import soundfile as sf
|
27 |
+
from fairseq import checkpoint_utils
|
28 |
+
import gradio as gr
|
29 |
+
import logging
|
30 |
+
from vc_infer_pipeline import VC
|
31 |
+
from config import Config
|
32 |
|
33 |
from utils import load_audio, CSVutil
|
34 |
|
|
|
37 |
Timbre = 1.0
|
38 |
|
39 |
f0_method = 'rmvpe'
|
40 |
+
f0_up_key = 0
|
41 |
crepe_hop_length = 120
|
42 |
filter_radius = 3
|
43 |
resample_sr = 1
|
44 |
rms_mix_rate = 0.21
|
45 |
protect = 0.33
|
46 |
+
index_rate = 0.66
|
47 |
+
|
48 |
+
sr_dict = {
|
49 |
+
"32k": 32000,
|
50 |
+
"40k": 40000,
|
51 |
+
"48k": 48000,
|
52 |
+
}
|
53 |
|
54 |
# essa parte excluir dps
|
55 |
if not os.path.isdir('csvdb/'):
|
|
|
92 |
|
93 |
download_models()
|
94 |
|
95 |
+
# Check if we're in a Google Colab environment
|
96 |
+
if os.path.exists('/content/'):
|
97 |
+
print("\n-------------------------------\nRVC v2 Easy GUI (Colab Edition)\n-------------------------------\n")
|
98 |
+
|
99 |
+
print("-------------------------------")
|
100 |
+
# Check if the file exists at the specified path
|
101 |
+
if os.path.exists('/content/Mangio-RVC-Fork/hubert_base.pt'):
|
102 |
+
# If the file exists, print a statement saying so
|
103 |
+
print("File /content/Mangio-RVC-Fork/hubert_base.pt already exists. No need to download.")
|
104 |
+
else:
|
105 |
+
# If the file doesn't exist, print a statement saying it's downloading
|
106 |
+
print("File /content/Mangio-RVC-Fork/hubert_base.pt does not exist. Starting download.")
|
107 |
+
|
108 |
+
# Make a request to the URL
|
109 |
+
response = requests.get('https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt')
|
110 |
+
|
111 |
+
# Ensure the request was successful
|
112 |
+
if response.status_code == 200:
|
113 |
+
# If the response was a success, save the content to the specified file path
|
114 |
+
with open('/content/Mangio-RVC-Fork/hubert_base.pt', 'wb') as f:
|
115 |
+
f.write(response.content)
|
116 |
+
print("Download complete. File saved to /content/Mangio-RVC-Fork/hubert_base.pt.")
|
117 |
+
else:
|
118 |
+
# If the response was a failure, print an error message
|
119 |
+
print("Failed to download file. Status code: " + str(response.status_code) + ".")
|
120 |
+
else:
|
121 |
+
print("\n-------------------------------\nRVC v2 Easy GUI (Local Edition)\n-------------------------------\n")
|
122 |
+
print("-------------------------------\nNot running on Google Colab, skipping download.")
|
123 |
|
124 |
i18n = I18nAuto()
|
125 |
ngpu = torch.cuda.device_count()
|
|
|
168 |
gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
|
169 |
default_batch_size = 1
|
170 |
gpus = "-".join([i[0] for i in gpu_infos])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
config = Config()
|
|
|
173 |
logging.getLogger("numba").setLevel(logging.WARNING)
|
174 |
|
175 |
hubert_model = None
|
|
|
188 |
hubert_model = hubert_model.float()
|
189 |
hubert_model.eval()
|
190 |
|
|
|
191 |
weight_root = "weights"
|
192 |
index_root = "logs"
|
193 |
names = []
|
|
|
201 |
index_paths.append("%s/%s" % (root, name))
|
202 |
|
203 |
def vc_single(
|
|
|
204 |
input_audio_path,
|
205 |
+
):
|
|
|
|
|
|
|
|
|
206 |
global tgt_sr, net_g, vc, hubert_model, version
|
207 |
if input_audio_path is None:
|
208 |
return "You need to upload an audio", None
|
|
|
209 |
try:
|
210 |
audio = load_audio(input_audio_path, 16000, DoFormant, Quefrency, Timbre)
|
211 |
audio_max = np.abs(audio).max() / 0.95
|
|
|
215 |
if hubert_model == None:
|
216 |
load_hubert()
|
217 |
if_f0 = cpt.get("f0", 1)
|
218 |
+
file_index = get_index()
|
219 |
file_index = (
|
220 |
(
|
221 |
file_index.strip(" ")
|
|
|
225 |
.strip(" ")
|
226 |
.replace("trained", "added")
|
227 |
)
|
228 |
+
)
|
|
|
|
|
|
|
229 |
audio_opt = vc.pipeline(
|
230 |
hubert_model,
|
231 |
net_g,
|
232 |
+
0,
|
233 |
audio,
|
234 |
input_audio_path,
|
235 |
times,
|
|
|
245 |
version,
|
246 |
protect,
|
247 |
crepe_hop_length,
|
248 |
+
f0_file=None,
|
249 |
)
|
250 |
if resample_sr >= 16000 and tgt_sr != resample_sr:
|
251 |
tgt_sr = resample_sr
|
|
|
323 |
net_g = net_g.float()
|
324 |
vc = VC(tgt_sr, config)
|
325 |
n_spk = cpt["config"][-3]
|
|
|
326 |
|
327 |
def change_choices():
|
328 |
names = []
|
|
|
336 |
index_paths.append("%s/%s" % (root, name))
|
337 |
return {"choices": sorted(names), "__type__": "update"}
|
338 |
|
339 |
+
def update_dropdowns():
|
340 |
+
return [change_choices(), change_choices2()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
#region RVC WebUI App
|
343 |
def change_choices2():
|
|
|
363 |
return ''
|
364 |
else:
|
365 |
return ''
|
366 |
+
return ''
|
367 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
def save_to_wav(record_button):
|
369 |
if record_button is None:
|
370 |
pass
|
|
|
380 |
shutil.move(file_path,'./audios')
|
381 |
return os.path.join('./audios',os.path.basename(file_path))
|
382 |
|
383 |
+
|
384 |
+
def match_index(sid0):
|
385 |
+
folder=sid0.split(".")[0]
|
386 |
+
parent_dir="./logs/"+folder
|
387 |
+
if os.path.exists(parent_dir):
|
388 |
+
for filename in os.listdir(parent_dir):
|
389 |
+
if filename.endswith(".index"):
|
390 |
+
index_path=os.path.join(parent_dir,filename)
|
391 |
+
return index_path
|
392 |
+
else:
|
393 |
+
return ''
|
394 |
+
|
395 |
+
|
396 |
def match_index(sid0):
|
397 |
folder=sid0.split(".")[0]
|
398 |
parent_dir="./logs/"+folder
|
|
|
452 |
except:
|
453 |
return "There's been an error."
|
454 |
|
455 |
+
def download_from_youtube(url):
|
456 |
+
if url == '':
|
457 |
+
pass
|
458 |
+
filename = subprocess.getoutput(f'yt-dlp --print filename {url} --format m4a -o "./audios/%(title)s.%(ext)s"')
|
459 |
+
subprocess.getoutput(f'yt-dlp {url} --format m4a -o "./audios/%(title)s.%(ext)s"')
|
460 |
+
if os.path.exists(filename[1:]):
|
461 |
+
return filename
|
462 |
|
463 |
+
css = """
|
464 |
+
.padding {padding-left: 15px; padding-top: 5px;}
|
465 |
+
"""
|
466 |
+
|
467 |
+
with gr.Blocks(theme = gr.themes.Base(), title="Vocais da Loirinha 👱🏻♀️", css=css) as app:
|
468 |
+
gr.HTML("<h1>Vocais da Loirinha 👱🏻♀️</h1>")
|
469 |
+
|
470 |
+
gr.HTML("<h2>Como usar?</h2>")
|
471 |
+
gr.Markdown("""Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus et volutpat eros. Nunc id magna vel ligula blandit ullamcorper. Proin commodo tincidunt gravida. Morbi posuere, lorem eu ornare auctor, dolor est volutpat eros, sed aliquet justo mi eu ligula. Maecenas convallis risus metus, at convallis ex gravida in. Suspendisse varius libero nec tellus placerat vulputate. Quisque ornare enim sed tristique ultrices.""")
|
472 |
+
|
473 |
+
gr.HTML("<h2>Comece aqui!</h2>")
|
474 |
+
with gr.Tabs():
|
475 |
+
with gr.TabItem("Inferência"):
|
476 |
+
with gr.Row().style(equal_height=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
with gr.Column():
|
478 |
with gr.Row():
|
479 |
+
model_dropdown = gr.Dropdown(label="1. Escolha a voz:", choices=sorted(names), value=check_for_name())
|
480 |
+
if check_for_name() != '':
|
481 |
+
get_vc(sorted(names)[0])
|
482 |
+
model_dropdown.change(
|
483 |
+
fn=get_vc,
|
484 |
+
inputs=[model_dropdown],
|
485 |
+
outputs=[],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
)
|
487 |
+
gr.HTML("<p>2. Adicione um arquivo de áudio</p>", elem_classes="padding")
|
488 |
+
yt_link_textbox = gr.Textbox(label="Insira um link para uma música no Youtube:")
|
489 |
+
download_yt_button = gr.Button("Baixar áudio do vídeo")
|
490 |
+
dropbox = gr.File(label="OU selecione um arquivo:")
|
491 |
+
record_button = gr.Audio(source="microphone", label="OR grave o áudio:", type="filepath")
|
492 |
+
|
493 |
+
with gr.Column():
|
494 |
+
with gr.Row():
|
495 |
+
audio_dropdown = gr.Dropdown(
|
496 |
+
label="3. Escolha o áudio",
|
497 |
+
value="",
|
498 |
+
choices=audio_files,
|
499 |
+
scale=1
|
500 |
)
|
501 |
+
refresh_button = gr.Button("Atualizar listas de vozes e áudios", variant="primary", scale=0)
|
502 |
+
# Events
|
503 |
+
download_yt_button.click(fn=download_from_youtube, inputs=[yt_link_textbox], outputs=[audio_dropdown])
|
504 |
+
dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[audio_dropdown])
|
505 |
+
dropbox.upload(fn=change_choices2, inputs=[], outputs=[audio_dropdown])
|
506 |
+
record_button.change(fn=save_to_wav, inputs=[record_button], outputs=[audio_dropdown])
|
507 |
+
record_button.change(fn=change_choices2, inputs=[], outputs=[audio_dropdown])
|
508 |
+
refresh_button.click(fn=update_dropdowns, inputs=[], outputs=[model_dropdown, audio_dropdown])
|
509 |
+
selected_audio = gr.Audio(label="Áudio selecionado", interactive=False)
|
510 |
+
separate_checkbox = gr.Checkbox(label="Separar vocais e instrumental",
|
511 |
+
info="Se os vocais não estiverem isolados no áudio selecionado, ative esta opção. Os vocais serão extraídos durante a conversão e depois reintegrados ao áudio final com os instrumentais.")
|
512 |
+
convert_button = gr.Button("Convert", variant="primary")
|
513 |
+
output_audio = gr.Audio(
|
514 |
label="Output Audio (Click on the Three Dots in the Right Corner to Download)",
|
515 |
type='filepath',
|
516 |
interactive=False,
|
517 |
)
|
518 |
+
output_audio_textbox = gr.Textbox(label="Resultado", interactive=False, placeholder="Nenhum áudio gerado.")
|
519 |
+
convert_button.click(vc_single, [audio_dropdown], [output_audio_textbox, output_audio])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
|
521 |
+
with gr.TabItem("Adicione uma voz"):
|
522 |
+
with gr.Column():
|
523 |
+
model_link_textbox = gr.Textbox(label="1. Insira o link para o modelo:", info="A URL inserida deve ser o link para o download de um arquivo zip que contém o arquivo .pth. Pode ser um link do Google Drive, Mega ou Hugging Face.")
|
524 |
+
model_name_textbox = gr.Textbox(label="2. Escolha um nome para identificar o modelo:", info="Esse nome deve ser diferente do nome dos modelos (vozes) já existentes!")
|
525 |
+
download_button = gr.Button("Baixar modelo")
|
526 |
+
output_download_textbox = gr.Textbox(label="Resultado", interactive=False, placeholder="Nenhum modelo baixado.")
|
527 |
+
download_button.click(fn=download_from_url, inputs=[model_link_textbox, model_name_textbox], outputs=[output_download_textbox])
|
|
|
|
|
528 |
with gr.Row():
|
529 |
gr.Markdown(
|
530 |
"""
|
|
|
534 |
Made with ❤️ by [Alice Oliveira](https://github.com/aliceoq) | Hosted with ❤️ by [Mateus Elias](https://github.com/mateuseap)
|
535 |
"""
|
536 |
)
|
537 |
+
|
538 |
+
if config.iscolab or config.paperspace: # Share gradio link for colab and paperspace (FORK FEATURE)
|
539 |
+
app.queue(concurrency_count=511, max_size=1022).launch(share=True, quiet=True)
|
540 |
+
else:
|
541 |
+
app.queue(concurrency_count=511, max_size=1022).launch(share=False, quiet=True)
|
542 |
#endregion
|