diff --git a/webui.py b/webui.py index f99d32f..b499bd7 100644 --- a/webui.py +++ b/webui.py @@ -1,5 +1,4 @@ import html -import json import os import sys import threading @@ -74,40 +73,6 @@ os.makedirs("outputs/tasks",exist_ok=True) os.makedirs("prompts",exist_ok=True) MAX_LENGTH_TO_USE_SPEED = 70 -example_cases = [] -with open("examples/cases.jsonl", "r", encoding="utf-8") as f: - for line in f: - line = line.strip() - if not line: - continue - example = json.loads(line) - if example.get("emo_audio",None): - emo_audio_path = os.path.join("examples",example["emo_audio"]) - else: - emo_audio_path = None - - example_cases.append([os.path.join("examples", example.get("prompt_audio", "sample_prompt.wav")), - EMO_CHOICES_ALL[example.get("emo_mode",0)], - example.get("text"), - emo_audio_path, - example.get("emo_weight",1.0), - example.get("emo_text",""), - example.get("emo_vec_1",0), - example.get("emo_vec_2",0), - example.get("emo_vec_3",0), - example.get("emo_vec_4",0), - example.get("emo_vec_5",0), - example.get("emo_vec_6",0), - example.get("emo_vec_7",0), - example.get("emo_vec_8",0), - ]) - -def get_example_cases(include_experimental = False): - if include_experimental: - return example_cases # show every example - - # exclude emotion control mode 3 (emotion from text description) - return [x for x in example_cases if x[1] != EMO_CHOICES_ALL[3]] def format_glossary_markdown(): """将词汇表转换为Markdown表格格式""" @@ -323,56 +288,6 @@ with gr.Blocks(title="IndexTTS Demo") as demo: # typical_sampling, typical_mass, ] - # we must use `gr.Dataset` to support dynamic UI rewrites, since `gr.Examples` - # binds tightly to UI and always restores the initial state of all components, - # such as the list of available choices in emo_control_method. - example_table = gr.Dataset(label="Examples", - samples_per_page=20, - samples=get_example_cases(include_experimental=False), - type="values", - # these components are NOT "connected". it just reads the column labels/available - # states from them, so we MUST link to the "all options" versions of all components, - # such as `emo_control_method_all` (to be able to see EXPERIMENTAL text labels)! - components=[prompt_audio, - emo_control_method_all, # important: support all mode labels! - input_text_single, - emo_upload, - emo_weight, - emo_text, - vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8] - ) - - def on_example_click(example): - print(f"Example clicked: ({len(example)} values) = {example!r}") - return ( - gr.update(value=example[0]), - gr.update(value=example[1]), - gr.update(value=example[2]), - gr.update(value=example[3]), - gr.update(value=example[4]), - gr.update(value=example[5]), - gr.update(value=example[6]), - gr.update(value=example[7]), - gr.update(value=example[8]), - gr.update(value=example[9]), - gr.update(value=example[10]), - gr.update(value=example[11]), - gr.update(value=example[12]), - gr.update(value=example[13]), - ) - - # click() event works on both desktop and mobile UI - example_table.click(on_example_click, - inputs=[example_table], - outputs=[prompt_audio, - emo_control_method, - input_text_single, - emo_upload, - emo_weight, - emo_text, - vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8] - ) - def on_input_text_change(text, max_text_tokens_per_segment): if text and len(text) > 0: text_tokens_list = tts.tokenizer.tokenize(text) @@ -480,15 +395,12 @@ with gr.Blocks(title="IndexTTS Demo") as demo: # we don't verify that OLD index means the same in NEW list, since we KNOW it does. new_index = current_mode_index if current_mode_index < len(new_choices) else 0 - return ( - gr.update(choices=new_choices, value=new_choices[new_index]), - gr.update(samples=get_example_cases(include_experimental=is_experimental)), - ) + return gr.update(choices=new_choices, value=new_choices[new_index]) experimental_checkbox.change( on_experimental_change, inputs=[experimental_checkbox, emo_control_method], - outputs=[emo_control_method, example_table] + outputs=[emo_control_method] ) def on_glossary_checkbox_change(is_enabled):