Spaces:
Runtime error
Runtime error
Refactor voice selection logic to use updated model initialization in version change handler
Browse files
app.py
CHANGED
|
@@ -37,8 +37,12 @@ def initialize_model(version="v1.0.0"):
|
|
| 37 |
if not voices:
|
| 38 |
raise gr.Error("No voices found. Please check the voices directory.")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
default_voice = 'af_sky' if 'af_sky' in voices else voices[0] if voices else None
|
| 41 |
-
|
| 42 |
return gr.update(choices=voices, value=default_voice)
|
| 43 |
except Exception as e:
|
| 44 |
raise gr.Error(f"Failed to initialize model: {str(e)}")
|
|
@@ -425,10 +429,12 @@ with gr.Blocks(title="Kokoro TTS Demo", css=styling) as demo:
|
|
| 425 |
|
| 426 |
def on_version_change(version):
|
| 427 |
voices = initialize_model(version)
|
| 428 |
-
#
|
| 429 |
if version == "v1.0.0":
|
| 430 |
return gr.update(choices=voices.choices, value=voices.value, multiselect=False)
|
| 431 |
-
|
|
|
|
|
|
|
| 432 |
|
| 433 |
version_dropdown.change(
|
| 434 |
fn=on_version_change,
|
|
|
|
| 37 |
if not voices:
|
| 38 |
raise gr.Error("No voices found. Please check the voices directory.")
|
| 39 |
|
| 40 |
+
# For v0.19, return raw list of voices
|
| 41 |
+
if version == "v0.19":
|
| 42 |
+
return voices
|
| 43 |
+
|
| 44 |
+
# For v1.0.0, return gr.update object
|
| 45 |
default_voice = 'af_sky' if 'af_sky' in voices else voices[0] if voices else None
|
|
|
|
| 46 |
return gr.update(choices=voices, value=default_voice)
|
| 47 |
except Exception as e:
|
| 48 |
raise gr.Error(f"Failed to initialize model: {str(e)}")
|
|
|
|
| 429 |
|
| 430 |
def on_version_change(version):
|
| 431 |
voices = initialize_model(version)
|
| 432 |
+
# For v1.0.0, voices is already a gr.update() object
|
| 433 |
if version == "v1.0.0":
|
| 434 |
return gr.update(choices=voices.choices, value=voices.value, multiselect=False)
|
| 435 |
+
# For v0.19, voices is a list of voice names
|
| 436 |
+
default_voice = 'af_sky' if 'af_sky' in voices else voices[0] if voices else None
|
| 437 |
+
return gr.update(choices=voices, value=default_voice, multiselect=True)
|
| 438 |
|
| 439 |
version_dropdown.change(
|
| 440 |
fn=on_version_change,
|