Spaces:
Runtime error
Runtime error
File size: 6,589 Bytes
c8be32d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
"""
Main application for the Ultimate RVC project.
Each tab of the application is defined in a separate module
in the `frontend/tabs` directory.
Components that are accessed across multiple tabs are passed as arguments
to the render functions in the respective modules.
"""
import asyncio
import os
from argparse import ArgumentParser
import gradio as gr
from backend.generate_song_cover import get_named_song_dirs
from backend.manage_audio import delete_gradio_temp_dir, get_output_audio
from backend.manage_voice_models import get_current_models
from frontend.tabs.manage_audio import render as render_manage_audio_tab
from frontend.tabs.manage_models import render as render_manage_models_tab
from frontend.tabs.multi_step_generation import render as render_multi_step_tab
from frontend.tabs.one_click_generation import render as render_one_click_tab
from common import GRADIO_TEMP_DIR
def _init_app() -> tuple[gr.Dropdown, ...]:
"""
Initialize app by deleting any existing Gradio temp directory
and updating the choices of all dropdowns.
Returns
-------
tuple[gr.Dropdown, ...]
Updated dropdowns for selecting voice models, song directories,
and output audio files.
"""
delete_gradio_temp_dir()
updated_rvc_model_dropdowns = tuple(
gr.Dropdown(choices=get_current_models()) for _ in range(3)
)
updated_song_dir_dropdowns = tuple(
gr.Dropdown(choices=get_named_song_dirs()) for _ in range(10)
)
updated_output_audio_dropdown = (gr.Dropdown(choices=get_output_audio()),)
return (
updated_rvc_model_dropdowns
+ updated_song_dir_dropdowns
+ updated_output_audio_dropdown
)
os.environ["GRADIO_TEMP_DIR"] = GRADIO_TEMP_DIR
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
with gr.Blocks(title="Ultimate RVC") as app:
gr.Label("Ultimate RVC ❤️", show_label=False)
dummy_deletion_checkbox = gr.Checkbox(visible=False)
delete_confirmation = gr.State(False)
song_dir_dropdowns = [
gr.Dropdown(
label="Song directory",
info=(
"Directory where intermediate audio files are stored and loaded from"
" locally. When a new song is retrieved, its directory is chosen by"
" default."
),
render=False,
)
for _ in range(7)
]
cached_input_songs_dropdown_1click, cached_input_songs_dropdown_multi = [
gr.Dropdown(
label="Song input",
info="Select a song from the list of cached songs.",
visible=False,
render=False,
)
for _ in range(2)
]
intermediate_audio_to_delete = gr.Dropdown(
label="Songs with intermediate audio files",
multiselect=True,
info=(
"Select one or more songs to delete their asssociated intermediate audio"
" files."
),
render=False,
)
output_audio_to_delete = gr.Dropdown(
label="Output audio files",
multiselect=True,
info="Select one or more output audio files to delete.",
render=False,
)
rvc_model_1click, rvc_model_multi = [
gr.Dropdown(label="Voice model", render=False) for _ in range(2)
]
rvc_models_to_delete = gr.Dropdown(
label="Voice models", multiselect=True, render=False
)
generate_buttons = [
gr.Button(label, variant="primary", render=False, scale=scale)
for label, scale, in [
("Retrieve song", 1),
("Separate vocals/instrumentals", 1),
("Separate main/backup vocals", 1),
("De-reverb vocals", 1),
("Convert vocals", 1),
("Post-process vocals", 1),
("Pitch shift background", 1),
("Mix song cover", 1),
("Generate", 2),
]
]
# main tab
with gr.Tab("Generate song covers"):
render_one_click_tab(
generate_buttons,
song_dir_dropdowns,
cached_input_songs_dropdown_1click,
cached_input_songs_dropdown_multi,
rvc_model_1click,
intermediate_audio_to_delete,
output_audio_to_delete,
)
render_multi_step_tab(
generate_buttons,
song_dir_dropdowns,
cached_input_songs_dropdown_1click,
cached_input_songs_dropdown_multi,
rvc_model_multi,
intermediate_audio_to_delete,
output_audio_to_delete,
)
with gr.Tab("Manage models"):
render_manage_models_tab(
dummy_deletion_checkbox,
delete_confirmation,
rvc_models_to_delete,
rvc_model_1click,
rvc_model_multi,
)
with gr.Tab("Manage audio"):
render_manage_audio_tab(
dummy_deletion_checkbox,
delete_confirmation,
song_dir_dropdowns,
cached_input_songs_dropdown_1click,
cached_input_songs_dropdown_multi,
intermediate_audio_to_delete,
output_audio_to_delete,
)
app.load(
_init_app,
outputs=[
rvc_model_1click,
rvc_model_multi,
rvc_models_to_delete,
intermediate_audio_to_delete,
cached_input_songs_dropdown_1click,
cached_input_songs_dropdown_multi,
*song_dir_dropdowns,
output_audio_to_delete,
],
show_progress="hidden",
)
app.unload(delete_gradio_temp_dir)
if __name__ == "__main__":
parser = ArgumentParser(
description="Generate a song cover song in the song_output/id directory.",
add_help=True,
)
parser.add_argument(
"--share",
action="store_true",
dest="share_enabled",
default=False,
help="Enable sharing",
)
parser.add_argument(
"--listen",
action="store_true",
default=False,
help="Make the WebUI reachable from your local network.",
)
parser.add_argument(
"--listen-host", type=str, help="The hostname that the server will use."
)
parser.add_argument(
"--listen-port", type=int, help="The listening port that the server will use."
)
args = parser.parse_args()
app.queue()
app.launch(
share=args.share_enabled,
server_name=None if not args.listen else (args.listen_host or "0.0.0.0"),
server_port=args.listen_port,
)
|