Update demo.py
Browse files
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 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|