Spaces:
Running
Running
debug
Browse files- event_handlers.py +94 -87
event_handlers.py
CHANGED
@@ -51,96 +51,103 @@ def load_refresh_per_speaker_ui(script_text: str, current_configs_state_dict: di
|
|
51 |
Generates or refreshes the dynamic UI components (accordions) for each speaker.
|
52 |
Returns a list of Gradio components to populate the dynamic UI area and the updated state.
|
53 |
"""
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
)
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
114 |
|
115 |
-
# Vibe Dropdown
|
116 |
-
vibe_label = "Vibe/Emotion Preset" + (" (For gpt-4o-mini-tts)" if instructions_relevant else " (Less impact on other models)")
|
117 |
-
vibe_dd = gr.Dropdown(
|
118 |
-
label=vibe_label, choices=VIBE_CHOICES, value=speaker_cfg.get("vibe", DEFAULT_VIBE), interactive=True
|
119 |
-
)
|
120 |
-
vibe_dd.change(
|
121 |
-
fn=partial(handle_dynamic_input_change, speaker_name=speaker_name, config_key="vibe", tts_model=tts_model),
|
122 |
-
inputs=[vibe_dd, speaker_configs_state_component],
|
123 |
-
outputs=[speaker_configs_state_component]
|
124 |
-
)
|
125 |
-
|
126 |
-
# Custom Instructions Textbox
|
127 |
-
custom_instr_label = "Custom Instructions"
|
128 |
-
custom_instr_placeholder = "Used if Vibe is 'Custom...'. Overrides Vibe preset."
|
129 |
-
custom_instr_tb = gr.Textbox(
|
130 |
-
label=custom_instr_label,
|
131 |
-
value=speaker_cfg.get("custom_instructions", ""),
|
132 |
-
placeholder=custom_instr_placeholder,
|
133 |
-
lines=2, interactive=True
|
134 |
-
)
|
135 |
-
custom_instr_tb.input(
|
136 |
-
fn=partial(handle_dynamic_input_change, speaker_name=speaker_name, config_key="custom_instructions", tts_model=tts_model),
|
137 |
-
inputs=[custom_instr_tb, speaker_configs_state_component],
|
138 |
-
outputs=[speaker_configs_state_component]
|
139 |
-
)
|
140 |
-
new_ui_components.append(speaker_accordion)
|
141 |
|
142 |
-
print(f"Returning {len(new_ui_components)} UI components for dynamic area.") # Debug
|
143 |
-
return new_ui_components, current_configs_state_dict
|
144 |
|
145 |
|
146 |
async def handle_script_processing(
|
|
|
51 |
Generates or refreshes the dynamic UI components (accordions) for each speaker.
|
52 |
Returns a list of Gradio components to populate the dynamic UI area and the updated state.
|
53 |
"""
|
54 |
+
# event_handlers.py - inside load_refresh_per_speaker_ui
|
55 |
+
print("DEBUG: load_refresh_per_speaker_ui CALLED - HARDCODED RETURN")
|
56 |
+
debug_markdown = gr.Markdown("## !! Dynamic Area Test Content Loaded !!")
|
57 |
+
# Return this simple component and an empty dict for state for now
|
58 |
+
return [debug_markdown], {}
|
59 |
+
# Comment out ALL original logic in this function for this test.
|
60 |
|
61 |
+
# print(f"Load/Refresh UI called. TTS Model: {tts_model}") # Debug
|
62 |
+
# unique_speakers = get_speakers_from_script(script_text)
|
63 |
+
# new_ui_components = []
|
64 |
+
|
65 |
+
# if current_configs_state_dict is None:
|
66 |
+
# current_configs_state_dict = {}
|
67 |
+
|
68 |
+
# # Ensure a default voice for safety
|
69 |
+
# safe_default_voice = APP_AVAILABLE_VOICES[0] if APP_AVAILABLE_VOICES else "alloy"
|
70 |
+
|
71 |
+
# for speaker_name in unique_speakers:
|
72 |
+
# if speaker_name not in current_configs_state_dict:
|
73 |
+
# current_configs_state_dict[speaker_name] = {
|
74 |
+
# "voice": safe_default_voice, "speed": 1.0,
|
75 |
+
# "vibe": DEFAULT_VIBE, "custom_instructions": ""
|
76 |
+
# }
|
77 |
+
# # Ensure all keys exist with defaults
|
78 |
+
# current_configs_state_dict[speaker_name].setdefault("voice", safe_default_voice)
|
79 |
+
# current_configs_state_dict[speaker_name].setdefault("speed", 1.0)
|
80 |
+
# current_configs_state_dict[speaker_name].setdefault("vibe", DEFAULT_VIBE)
|
81 |
+
# current_configs_state_dict[speaker_name].setdefault("custom_instructions", "")
|
82 |
+
|
83 |
+
# if not unique_speakers:
|
84 |
+
# print("No unique speakers found, returning markdown.") # Debug
|
85 |
+
# new_ui_components.append(gr.Markdown("No speakers detected in the script, or script is empty. Type a script and click 'Load/Refresh' again, or change the script content."))
|
86 |
+
# return new_ui_components, current_configs_state_dict
|
87 |
+
|
88 |
+
# print(f"Found speakers: {unique_speakers}. Building UI...") # Debug
|
89 |
+
# for speaker_name in unique_speakers:
|
90 |
+
# speaker_cfg = current_configs_state_dict[speaker_name]
|
91 |
+
|
92 |
+
# speed_interactive = tts_model in ["tts-1", "tts-1-hd"]
|
93 |
+
# instructions_relevant = tts_model == "gpt-4o-mini-tts"
|
94 |
+
|
95 |
+
# # Use a unique elem_id for each accordion to help Gradio differentiate if needed
|
96 |
+
# accordion_elem_id = f"accordion_speaker_{speaker_name.replace(' ', '_')}"
|
97 |
+
|
98 |
+
# with gr.Accordion(label=f"Settings for: {speaker_name}", open=False, elem_id=accordion_elem_id) as speaker_accordion:
|
99 |
+
# # Voice Dropdown
|
100 |
+
# voice_dd = gr.Dropdown(
|
101 |
+
# label="Voice", choices=APP_AVAILABLE_VOICES, value=speaker_cfg.get("voice", safe_default_voice), interactive=True
|
102 |
+
# )
|
103 |
+
# voice_dd.change(
|
104 |
+
# fn=partial(handle_dynamic_input_change, speaker_name=speaker_name, config_key="voice", tts_model=tts_model),
|
105 |
+
# inputs=[voice_dd, speaker_configs_state_component],
|
106 |
+
# outputs=[speaker_configs_state_component]
|
107 |
+
# )
|
108 |
+
|
109 |
+
# # Speed Slider
|
110 |
+
# speed_slider_label = "Speech Speed" + (" (Active for tts-1/hd)" if speed_interactive else " (N/A for this model)")
|
111 |
+
# speed_slider = gr.Slider(
|
112 |
+
# label=speed_slider_label, minimum=0.25, maximum=4.0, value=float(speaker_cfg.get("speed", 1.0)),
|
113 |
+
# step=0.05, interactive=speed_interactive
|
114 |
+
# )
|
115 |
+
# if speed_interactive:
|
116 |
+
# speed_slider.release(
|
117 |
+
# fn=partial(handle_dynamic_input_change, speaker_name=speaker_name, config_key="speed", tts_model=tts_model),
|
118 |
+
# inputs=[speed_slider, speaker_configs_state_component],
|
119 |
+
# outputs=[speaker_configs_state_component]
|
120 |
+
# )
|
121 |
|
122 |
+
# # Vibe Dropdown
|
123 |
+
# vibe_label = "Vibe/Emotion Preset" + (" (For gpt-4o-mini-tts)" if instructions_relevant else " (Less impact on other models)")
|
124 |
+
# vibe_dd = gr.Dropdown(
|
125 |
+
# label=vibe_label, choices=VIBE_CHOICES, value=speaker_cfg.get("vibe", DEFAULT_VIBE), interactive=True
|
126 |
+
# )
|
127 |
+
# vibe_dd.change(
|
128 |
+
# fn=partial(handle_dynamic_input_change, speaker_name=speaker_name, config_key="vibe", tts_model=tts_model),
|
129 |
+
# inputs=[vibe_dd, speaker_configs_state_component],
|
130 |
+
# outputs=[speaker_configs_state_component]
|
131 |
+
# )
|
132 |
+
|
133 |
+
# # Custom Instructions Textbox
|
134 |
+
# custom_instr_label = "Custom Instructions"
|
135 |
+
# custom_instr_placeholder = "Used if Vibe is 'Custom...'. Overrides Vibe preset."
|
136 |
+
# custom_instr_tb = gr.Textbox(
|
137 |
+
# label=custom_instr_label,
|
138 |
+
# value=speaker_cfg.get("custom_instructions", ""),
|
139 |
+
# placeholder=custom_instr_placeholder,
|
140 |
+
# lines=2, interactive=True
|
141 |
+
# )
|
142 |
+
# custom_instr_tb.input(
|
143 |
+
# fn=partial(handle_dynamic_input_change, speaker_name=speaker_name, config_key="custom_instructions", tts_model=tts_model),
|
144 |
+
# inputs=[custom_instr_tb, speaker_configs_state_component],
|
145 |
+
# outputs=[speaker_configs_state_component]
|
146 |
+
# )
|
147 |
+
# new_ui_components.append(speaker_accordion)
|
148 |
|
149 |
+
# print(f"Returning {len(new_ui_components)} UI components for dynamic area.") # Debug
|
150 |
+
# return new_ui_components, current_configs_state_dict
|
151 |
|
152 |
|
153 |
async def handle_script_processing(
|