abocha commited on
Commit
7b60030
·
1 Parent(s): d796b83
Files changed (1) hide show
  1. event_handlers.py +19 -13
event_handlers.py CHANGED
@@ -17,6 +17,7 @@ DEFAULT_FALLBACK_VOICE = APP_AVAILABLE_VOICES[0] if APP_AVAILABLE_VOICES else "a
17
 
18
 
19
  def get_speakers_from_script(script_text: str):
 
20
  if not script_text.strip():
21
  return []
22
  try:
@@ -33,6 +34,7 @@ def get_speakers_from_script(script_text: str):
33
 
34
 
35
  def handle_dynamic_input_change(new_value, current_configs_state_dict: dict, speaker_name: str, config_key: str, tts_model: str):
 
36
  if current_configs_state_dict is None:
37
  current_configs_state_dict = {}
38
  if speaker_name not in current_configs_state_dict:
@@ -43,11 +45,11 @@ def handle_dynamic_input_change(new_value, current_configs_state_dict: dict, spe
43
 
44
 
45
  def load_refresh_per_speaker_ui(script_text: str, current_configs_state_dict: dict, tts_model: str, speaker_configs_state_component: gr.State):
46
- # --- START OF PHASE 1 DEBUGGING (MODIFIED) ---
47
- print("DEBUG: load_refresh_per_speaker_ui CALLED - Phase 1: HARDCODED RETURN with gr.update()")
48
- debug_markdown = gr.Markdown("## !! Dynamic Area Test Content Loaded (gr.update) !!")
49
- # Return an explicit gr.update for the column's children, and the state update
50
- return gr.update(children=[debug_markdown]), {}
51
  # --- END OF PHASE 1 DEBUGGING ---
52
 
53
  # --- ORIGINAL LOGIC (Commented out for Phase 1) ---
@@ -55,21 +57,21 @@ def load_refresh_per_speaker_ui(script_text: str, current_configs_state_dict: di
55
  # unique_speakers = get_speakers_from_script(script_text)
56
  # new_ui_components = []
57
  # # ... (rest of original logic) ...
58
- # # At the end of original logic, if returning components for the column:
59
- # # return gr.update(children=new_ui_components), current_configs_state_dict
60
  # --- END OF ORIGINAL LOGIC ---
61
 
62
 
63
  async def handle_script_processing(
64
  openai_api_key: str, async_openai_client, nsfw_api_url_template: str,
65
  dialogue_script: str, tts_model: str, pause_ms: int,
 
66
  speaker_config_method: str, global_voice_selection: str,
67
  speaker_configs_state_dict: dict,
68
  global_speed: float,
69
  global_instructions: str,
70
  progress=gr.Progress(track_tqdm=True)
71
  ):
72
- # ... (content of this function remains unchanged from the previous correct version) ...
73
  if not openai_api_key or not async_openai_client:
74
  return None, None, "Error: OpenAI API Key or client is not configured."
75
  if not dialogue_script.strip():
@@ -193,7 +195,7 @@ async def handle_script_processing(
193
  status)
194
 
195
  def handle_calculate_cost(dialogue_script: str, tts_model: str):
196
- # ... (content of this function remains unchanged) ...
197
  if not dialogue_script.strip(): return "Cost: $0.00 (Script is empty)"
198
  try:
199
  parsed, chars = parse_dialogue_script(dialogue_script)
@@ -209,14 +211,17 @@ def update_model_controls_visibility(selected_model: str, script_text_for_refres
209
  """Updates visibility of global controls and refreshes per-speaker UI when TTS model changes."""
210
  print(f"Model changed to: {selected_model}. Refreshing dynamic UI and controls.")
211
  try:
212
- # load_refresh_per_speaker_ui now returns (gr.update(children=...), updated_state_dict)
213
- dynamic_ui_update_object, updated_state_dict = load_refresh_per_speaker_ui(
214
  script_text_for_refresh, current_speaker_configs_for_refresh, selected_model, speaker_configs_state_comp
215
  )
 
 
 
216
  except Exception as e:
217
  print(f"Error in load_refresh_per_speaker_ui called from model_controls_visibility: {e}")
218
  error_markdown = gr.Markdown(f"Error refreshing per-speaker UI: {e}")
219
- dynamic_ui_update_object = gr.update(children=[error_markdown]) # Wrap error in update
220
  updated_state_dict = current_speaker_configs_for_refresh
221
 
222
  is_tts1_family = selected_model in ["tts-1", "tts-1-hd"]
@@ -225,12 +230,13 @@ def update_model_controls_visibility(selected_model: str, script_text_for_refres
225
  return (
226
  gr.update(visible=is_tts1_family, interactive=is_tts1_family),
227
  gr.update(visible=is_gpt_mini_tts, interactive=is_gpt_mini_tts),
228
- dynamic_ui_update_object, # This is now directly the gr.update object for the column
229
  updated_state_dict
230
  )
231
 
232
 
233
  def update_speaker_config_method_visibility(method: str):
 
234
  is_single = (method == "Single Voice (Global)")
235
  is_detailed_per_speaker = (method == "Detailed Configuration (Per Speaker UI)")
236
 
 
17
 
18
 
19
  def get_speakers_from_script(script_text: str):
20
+ # ... (no change) ...
21
  if not script_text.strip():
22
  return []
23
  try:
 
34
 
35
 
36
  def handle_dynamic_input_change(new_value, current_configs_state_dict: dict, speaker_name: str, config_key: str, tts_model: str):
37
+ # ... (no change) ...
38
  if current_configs_state_dict is None:
39
  current_configs_state_dict = {}
40
  if speaker_name not in current_configs_state_dict:
 
45
 
46
 
47
  def load_refresh_per_speaker_ui(script_text: str, current_configs_state_dict: dict, tts_model: str, speaker_configs_state_component: gr.State):
48
+ # --- START OF PHASE 1 DEBUGGING (MODIFIED - returns list directly) ---
49
+ print("DEBUG: load_refresh_per_speaker_ui CALLED - Phase 1: HARDCODED RETURN (list of components)")
50
+ debug_markdown = gr.Markdown("## !! Dynamic Area Test Content Loaded (Direct List) !!")
51
+ # Return the list of components and the state update
52
+ return [debug_markdown], {}
53
  # --- END OF PHASE 1 DEBUGGING ---
54
 
55
  # --- ORIGINAL LOGIC (Commented out for Phase 1) ---
 
57
  # unique_speakers = get_speakers_from_script(script_text)
58
  # new_ui_components = []
59
  # # ... (rest of original logic) ...
60
+ # # At the end of original logic, it would be:
61
+ # # return new_ui_components, current_configs_state_dict
62
  # --- END OF ORIGINAL LOGIC ---
63
 
64
 
65
  async def handle_script_processing(
66
  openai_api_key: str, async_openai_client, nsfw_api_url_template: str,
67
  dialogue_script: str, tts_model: str, pause_ms: int,
68
+ # ... (rest of function signature and body unchanged) ...
69
  speaker_config_method: str, global_voice_selection: str,
70
  speaker_configs_state_dict: dict,
71
  global_speed: float,
72
  global_instructions: str,
73
  progress=gr.Progress(track_tqdm=True)
74
  ):
 
75
  if not openai_api_key or not async_openai_client:
76
  return None, None, "Error: OpenAI API Key or client is not configured."
77
  if not dialogue_script.strip():
 
195
  status)
196
 
197
  def handle_calculate_cost(dialogue_script: str, tts_model: str):
198
+ # ... (no change) ...
199
  if not dialogue_script.strip(): return "Cost: $0.00 (Script is empty)"
200
  try:
201
  parsed, chars = parse_dialogue_script(dialogue_script)
 
211
  """Updates visibility of global controls and refreshes per-speaker UI when TTS model changes."""
212
  print(f"Model changed to: {selected_model}. Refreshing dynamic UI and controls.")
213
  try:
214
+ # load_refresh_per_speaker_ui now returns (list_of_components, updated_state_dict)
215
+ dynamic_ui_components_list, updated_state_dict = load_refresh_per_speaker_ui(
216
  script_text_for_refresh, current_speaker_configs_for_refresh, selected_model, speaker_configs_state_comp
217
  )
218
+ # Wrap the list of components in gr.update(children=...) here
219
+ dynamic_ui_update_for_column = gr.update(children=dynamic_ui_components_list)
220
+
221
  except Exception as e:
222
  print(f"Error in load_refresh_per_speaker_ui called from model_controls_visibility: {e}")
223
  error_markdown = gr.Markdown(f"Error refreshing per-speaker UI: {e}")
224
+ dynamic_ui_update_for_column = gr.update(children=[error_markdown]) # Wrap error in update
225
  updated_state_dict = current_speaker_configs_for_refresh
226
 
227
  is_tts1_family = selected_model in ["tts-1", "tts-1-hd"]
 
230
  return (
231
  gr.update(visible=is_tts1_family, interactive=is_tts1_family),
232
  gr.update(visible=is_gpt_mini_tts, interactive=is_gpt_mini_tts),
233
+ dynamic_ui_update_for_column, # This is now explicitly gr.update(children=...)
234
  updated_state_dict
235
  )
236
 
237
 
238
  def update_speaker_config_method_visibility(method: str):
239
+ # ... (no change) ...
240
  is_single = (method == "Single Voice (Global)")
241
  is_detailed_per_speaker = (method == "Detailed Configuration (Per Speaker UI)")
242