abocha commited on
Commit
186ebe6
·
1 Parent(s): 7b60030
Files changed (1) hide show
  1. event_handlers.py +11 -15
event_handlers.py CHANGED
@@ -32,7 +32,6 @@ def get_speakers_from_script(script_text: str):
32
  except ValueError:
33
  return []
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:
@@ -45,20 +44,15 @@ def handle_dynamic_input_change(new_value, current_configs_state_dict: dict, spe
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) ---
56
- # print(f"Load/Refresh UI called. TTS Model: {tts_model}")
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
 
@@ -72,6 +66,7 @@ async def handle_script_processing(
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():
@@ -211,17 +206,18 @@ def update_model_controls_visibility(selected_model: str, script_text_for_refres
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,7 +226,7 @@ def update_model_controls_visibility(selected_model: str, script_text_for_refres
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
 
 
32
  except ValueError:
33
  return []
34
 
 
35
  def handle_dynamic_input_change(new_value, current_configs_state_dict: dict, speaker_name: str, config_key: str, tts_model: str):
36
  # ... (no change) ...
37
  if current_configs_state_dict is None:
 
44
 
45
 
46
  def load_refresh_per_speaker_ui(script_text: str, current_configs_state_dict: dict, tts_model: str, speaker_configs_state_component: gr.State):
47
+ # --- START OF PHASE 1 DEBUGGING (returns list of components directly) ---
48
+ print("DEBUG: load_refresh_per_speaker_ui CALLED - Phase 1: HARDCODED RETURN (direct list for Column)")
49
+ debug_markdown = gr.Markdown("## !! Dynamic Area Test Content Loaded (Direct list for Column) !!")
50
  # Return the list of components and the state update
51
  return [debug_markdown], {}
52
  # --- END OF PHASE 1 DEBUGGING ---
53
 
54
  # --- ORIGINAL LOGIC (Commented out for Phase 1) ---
55
+ # ... (original logic would eventually return: new_ui_components, current_configs_state_dict)
 
 
 
 
 
56
  # --- END OF ORIGINAL LOGIC ---
57
 
58
 
 
66
  global_instructions: str,
67
  progress=gr.Progress(track_tqdm=True)
68
  ):
69
+ # ... (content of this function remains unchanged from the previous correct version) ...
70
  if not openai_api_key or not async_openai_client:
71
  return None, None, "Error: OpenAI API Key or client is not configured."
72
  if not dialogue_script.strip():
 
206
  """Updates visibility of global controls and refreshes per-speaker UI when TTS model changes."""
207
  print(f"Model changed to: {selected_model}. Refreshing dynamic UI and controls.")
208
  try:
209
+ # load_refresh_per_speaker_ui returns (list_of_components, updated_state_dict)
210
  dynamic_ui_components_list, updated_state_dict = load_refresh_per_speaker_ui(
211
  script_text_for_refresh, current_speaker_configs_for_refresh, selected_model, speaker_configs_state_comp
212
  )
213
+ # The list of components is passed directly for the Column output.
214
+ # Gradio should handle replacing children of 'dynamic_speaker_ui_area' (a gr.Column)
215
+ # with this new list of components.
216
 
217
  except Exception as e:
218
  print(f"Error in load_refresh_per_speaker_ui called from model_controls_visibility: {e}")
219
  error_markdown = gr.Markdown(f"Error refreshing per-speaker UI: {e}")
220
+ dynamic_ui_components_list = [error_markdown] # Fallback to an error message list
221
  updated_state_dict = current_speaker_configs_for_refresh
222
 
223
  is_tts1_family = selected_model in ["tts-1", "tts-1-hd"]
 
226
  return (
227
  gr.update(visible=is_tts1_family, interactive=is_tts1_family),
228
  gr.update(visible=is_gpt_mini_tts, interactive=is_gpt_mini_tts),
229
+ dynamic_ui_components_list, # Pass the list of components directly
230
  updated_state_dict
231
  )
232