NeoPy commited on
Commit
f93e77c
·
verified ·
1 Parent(s): 69ca629

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +17 -3
demo.py CHANGED
@@ -140,9 +140,23 @@ with gr.Blocks(title="🔊", theme=gr.themes.Base(primary_hue="blue", neutral_hu
140
  model_choices, index_choices = change_choices()
141
 
142
  audio_paths = get_audio_paths('audios')
143
- default_audio = audio_paths[0] if audio_paths else ""
144
- default_model = model_choices[0] if model_choices else ""
145
- default_index = index_choices[0] if index_choices else ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  return (
148
  gr.update(choices=model_choices, value=default_model), # voice_model
 
140
  model_choices, index_choices = change_choices()
141
 
142
  audio_paths = get_audio_paths('audios')
143
+
144
+ # Helper to safely get the first item from list or dict
145
+ # Fixes KeyError: 0 when change_choices returns a dictionary
146
+ def safe_first(data):
147
+ if not data: return ""
148
+ if isinstance(data, dict):
149
+ # If it's a dict, Gradio uses values as the actual data/paths
150
+ return next(iter(data.values()))
151
+ try:
152
+ # Assume it's a list or sequence
153
+ return data[0]
154
+ except (IndexError, KeyError):
155
+ return ""
156
+
157
+ default_audio = safe_first(audio_paths)
158
+ default_model = safe_first(model_choices)
159
+ default_index = safe_first(index_choices)
160
 
161
  return (
162
  gr.update(choices=model_choices, value=default_model), # voice_model