Spaces:
Running on Zero
Running on Zero
Kuangwei Chen commited on
Commit ·
0b476f3
1
Parent(s): d76bd4f
Fix demo dropdown state and ZeroGPU duration args
Browse files
app.py
CHANGED
|
@@ -113,6 +113,7 @@ DEFAULT_VOICE_VALUE = (
|
|
| 113 |
DEMO_ENTRIES = load_demo_entries()
|
| 114 |
DEMO_ENTRY_MAP = {entry.demo_id: entry for entry in DEMO_ENTRIES}
|
| 115 |
DEMO_AUDIO_PATH_MAP = {str(entry.prompt_audio_path): entry for entry in DEMO_ENTRIES}
|
|
|
|
| 116 |
VOICE_FILE_TO_NAME = {
|
| 117 |
preset.prompt_audio_path.name: preset.name
|
| 118 |
for preset in _VOICE_PRESETS.values()
|
|
@@ -146,6 +147,18 @@ def maybe_delete_file(path: str | Path | None) -> None:
|
|
| 146 |
logging.warning("failed to delete temporary file: %s", path, exc_info=True)
|
| 147 |
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
@functools.lru_cache(maxsize=2)
|
| 150 |
def get_tts_service(runtime_has_cuda: bool) -> NanoTTSService:
|
| 151 |
return NanoTTSService(
|
|
@@ -249,6 +262,7 @@ def apply_demo_case_selection(
|
|
| 249 |
voice: str,
|
| 250 |
prompt_audio_path: str | None,
|
| 251 |
):
|
|
|
|
| 252 |
if not demo_case_id:
|
| 253 |
preview_path, prompt_source = refresh_prompt_preview(voice, prompt_audio_path, "")
|
| 254 |
return (
|
|
@@ -323,23 +337,14 @@ def build_status_text(
|
|
| 323 |
|
| 324 |
|
| 325 |
def estimate_gpu_duration(
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
prompt_audio_path: str | None,
|
| 329 |
-
max_new_frames: int,
|
| 330 |
-
voice_clone_max_text_tokens: int,
|
| 331 |
-
do_sample: bool,
|
| 332 |
-
text_temperature: float,
|
| 333 |
-
text_top_p: float,
|
| 334 |
-
text_top_k: int,
|
| 335 |
-
audio_temperature: float,
|
| 336 |
-
audio_top_p: float,
|
| 337 |
-
audio_top_k: int,
|
| 338 |
-
audio_repetition_penalty: float,
|
| 339 |
-
seed: float | int,
|
| 340 |
) -> int:
|
| 341 |
-
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
| 343 |
text_len = len(str(text or "").strip())
|
| 344 |
estimated = 75 + (text_len // 12) + int(max_new_frames) // 8 + int(voice_clone_max_text_tokens) // 10
|
| 345 |
return max(90, min(240, estimated))
|
|
@@ -454,6 +459,7 @@ def build_demo():
|
|
| 454 |
value="",
|
| 455 |
label="Default Case",
|
| 456 |
info="Select a built-in case to auto-fill the text and prompt preview.",
|
|
|
|
| 457 |
)
|
| 458 |
text = gr.Textbox(
|
| 459 |
label="Target Text",
|
|
|
|
| 113 |
DEMO_ENTRIES = load_demo_entries()
|
| 114 |
DEMO_ENTRY_MAP = {entry.demo_id: entry for entry in DEMO_ENTRIES}
|
| 115 |
DEMO_AUDIO_PATH_MAP = {str(entry.prompt_audio_path): entry for entry in DEMO_ENTRIES}
|
| 116 |
+
DEMO_ENTRY_NAME_MAP = {entry.name: entry for entry in DEMO_ENTRIES}
|
| 117 |
VOICE_FILE_TO_NAME = {
|
| 118 |
preset.prompt_audio_path.name: preset.name
|
| 119 |
for preset in _VOICE_PRESETS.values()
|
|
|
|
| 147 |
logging.warning("failed to delete temporary file: %s", path, exc_info=True)
|
| 148 |
|
| 149 |
|
| 150 |
+
def normalize_demo_case_id(demo_case_id: str | None) -> str:
|
| 151 |
+
normalized = str(demo_case_id or "").strip()
|
| 152 |
+
if not normalized:
|
| 153 |
+
return ""
|
| 154 |
+
if normalized in DEMO_ENTRY_MAP:
|
| 155 |
+
return normalized
|
| 156 |
+
matched_entry = DEMO_ENTRY_NAME_MAP.get(normalized)
|
| 157 |
+
if matched_entry is not None:
|
| 158 |
+
return matched_entry.demo_id
|
| 159 |
+
return ""
|
| 160 |
+
|
| 161 |
+
|
| 162 |
@functools.lru_cache(maxsize=2)
|
| 163 |
def get_tts_service(runtime_has_cuda: bool) -> NanoTTSService:
|
| 164 |
return NanoTTSService(
|
|
|
|
| 262 |
voice: str,
|
| 263 |
prompt_audio_path: str | None,
|
| 264 |
):
|
| 265 |
+
demo_case_id = normalize_demo_case_id(demo_case_id)
|
| 266 |
if not demo_case_id:
|
| 267 |
preview_path, prompt_source = refresh_prompt_preview(voice, prompt_audio_path, "")
|
| 268 |
return (
|
|
|
|
| 337 |
|
| 338 |
|
| 339 |
def estimate_gpu_duration(
|
| 340 |
+
*args,
|
| 341 |
+
**kwargs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
) -> int:
|
| 343 |
+
text = kwargs.get("text", args[0] if len(args) > 0 else "")
|
| 344 |
+
max_new_frames = kwargs.get("max_new_frames", args[6] if len(args) > 6 else 375)
|
| 345 |
+
voice_clone_max_text_tokens = (
|
| 346 |
+
kwargs.get("voice_clone_max_text_tokens", args[7] if len(args) > 7 else 75)
|
| 347 |
+
)
|
| 348 |
text_len = len(str(text or "").strip())
|
| 349 |
estimated = 75 + (text_len // 12) + int(max_new_frames) // 8 + int(voice_clone_max_text_tokens) // 10
|
| 350 |
return max(90, min(240, estimated))
|
|
|
|
| 459 |
value="",
|
| 460 |
label="Default Case",
|
| 461 |
info="Select a built-in case to auto-fill the text and prompt preview.",
|
| 462 |
+
allow_custom_value=True,
|
| 463 |
)
|
| 464 |
text = gr.Textbox(
|
| 465 |
label="Target Text",
|