Skip to content

Commit

Permalink
✨ improve webui split_tab
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Jun 26, 2024
1 parent d8b8596 commit 9578cc7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
36 changes: 29 additions & 7 deletions modules/webui/ssml/spliter_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def create_spliter_tab(ssml_input, tabs1, tabs2):
show_label=False,
value="*auto",
)

with gr.Group():
gr.Markdown("🗣️Seed")
gr.Markdown("💃Inference Seed")
infer_seed_input = gr.Number(
value=42,
label="Inference Seed",
Expand All @@ -84,10 +85,23 @@ def create_spliter_tab(ssml_input, tabs1, tabs2):
)
infer_seed_rand_button = gr.Button(
value="🎲",
# tooltip="Random Seed",
variant="secondary",
)

send_btn = gr.Button("📩Send to SSML", variant="primary")
with gr.Group():
gr.Markdown("🎛️Spliter")
eos_input = gr.Textbox(
label="eos",
value="[uv_break]",
)
spliter_thr_input = gr.Slider(
label="Spliter Threshold",
value=100,
minimum=50,
maximum=1000,
step=1,
)

with gr.Column(scale=3):
with gr.Group():
Expand All @@ -102,19 +116,21 @@ def create_spliter_tab(ssml_input, tabs1, tabs2):
)
long_text_split_button = gr.Button("🔪Split Text")

with gr.Row():
with gr.Column(scale=3):
with gr.Group():
gr.Markdown("🎨Output")
long_text_output = gr.DataFrame(
headers=["index", "text", "length"],
datatype=["number", "str", "number"],
elem_id="long-text-output",
interactive=False,
interactive=True,
wrap=True,
value=[],
row_count=(0, "dynamic"),
col_count=(3, "fixed"),
)

send_btn = gr.Button("📩Send to SSML", variant="primary")

spk_input_dropdown.change(
fn=lambda x: x.startswith("*") and "-1" or x.split(":")[-1].strip(),
inputs=[spk_input_dropdown],
Expand All @@ -132,8 +148,14 @@ def create_spliter_tab(ssml_input, tabs1, tabs2):
)
long_text_split_button.click(
split_long_text,
inputs=[long_text_input],
outputs=[long_text_output],
inputs=[
long_text_input,
spliter_thr_input,
eos_input,
],
outputs=[
long_text_output,
],
)

infer_seed_rand_button.click(
Expand Down
9 changes: 5 additions & 4 deletions modules/webui/webui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ def refine_text(

@torch.inference_mode()
@spaces.GPU(duration=120)
def split_long_text(long_text_input):
spliter = SentenceSplitter(webui_config.spliter_threshold)
def split_long_text(long_text_input, spliter_threshold=100, eos=""):
spliter = SentenceSplitter(threshold=spliter_threshold)
sentences = spliter.parse(long_text_input)
sentences = [text_normalize(s) for s in sentences]
sentences = [text_normalize(s) + eos for s in sentences]
data = []
for i, text in enumerate(sentences):
data.append([i, text, len(text)])
token_length = spliter.count_tokens(text)
data.append([i, text, token_length])
return data

0 comments on commit 9578cc7

Please sign in to comment.