RVC-GUI / app.py
AnhP's picture
Update app.py
94231f9 verified
raw
history blame contribute delete
No virus
17.7 kB
import os
from cachedmodels import CachedModels
from function import download_from_url, tach_nhac, TTS, download_url, merge_audio
import subprocess
import shutil
model_library = CachedModels()
os.makedirs('logs', exist_ok=True)
os.makedirs('audios', exist_ok=True)
os.makedirs('assets/weights', exist_ok=True)
os.makedirs('assets/rmvpe', exist_ok=True)
os.makedirs('assets/hubert', exist_ok=True)
if not os.path.exists('assets/rmvpe/rmvpe.pt'): subprocess.run(["wget", "https://huggingface.co/AnhP/Colab_RVC_Project/resolve/main/rmvpe.pt", "-O", f'assets/rmvpe/rmvpe.pt'])
if not os.path.exists('assets/hubert/hubert_base.pt'): subprocess.run(["wget", "https://huggingface.co/AnhP/Colab_RVC_Project/resolve/main/hubert_base.pt", "-O", f'assets/hubert/hubert_base.pt'])
if not os.path.exists('configs'): shutil.unpack_archive(f'configs.zip', "configs", 'zip')
from original import *
import gradio as gr
with gr.Blocks(title="📱 RVC GUI", theme='NoCrypt/miku') as app:
with gr.Row():
gr.HTML("<h1>🎼 RVC GUI 🎼<h1>")
with gr.Row():
gr.Markdown("Lưu Ý: Tách Nhạc Tách Cực Kì Lâu Nếu Không Có GPU, Nếu Muồn Nhanh Hãy Sử Dụng Bản Google Colab")
with gr.Row():
gr.Markdown("Sử Dụng Thử Bản [GoogleColab](https://colab.research.google.com/drive/18Ed5HbwcX0di6aJymX0EaUNz-xXU5uUc?hl=vi#scrollTo=DZDKirCM0F9g)")
with gr.Tabs():
with gr.TabItem("Tách Nhạc"):
gr.HTML("<h1> Tách Nhạc <h1>")
with gr.Row():
url = gr.Textbox(label="Đường Dẫn Liên Kết Đến Âm Nhạc", value="", placeholder="https://www.youtube.com/...", scale=6)
download_button = gr.Button("Bấm Để Tải")
with gr.Row():
gr.Markdown("""Backup Vocal Khi Tách Ra Chắc Chắn Sẽ Bị Nhiễu, Mọi Người Chú Ý""")
with gr.Row():
with gr.Column():
overlap = gr.Radio(label="Overlap", choices=["0.25", "0.5", "0.75", "0.99"], value="0.25", interactive=True)
segmentsize = gr.Slider(label="Segment Size", minimum=32, maximum=4000, value=256, step=8, interactive=True)
with gr.Column():
format = gr.Radio(label="Định Dạng", choices=["mp3", "wav", "flac"], value="mp3", interactive=True)
Denoise = gr.Radio(label="Denoise", choices=[True, False], value=True, interactive=True)
tachnhac_button = gr.Button("Tách Nhạc", variant="primary")
with gr.Row():
audio_in = gr.File(label="Thả Âm Thanh Vào Đây", file_types=['audio'])
tachnhac_input = gr.Dropdown(value="", allow_custom_value=True, visible=False)
with gr.Row():
Inp = gr.Audio(label="Đầu Vào Âm Thanh")
with gr.Row():
gr.Markdown("""Các File Được Tách""")
with gr.Row():
Instru = gr.Audio(show_download_button = True, label="Instruments")
Original = gr.Audio(show_download_button = True, label="Original Vocals")
Backup = gr.Audio(show_download_button = True, label="Backup Vocals")
Main = gr.Audio(show_download_button = True, label="Main Vocals")
with gr.Row():
download_button.click(
fn=download_url,
inputs=[url],
outputs=[tachnhac_input, url],
api_name='download_audio'
)
tachnhac_input.change(
fn=lambda path: {"value":path,"__type__":"update"} if os.path.exists(path) else None,
inputs=[tachnhac_input],
outputs=[Inp],
api_name='input_change'
)
audio_in.upload(
fn=lambda audio_in:audio_in.name,
inputs=[audio_in],
outputs=[tachnhac_input],
api_name='audio_upload'
)
tachnhac_button.click(
tach_nhac,
[tachnhac_input, format, segmentsize, overlap, Denoise],
[Instru, Original, Backup, Main],
api_name='tach_nhac'
)
with gr.TabItem("Convert"):
gr.HTML("<h1> Convert Âm Thanh <h1>")
with gr.Row():
voice_model = gr.Dropdown(label="Model", choices=sorted(names), value=lambda:sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True, allow_custom_value=True)
refresh_button = gr.Button("Tải Lại", variant="primary")
vc_transform0 = gr.Slider(minimum=-20, maximum=20, step=1, label="Cao Độ(pitch)", value=0, interactive=True)
but0 = gr.Button(value="Convert", variant="primary")
with gr.Row():
with gr.Column():
with gr.Row():
dropbox = gr.File(label="Thả Âm Thanh Vào Đây", file_types=['audio'])
with gr.Row():
paths_for_files = lambda path:[os.path.abspath(os.path.join(path, f)) for f in os.listdir(path) if os.path.splitext(f)[1].lower() in ('.mp3', '.wav', '.flac', '.ogg')]
input_audio0 = gr.Dropdown(label="Đường Dẫn Âm Thanh", value=paths_for_files('audios')[0] if len(paths_for_files('audios')) > 0 else '', choices=paths_for_files('audios'), allow_custom_value=True)
with gr.Row():
audio_player = gr.Audio()
input_audio0.change(
fn=lambda path: {"value":path,"__type__":"update"} if os.path.exists(path) else None,
inputs=[input_audio0],
outputs=[audio_player],
api_name='input0_change'
)
dropbox.upload(
fn=lambda audio:audio.name,
inputs=[dropbox],
outputs=[input_audio0],
api_name='audi0_upload'
)
with gr.Column():
with gr.Accordion("Thay Đổi Index", open=False):
file_index2 = gr.Dropdown(label="Thay Đổi Index", choices=sorted(index_paths), interactive=True, value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else '', allow_custom_value=True)
index_rate1 = gr.Slider(minimum=0, maximum=1, label="Index Strength", step=0.1, value=0.5, interactive=True)
with gr.Accordion("Cài Đặt", open=False):
f0method0 = gr.Radio(label="Phương Pháp", choices=["pm", "harvest", "rmvpe"], value="pm", interactive=True)
filter_radius0 = gr.Slider(minimum=0, maximum=7, label="Giảm Hơi Thở(Chỉ Harvest)", value=3, step=1, interactive=True)
resample_sr0 = gr.Slider(minimum=0, maximum=48000, label="Lấy Mẫu Lại", value=0, step=1, interactive=True, visible=False)
rms_mix_rate0 = gr.Slider(minimum=0, maximum=1, label="Chuẩn Hóa Âm Lượng", value=0, interactive=True)
protect0 = gr.Slider(minimum=0, maximum=0.5, label="Bảo Vệ Hơi Thở (0 Là Bật, 0.5 Là Tắt)", value=0.33, step=0.01, interactive=True)
if voice_model != None: vc.get_vc(voice_model.value, protect0, protect0)
vc_output2 = gr.Audio(label="Đầu Ra Âm Thanh")
refresh_button.click(
fn=change_choices,
inputs=[],
outputs=[voice_model, file_index2],
api_name='change_choices'
)
refresh_button.click(
fn=lambda:{"choices":paths_for_files('audios'),"__type__":"update"},
inputs=[],
outputs = [input_audio0],
api_name='refesh_button'
)
refresh_button.click(
fn=lambda:{"value":paths_for_files('audios')[0],"__type__":"update"} if len(paths_for_files('audios')) > 0 else {"value":"","__type__":"update"},
inputs=[],
outputs = [input_audio0],
api_name='refresh_button_1'
)
with gr.Row():
file_index1 = gr.Textbox(visible=False)
spk_item = gr.Slider(value=0, visible=False)
f0_file = gr.File(visible=False)
with gr.Row():
vc_output1 = gr.Textbox(visible=False)
but0.click(
vc.vc_single,
[
spk_item,
input_audio0,
vc_transform0,
f0_file,
f0method0,
file_index1,
file_index2,
index_rate1,
filter_radius0,
resample_sr0,
rms_mix_rate0,
protect0,
],
[vc_output1, vc_output2],
api_name='convert_audio'
)
voice_model.change(
fn=vc.get_vc,
inputs=[voice_model, protect0, protect0],
outputs=[spk_item, protect0, protect0, file_index2, file_index2],
api_name='get_vc'
)
with gr.TabItem("Text To Speech"):
gr.HTML("<h1> Chuyển Đổi Văn Bản Thành Giọng Nói <h1>")
with gr.Row():
with gr.Column():
prompt = gr.Textbox(label="Prompt", value="",placeholder="Xin Chào Thế Giới", scale=10)
with gr.Row():
with gr.Column():
Voice = gr.Radio(label="Giọng", choices=["vi-VN-NamMinhNeural", "vi-VN-HoaiMyNeural"], value="vi-VN-NamMinhNeural", interactive=True)
speed = gr.Slider(minimum=-100, maximum=100, label="Tốc Độ Đọc", value=0, step=1, interactive=True)
tts_button = gr.Button("Text To Speech")
with gr.Row():
voice_model1 = gr.Dropdown(label="Model", choices=sorted(names), value=lambda:sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True, allow_custom_value=True)
refresh_button1 = gr.Button("Tải Lại", variant="primary")
vc_transform1 = gr.Slider(minimum=-20, maximum=20, step=1, label="Cao Độ(pitch)", value=0, interactive=True)
infer_butt = gr.Button(value="Convert", variant="primary")
with gr.Row():
input_audio1 = gr.Dropdown(value='', choices='', allow_custom_value=True, visible=False)
with gr.Column():
with gr.Row():
with gr.Column():
protect1 = gr.Slider(minimum=0, maximum=0.5, label="Bảo Vệ Hơi Thở (0 Là Bật, 0.5 Là Tắt)", value=0.33, step=0.01, interactive=True)
f0method1 = gr.Radio(label="Phương Pháp", choices=["pm", "harvest", "rmvpe"], value='pm', interactive=True)
with gr.Accordion("Thay Đổi Index", open=True):
file_index3 = gr.Dropdown(label="Thay Đổi Index", choices=sorted(index_paths), interactive=True, value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else '', allow_custom_value=True)
index_rate2 = gr.Slider(minimum=0, maximum=1, label="Index Strength", value=0.5, interactive=True)
with gr.Column():
audio_player = gr.Audio(label="Đầu Vào Âm Thanh")
vc_output4 = gr.Audio(label="Đầu Ra Âm Thanh")
tts_button.click(
fn=TTS,
inputs=[prompt, Voice, speed],
outputs=[input_audio1, audio_player, prompt],
api_name='text_to_speech'
)
filter_radius0 = gr.Slider(value=3, visible=False)
resample_sr0 = gr.Slider(value=0, visible=False)
rms_mix_rate0 = gr.Slider(value=0, visible=False)
refresh_button1.click(
fn=change_choices,
inputs=[],
outputs=[voice_model1, file_index3],
api_name='refresh_button_2'
)
with gr.Row():
if voice_model1 != None: vc.get_vc(voice_model1.value, protect1, protect1)
with gr.Row():
spk_item1 = gr.Slider(value=0, visible=False)
f0_file = gr.File(visible=False)
with gr.Row():
file_index4 = gr.Textbox(visible=False)
vc_output3 = gr.Textbox(visible=False)
infer_butt.click(
vc.vc_single,
[
spk_item1,
input_audio1,
vc_transform1,
f0_file,
f0method1,
file_index4,
file_index3,
index_rate2,
filter_radius0,
resample_sr0,
rms_mix_rate0,
protect1,
],
[vc_output3, vc_output4],
api_name='convert_tts'
)
voice_model1.change(
fn=vc.get_vc,
inputs=[voice_model1, protect1, protect1],
outputs=[spk_item1, protect1, protect1, file_index3, file_index3],
api_name='get_vc_1'
)
with gr.TabItem("Kết Hợp"):
gr.HTML("<h1> Kết Hợp Nhạc <h1>")
with gr.Row():
file1 = gr.File(label="Âm Thanh 1", file_types=['audio'])
file2 = gr.File(label="Âm Thanh 2", file_types=['audio'])
file3 = gr.File(label="Âm Thanh 3", file_types=['audio'])
file4 = gr.File(label="Âm Thanh 4", file_types=['audio'])
with gr.Row():
format = gr.Radio(label="Phương Pháp", choices=["wav", "mp3"], value="wav", interactive=True)
button = gr.Button("Kết Hợp", variant="primary")
with gr.Row():
output = gr.Audio(label="Đoạn Âm Thanh Đã Kết Hợp")
with gr.Row():
button.click(
fn=merge_audio,
inputs=[file1, file2, file3, file4, format],
outputs=[output],
api_name='merge_audio'
)
with gr.TabItem("Tải Xuống Model"):
gr.HTML("<h1> Tải Xuống Model <h1>")
with gr.Row():
url_input = gr.Textbox(label="Đường Dẫn Model", value="",placeholder="https://...", scale=6)
name_output = gr.Textbox(label="Tên Để Lưu", value="",placeholder="Tên Model",scale=2)
url_download = gr.Button(value="Tải Xuống Model",scale=2)
url_download.click(
fn=download_from_url,
inputs=[url_input,name_output],
outputs=[url_input],
api_name='download_model'
)
with gr.Row():
model_browser = gr.Dropdown(choices=list(model_library.models.keys()),label="Hoặc Tìm Từ Kho Model(Model Chưa Được Kiểm Chứng Chất Lượng)",scale=5,allow_custom_value=True)
download_from_browser = gr.Button(value="Nhận Model", scale=2, variant="primary")
download_from_browser.click(
fn=lambda model: download_from_url(model_library.models[model],model),
inputs=[model_browser],
outputs=[model_browser],
api_name='download_model_library'
)
with gr.TabItem("Credits"):
gr.HTML("<h1>Credits<h1>")
with gr.Row():
gr.Markdown("""
**Dựa Trên [RVC-Project](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI?tab=readme-ov-file) Của Tác Giả [RVC BOSS](https://github.com/RVC-Boss).**
**Spaces Được Làm Lại Bởi P.Anh, Nếu Có Vấn Đề Gì Về Bản Quyền Xin Hãy Liên Hệ Với Tôi Để Tìm Cách Xử Lý Qua Id Discord Này: 923385115629985823, Xin Cảm Ơn.**
""")
gr.Markdown("""
**Based on [RVC-Project](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI?tab=readme-ov-file) By Author [RVC BOSS](https://github.com/RVC-Boss).**
**The Spaces is Remade by P.Anh, If There Are Any Problems About Copyright, Please Contact Me To Find A Solution Through This Discord Id: 923385115629985823, Thank You.**
""")
app.queue().launch(share=True)