Skip to content

Commit

Permalink
improve models selector logic
Browse files Browse the repository at this point in the history
  • Loading branch information
blaisewf committed Dec 21, 2024
1 parent 7a8e12c commit 1ef4765
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 12 additions & 2 deletions tabs/inference/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
)
]

default_weight = names[0] if names else None

indexes_list = [
os.path.join(root, name)
for root, _, files in os.walk(model_root_relative, topdown=False)
Expand Down Expand Up @@ -239,6 +241,15 @@ def get_indexes():
return indexes_list if indexes_list else ""


def extract_model_and_epoch(path):
base_name = os.path.basename(path)
match = re.match(r'(.+?)_(\d+)e_', base_name)
if match:
model, epoch = match.groups()
return model, int(epoch)
return "", 0


def save_to_wav(record_button):
if record_button is None:
pass
Expand Down Expand Up @@ -337,13 +348,12 @@ def get_speakers_id(model):

# Inference tab
def inference_tab():
default_weight = names[0] if names else None
with gr.Column():
with gr.Row():
model_file = gr.Dropdown(
label=i18n("Voice Model"),
info=i18n("Select the voice model to use for the conversion."),
choices=sorted(names, key=lambda path: os.path.getsize(path)),
choices=sorted(names, key=lambda x: extract_model_and_epoch(x)),
interactive=True,
value=default_weight,
allow_custom_value=True,
Expand Down
7 changes: 4 additions & 3 deletions tabs/tts/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
get_indexes,
get_speakers_id,
match_index,
names,
refresh_embedders_folders,
extract_model_and_epoch,
names,
default_weight,
)

i18n = I18nAuto()

default_weight = random.choice(names) if names else ""

with open(
os.path.join("rvc", "lib", "tools", "tts_voices.json"), "r", encoding="utf-8"
Expand Down Expand Up @@ -50,7 +51,7 @@ def tts_tab():
model_file = gr.Dropdown(
label=i18n("Voice Model"),
info=i18n("Select the voice model to use for the conversion."),
choices=sorted(names, key=lambda path: os.path.getsize(path)),
choices=sorted(names, key=lambda x: extract_model_and_epoch(x)),
interactive=True,
value=default_weight,
allow_custom_value=True,
Expand Down

0 comments on commit 1ef4765

Please sign in to comment.