Skip to content

Commit

Permalink
cleaning the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
blaise-tk committed Feb 20, 2024
1 parent f147768 commit a946e58
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 149 deletions.
43 changes: 21 additions & 22 deletions modules/tabs/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@


def server_options_ui(show_out_dir=True):
with gr.Row().style(equal_height=False):
with gr.Row():
with gr.Row():
host = gr.Textbox(value="127.0.0.1", label="host")
port = gr.Textbox(value="5001", label="port")
with gr.Row().style(equal_height=False):
with gr.Row():
with gr.Row():
rvc_model_file = gr.Textbox(
label="RVC model file path",
value=os.path.join(
MODELS_DIR, "pretrained", "beta", "voras_sample_japanese.pth"
),
)
with gr.Row().style(equal_height=False):
with gr.Row():
with gr.Row():
input_voice_file = gr.Textbox(value="", label="input voice file path")
speaker_id = gr.Number(
Expand Down Expand Up @@ -79,25 +79,24 @@ def convert(host, port, input_voice_file, speaker_id):
yield "convert succeed", (sr, audio)

with gr.Group():
with gr.Box():
with gr.Column():
(
host,
port,
rvc_model_file,
input_voice_file,
speaker_id,
) = server_options_ui()

with gr.Row().style(equal_height=False):
with gr.Column():
status = gr.Textbox(value="", label="Status")
output = gr.Audio(label="Output", interactive=False)

with gr.Row():
start_button = gr.Button("Start server", variant="primary")
upload_button = gr.Button("Upload Model")
convert_button = gr.Button("Convert Voice")
with gr.Column():
(
host,
port,
rvc_model_file,
input_voice_file,
speaker_id,
) = server_options_ui()

with gr.Row():
with gr.Column():
status = gr.Textbox(value="", label="Status")
output = gr.Audio(label="Output", interactive=False)

with gr.Row():
start_button = gr.Button("Start server", variant="primary")
upload_button = gr.Button("Upload Model")
convert_button = gr.Button("Convert Voice")

start_button.click(
start,
Expand Down
192 changes: 98 additions & 94 deletions modules/tabs/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def train_all(
yield "Training index..."

with gr.Group():
with gr.Box():
with gr.Accordion("Model Information"):
with gr.Column():
with gr.Row().style():
with gr.Row():
with gr.Column():
model_name = gr.Textbox(label="Model Name")
ignore_cache = gr.Checkbox(label="Ignore cache")
Expand All @@ -127,98 +127,102 @@ def train_all(
multiple_speakers = gr.Checkbox(
label="Multiple speakers", value=False
)
with gr.Row().style(equal_height=False):
version = gr.Radio(
choices=["voras"],
value="voras",
label="Model version",
)
target_sr = gr.Radio(
choices=["24k"],
value="24k",
label="Target sampling rate",
)
f0 = gr.Radio(
choices=["No"],
value="No",
label="f0 Model",
)
with gr.Row().style(equal_height=False):
embedding_name = gr.Radio(
choices=list(models.EMBEDDINGS_LIST.keys()),
value="hubert-base-japanese",
label="Using phone embedder",
)
embedding_channels = gr.Radio(
choices=["768"],
value="768",
label="Embedding channels",
)
embedding_output_layer = gr.Radio(
choices=["12"],
value="12",
label="Embedding output layer",
)
with gr.Row().style(equal_height=False):
gpu_id = gr.Textbox(
label="GPU ID",
value=", ".join([f"{x.index}" for x in utils.get_gpus()]),
)
num_cpu_process = gr.Slider(
minimum=0,
maximum=cpu_count(),
step=1,
value=math.ceil(cpu_count() / 2),
label="Number of CPU processes",
)
with gr.Row().style(equal_height=False):
batch_size = gr.Number(value=4, label="Batch size")
num_epochs = gr.Number(
value=30,
label="Number of epochs",
)
save_every_epoch = gr.Slider(
minimum=0,
maximum=100,
value=10,
step=1,
label="Save every epoch",
)
fp16 = gr.Checkbox(
label="BFP16", value=half_support, disabled=not half_support
)
with gr.Row().style(equal_height=False):
augment = gr.Checkbox(label="Augment", value=True)
augment_from_pretrain = gr.Checkbox(
label="Augment From Pretrain", value=True
)
augment_path = gr.Textbox(
label="Pre trained checkpoint path (pth)",
value=os.path.join(
MODELS_DIR,
"pretrained",
"beta",
"voras_pretrain_libritts_r.pth",
),
)
with gr.Row().style(equal_height=False):
finetuning = gr.Checkbox(label="finetuning", value=True)
pre_trained_generator = gr.Textbox(
label="Pre trained generator path",
value=os.path.join(
MODELS_DIR, "pretrained", "beta", "G24k.pth"
),
)
pre_trained_discriminator = gr.Textbox(
label="Pre trained discriminator path",
value=os.path.join(
MODELS_DIR, "pretrained", "beta", "D24k.pth"
),
)
with gr.Row().style(equal_height=False):
status = gr.Textbox(value="", label="Status")
with gr.Row().style(equal_height=False):
train_all_button = gr.Button("Train", variant="primary")
with gr.Group():
with gr.Accordion("VoRAS Settings"):
with gr.Row():
version = gr.Radio(
choices=["voras"],
value="voras",
label="Model version",
)
target_sr = gr.Radio(
choices=["24k"],
value="24k",
label="Target sampling rate",
)
f0 = gr.Radio(
choices=["No"],
value="No",
label="f0 Model",
)
with gr.Row():
embedding_name = gr.Radio(
choices=list(models.EMBEDDINGS_LIST.keys()),
value="hubert-base-japanese",
label="Using phone embedder",
)
embedding_channels = gr.Radio(
choices=["768"],
value="768",
label="Embedding channels",
)
embedding_output_layer = gr.Radio(
choices=["12"],
value="12",
label="Embedding output layer",
)
with gr.Group():
with gr.Accordion("Training Configuration"):
with gr.Row():
gpu_id = gr.Textbox(
label="GPU ID",
value=", ".join([f"{x.index}" for x in utils.get_gpus()]),
)
num_cpu_process = gr.Slider(
minimum=0,
maximum=cpu_count(),
step=1,
value=math.ceil(cpu_count() / 2),
label="Number of CPU processes",
)
batch_size = gr.Slider(
value=4, minimum=1, maximum=100, step=1, label="Batch size"
)
num_epochs = gr.Slider(
value=100,
minimum=1,
step=1,
maximum=1000,
label="Epochs",
)
save_every_epoch = gr.Slider(
minimum=1,
maximum=100,
value=10,
step=1,
label="Save every epoch",
)

with gr.Row():
augment = gr.Checkbox(label="Augment", value=True)
augment_from_pretrain = gr.Checkbox(
label="Augment From Pretrain", value=True
)
finetuning = gr.Checkbox(label="finetuning", value=True)
fp16 = gr.Checkbox(label="BFP16", value=half_support)
with gr.Row():
pre_trained_generator = gr.Textbox(
label="Pre trained generator path",
value=os.path.join(MODELS_DIR, "pretrained", "beta", "G24k.pth"),
)
pre_trained_discriminator = gr.Textbox(
label="Pre trained discriminator path",
value=os.path.join(MODELS_DIR, "pretrained", "beta", "D24k.pth"),
)
augment_path = gr.Textbox(
label="Pre trained checkpoint path (pth)",
value=os.path.join(
MODELS_DIR,
"pretrained",
"beta",
"voras_pretrain_libritts_r.pth",
),
)

with gr.Group():
with gr.Column():
train_all_button = gr.Button("Train", variant="primary")
status = gr.Textbox(value="", label="Status")

train_all_button.click(
train_all,
Expand Down
31 changes: 3 additions & 28 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from .core import preload
from .shared import ROOT_DIR

import logging
logging.getLogger("httpx").setLevel(logging.CRITICAL)

class Tab:
TABS_DIR = os.path.join(ROOT_DIR, "modules", "tabs")
Expand Down Expand Up @@ -96,34 +98,9 @@ def webpath(fn):
return f"file={web_path}?{os.path.getmtime(fn)}"


def javascript_html():
script_js = os.path.join(ROOT_DIR, "script.js")
head = f'<script type="text/javascript" src="{webpath(script_js)}"></script>\n'

return head


def css_html():
return f'<link rel="stylesheet" property="stylesheet" href="{webpath(os.path.join(ROOT_DIR, "styles.css"))}">'


def create_head():
head = ""
head += css_html()
head += javascript_html()

def template_response(*args, **kwargs):
res = shared.gradio_template_response_original(*args, **kwargs)
res.body = res.body.replace(b"</head>", f"{head}</head>".encode("utf8"))
res.init_headers()
return res

gradio.routes.templates.TemplateResponse = template_response


def create_ui():
preload()
block = gr.Blocks()
block = gr.Blocks(theme="remilia/Ghostly")

with block:
with gr.Tabs():
Expand All @@ -132,8 +109,6 @@ def create_ui():
with gr.Tab(tab.title()):
tab()

create_head()

return block


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gradio==3.28.3
gradio
tqdm==4.65.0
numpy==1.23.5
faiss-cpu==1.7.3
Expand Down
Empty file removed script.js
Empty file.
Empty file removed styles.css
Empty file.
9 changes: 5 additions & 4 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

from modules import cmd_opts, ui

# なんか知らんが湧いて出てくる ".DS_Store" を無視する。
# ここにこんなコードを置くべきかはわからないけど…
_list_dir = os.listdir


def listdir4mac(path):
return [file for file in _list_dir(path) if not file.startswith(".")]


os.listdir = listdir4mac


def webui():
app = ui.create_ui()
app.queue(64)
app, local_url, share_url = app.launch(
app = app.launch(
server_name=cmd_opts.opts.host,
server_port=cmd_opts.opts.port,
share=cmd_opts.opts.share,
inbrowser=True,
)


if __name__ == "__main__":
webui()
webui()

0 comments on commit a946e58

Please sign in to comment.