Spaces:
Running
Running
debug new
Browse files- app.py +13 -7
- event_handlers.py +34 -30
- ui_layout.py +17 -2
app.py
CHANGED
@@ -54,18 +54,22 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
54 |
(script_input, tts_model_dropdown, pause_input,
|
55 |
global_speed_input, global_instructions_input) = create_main_input_components(EFFECTIVE_MODEL_DEFAULT)
|
56 |
|
|
|
57 |
(speaker_config_method_dropdown, single_voice_group, global_voice_dropdown,
|
58 |
detailed_per_speaker_ui_group, load_per_speaker_ui_button,
|
59 |
-
|
60 |
|
61 |
(calculate_cost_button, generate_button, cost_output,
|
62 |
individual_lines_zip_output, merged_dialogue_mp3_output,
|
63 |
status_output) = create_action_and_output_components()
|
64 |
|
|
|
65 |
tts_model_dropdown.change(
|
66 |
fn=update_model_controls_visibility,
|
67 |
-
|
68 |
-
|
|
|
|
|
69 |
)
|
70 |
|
71 |
speaker_config_method_dropdown.change(
|
@@ -74,11 +78,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
74 |
outputs=[single_voice_group, detailed_per_speaker_ui_group]
|
75 |
)
|
76 |
|
77 |
-
#
|
78 |
load_per_speaker_ui_button.click(
|
79 |
-
fn=handle_load_refresh_button_click,
|
80 |
-
|
81 |
-
|
|
|
|
|
82 |
)
|
83 |
|
84 |
calculate_cost_button.click(
|
|
|
54 |
(script_input, tts_model_dropdown, pause_input,
|
55 |
global_speed_input, global_instructions_input) = create_main_input_components(EFFECTIVE_MODEL_DEFAULT)
|
56 |
|
57 |
+
# Destructure the returned components from create_speaker_config_components
|
58 |
(speaker_config_method_dropdown, single_voice_group, global_voice_dropdown,
|
59 |
detailed_per_speaker_ui_group, load_per_speaker_ui_button,
|
60 |
+
dynamic_speaker_ui_wrapper) = create_speaker_config_components() # MODIFIED: use dynamic_speaker_ui_wrapper
|
61 |
|
62 |
(calculate_cost_button, generate_button, cost_output,
|
63 |
individual_lines_zip_output, merged_dialogue_mp3_output,
|
64 |
status_output) = create_action_and_output_components()
|
65 |
|
66 |
+
# Event handler for TTS Model Dropdown
|
67 |
tts_model_dropdown.change(
|
68 |
fn=update_model_controls_visibility,
|
69 |
+
# CLEANUP: Removed duplicate speaker_configs_state
|
70 |
+
inputs=[tts_model_dropdown, script_input, speaker_configs_state],
|
71 |
+
# MODIFIED: Output to the wrapper
|
72 |
+
outputs=[global_speed_input, global_instructions_input, dynamic_speaker_ui_wrapper, speaker_configs_state]
|
73 |
)
|
74 |
|
75 |
speaker_config_method_dropdown.change(
|
|
|
78 |
outputs=[single_voice_group, detailed_per_speaker_ui_group]
|
79 |
)
|
80 |
|
81 |
+
# Event handler for the "Load/Refresh" Button
|
82 |
load_per_speaker_ui_button.click(
|
83 |
+
fn=handle_load_refresh_button_click,
|
84 |
+
# CLEANUP: Removed duplicate speaker_configs_state
|
85 |
+
inputs=[script_input, speaker_configs_state, tts_model_dropdown],
|
86 |
+
# MODIFIED: Output to the wrapper
|
87 |
+
outputs=[dynamic_speaker_ui_wrapper, speaker_configs_state]
|
88 |
)
|
89 |
|
90 |
calculate_cost_button.click(
|
event_handlers.py
CHANGED
@@ -44,25 +44,16 @@ def handle_dynamic_input_change(new_value, current_configs_state_dict: dict, spe
|
|
44 |
return current_configs_state_dict
|
45 |
|
46 |
|
47 |
-
|
|
|
48 |
"""
|
49 |
Core logic for generating per-speaker UI components.
|
50 |
-
Returns: (
|
51 |
"""
|
52 |
-
|
53 |
-
|
54 |
-
debug_markdown = gr.Markdown("## !!
|
55 |
-
return [debug_markdown], {}
|
56 |
-
# --- END OF PHASE 1 DEBUGGING ---
|
57 |
-
|
58 |
-
# --- ORIGINAL LOGIC (Commented out for Phase 1) ---
|
59 |
-
# print(f"load_refresh_per_speaker_ui_core CALLED. TTS Model: {tts_model}")
|
60 |
-
# unique_speakers = get_speakers_from_script(script_text)
|
61 |
-
# new_ui_components = []
|
62 |
-
# # ... (rest of original logic from previous load_refresh_per_speaker_ui) ...
|
63 |
-
# # Make sure this original logic path would also return:
|
64 |
-
# # return new_ui_components, current_configs_state_dict
|
65 |
-
# --- END OF ORIGINAL LOGIC ---
|
66 |
|
67 |
|
68 |
async def handle_script_processing(
|
@@ -212,28 +203,41 @@ def handle_calculate_cost(dialogue_script: str, tts_model: str):
|
|
212 |
return f"An unexpected error occurred during cost calculation: {str(e)}"
|
213 |
|
214 |
# Wrapper for the "Load/Refresh Per-Speaker UI Button" click
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
218 |
)
|
219 |
-
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
221 |
|
222 |
-
|
|
|
|
|
223 |
"""Updates visibility of global controls and refreshes per-speaker UI when TTS model changes."""
|
224 |
-
print(f"Model changed to: {selected_model}. Refreshing dynamic UI and controls.")
|
225 |
try:
|
226 |
-
|
227 |
-
|
228 |
-
script_text_for_refresh, current_configs_state_dict, selected_model, speaker_configs_state_comp
|
229 |
)
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
232 |
|
233 |
except Exception as e:
|
234 |
print(f"Error in load_refresh_per_speaker_ui_core called from model_controls_visibility: {e}")
|
235 |
error_markdown = gr.Markdown(f"Error refreshing per-speaker UI: {e}")
|
236 |
-
|
|
|
|
|
237 |
updated_state_dict = current_configs_state_dict
|
238 |
|
239 |
is_tts1_family = selected_model in ["tts-1", "tts-1-hd"]
|
@@ -242,7 +246,7 @@ def update_model_controls_visibility(selected_model: str, script_text_for_refres
|
|
242 |
return (
|
243 |
gr.update(visible=is_tts1_family, interactive=is_tts1_family),
|
244 |
gr.update(visible=is_gpt_mini_tts, interactive=is_gpt_mini_tts),
|
245 |
-
|
246 |
updated_state_dict
|
247 |
)
|
248 |
|
|
|
44 |
return current_configs_state_dict
|
45 |
|
46 |
|
47 |
+
# CLEANUP: Modify function signatures to remove the redundant speaker_configs_state_comp argument
|
48 |
+
def load_refresh_per_speaker_ui_core(script_text: str, current_configs_state_dict: dict, tts_model: str):
|
49 |
"""
|
50 |
Core logic for generating per-speaker UI components.
|
51 |
+
Returns: (list_of_components_for_inner_column, updated_state_dict)
|
52 |
"""
|
53 |
+
print(f"DEBUG: load_refresh_per_speaker_ui_core CALLED (for wrapper). TTS Model: {tts_model}")
|
54 |
+
# This list of components will be the children of the *new inner column*
|
55 |
+
debug_markdown = gr.Markdown("## !! Test Content for Inner Column (via Wrapper) !!")
|
56 |
+
return [debug_markdown], {} # Returns: (list_of_components, state_dictionary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
|
59 |
async def handle_script_processing(
|
|
|
203 |
return f"An unexpected error occurred during cost calculation: {str(e)}"
|
204 |
|
205 |
# Wrapper for the "Load/Refresh Per-Speaker UI Button" click
|
206 |
+
# CLEANUP: Signature changed
|
207 |
+
def handle_load_refresh_button_click(script_text: str, current_configs_state_dict: dict, tts_model: str):
|
208 |
+
components_list_for_inner_column, new_state_dict = load_refresh_per_speaker_ui_core(
|
209 |
+
script_text, current_configs_state_dict, tts_model # CLEANUP: Removed speaker_configs_state_comp
|
210 |
)
|
211 |
+
|
212 |
+
# Create a new instance of the inner gr.Column with the dynamic children
|
213 |
+
new_inner_column = gr.Column(children=components_list_for_inner_column, elem_id="dynamic_ui_area_for_speakers")
|
214 |
+
|
215 |
+
# Return gr.update for the wrapper group (to replace its children with the new_inner_column),
|
216 |
+
# and the raw state dict for the gr.State component.
|
217 |
+
return gr.update(children=[new_inner_column]), new_state_dict
|
218 |
|
219 |
+
# Handler for TTS model dropdown change
|
220 |
+
# CLEANUP: Signature changed
|
221 |
+
def update_model_controls_visibility(selected_model: str, script_text_for_refresh: str, current_configs_state_dict: dict):
|
222 |
"""Updates visibility of global controls and refreshes per-speaker UI when TTS model changes."""
|
223 |
+
print(f"Model changed to: {selected_model}. Refreshing dynamic UI (via wrapper) and controls.")
|
224 |
try:
|
225 |
+
dynamic_ui_children_list, updated_state_dict = load_refresh_per_speaker_ui_core(
|
226 |
+
script_text_for_refresh, current_configs_state_dict, selected_model # CLEANUP: Removed speaker_configs_state_comp
|
|
|
227 |
)
|
228 |
+
|
229 |
+
# Create a new instance of the inner gr.Column
|
230 |
+
new_inner_column_for_model_change = gr.Column(children=dynamic_ui_children_list, elem_id="dynamic_ui_area_for_speakers")
|
231 |
+
|
232 |
+
# This will be the update for the dynamic_speaker_ui_wrapper
|
233 |
+
dynamic_ui_update_for_wrapper = gr.update(children=[new_inner_column_for_model_change])
|
234 |
|
235 |
except Exception as e:
|
236 |
print(f"Error in load_refresh_per_speaker_ui_core called from model_controls_visibility: {e}")
|
237 |
error_markdown = gr.Markdown(f"Error refreshing per-speaker UI: {e}")
|
238 |
+
# Update the wrapper to show an error message inside a new inner column
|
239 |
+
error_inner_column = gr.Column(children=[error_markdown], elem_id="dynamic_ui_area_for_speakers")
|
240 |
+
dynamic_ui_update_for_wrapper = gr.update(children=[error_inner_column])
|
241 |
updated_state_dict = current_configs_state_dict
|
242 |
|
243 |
is_tts1_family = selected_model in ["tts-1", "tts-1-hd"]
|
|
|
246 |
return (
|
247 |
gr.update(visible=is_tts1_family, interactive=is_tts1_family),
|
248 |
gr.update(visible=is_gpt_mini_tts, interactive=is_gpt_mini_tts),
|
249 |
+
dynamic_ui_update_for_wrapper, # MODIFIED: This now updates the wrapper
|
250 |
updated_state_dict
|
251 |
)
|
252 |
|
ui_layout.py
CHANGED
@@ -80,9 +80,24 @@ def create_speaker_config_components():
|
|
80 |
with gr.Column(visible=(DEFAULT_SPEAKER_CONFIG_METHOD == "Detailed Configuration (Per Speaker UI)")) as detailed_per_speaker_ui_group:
|
81 |
load_per_speaker_ui_button = gr.Button("Load/Refresh Per-Speaker Settings UI (from Script Above)")
|
82 |
gr.Markdown("<small>Click button above to populate settings for each speaker found in the script. Settings are applied per-speaker. If script changes, click again to refresh.</small>")
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
def create_action_and_output_components():
|
88 |
"""Creates buttons for actions (cost, generate) and output display areas."""
|
|
|
80 |
with gr.Column(visible=(DEFAULT_SPEAKER_CONFIG_METHOD == "Detailed Configuration (Per Speaker UI)")) as detailed_per_speaker_ui_group:
|
81 |
load_per_speaker_ui_button = gr.Button("Load/Refresh Per-Speaker Settings UI (from Script Above)")
|
82 |
gr.Markdown("<small>Click button above to populate settings for each speaker found in the script. Settings are applied per-speaker. If script changes, click again to refresh.</small>")
|
83 |
+
|
84 |
+
# NEW: Wrapper for the dynamic area
|
85 |
+
# This group will now be the target for updates.
|
86 |
+
dynamic_speaker_ui_wrapper = gr.Group(elem_id="dynamic_ui_wrapper_for_speakers")
|
87 |
+
with dynamic_speaker_ui_wrapper:
|
88 |
+
# The actual column is now a child of the wrapper.
|
89 |
+
# It can be initially empty or have a placeholder if desired.
|
90 |
+
dynamic_speaker_ui_area = gr.Column(elem_id="dynamic_ui_area_for_speakers")
|
91 |
|
92 |
+
# Ensure the new wrapper is returned correctly
|
93 |
+
return (
|
94 |
+
speaker_config_method_dropdown,
|
95 |
+
single_voice_group,
|
96 |
+
global_voice_dropdown,
|
97 |
+
detailed_per_speaker_ui_group,
|
98 |
+
load_per_speaker_ui_button,
|
99 |
+
dynamic_speaker_ui_wrapper # MODIFIED: Return the wrapper
|
100 |
+
)
|
101 |
|
102 |
def create_action_and_output_components():
|
103 |
"""Creates buttons for actions (cost, generate) and output display areas."""
|