diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py
index 246748ae..3f93352b 100644
--- a/GPT_SoVITS/inference_webui.py
+++ b/GPT_SoVITS/inference_webui.py
@@ -32,6 +32,8 @@ from time import time as ttime
from module.mel_processing import spectrogram_torch
from my_utils import load_audio
from tools.i18n.i18n import I18nAuto
+import random
+import pandas as pd
i18n = I18nAuto()
device = "cuda"
@@ -326,6 +328,28 @@ def cut3(inp):
return "\n".join(["%s。" % item for item in inp.strip("。").split("。")])
+def select_random_file(folder_path):
+ files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
+ return os.path.join(folder_path, random.choice(files))
+
+
+def get_labels(csv_path):
+ if csv_path:
+ df = pd.read_csv(csv_path)
+ return {"choices": df['clust'].unique().tolist(), "__type__": "update"}
+ else:
+ return {"choices": [], "__type__": "update"}
+
+
+def select_random_file_from_csv(csv_path, label, folder_path):
+ if csv_path:
+ df = pd.read_csv(csv_path)
+ files = df[df['clust'] == label]['filename'].apply(os.path.basename).tolist()
+ return os.path.join(folder_path, random.choice(files))
+ else:
+ return select_random_file(folder_path)
+
+
with gr.Blocks(title="GPT-SoVITS WebUI") as app:
gr.Markdown(
value=i18n("本软件以MIT协议开源, 作者不对软件具备任何控制力, 使用软件者、传播软件导出的声音者自负全责.
如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录LICENSE.")
@@ -333,9 +357,18 @@ with gr.Blocks(title="GPT-SoVITS WebUI") as app:
# with gr.Tabs():
# with gr.TabItem(i18n("伴奏人声分离&去混响&去回声")):
with gr.Group():
+ gr.Markdown(value="随机抽取参考音频,可以导入csv文件限定抽取范围,csv第一列为filename,第二列为clust(类别标签)")
+ with gr.Row():
+ folder_path = gr.Textbox(label="请输入音频文件夹路径", value="")
+ csv_path = gr.Textbox(label="请输入CSV文件路径(可选)", value="")
+ label = gr.Dropdown(label="请选择一个标签(可选)", choices=[], value="")
+ update_labels_button = gr.Button("更新标签", variant="primary")
+ update_labels_button.click(get_labels, [csv_path], [label])
+ random_file_button = gr.Button("随机选择音频文件", variant="primary")
gr.Markdown(value=i18n("*请上传并填写参考信息"))
with gr.Row():
inp_ref = gr.Audio(label=i18n("请上传参考音频"), type="filepath")
+ random_file_button.click(select_random_file_from_csv, [csv_path, label, folder_path], [inp_ref])
prompt_text = gr.Textbox(label=i18n("参考音频的文本"), value="")
prompt_language = gr.Dropdown(
label=i18n("参考音频的语种"),choices=[i18n("中文"),i18n("英文"),i18n("日文")],value=i18n("中文")