From c7953dc4e0d0036b9cd78f768928a0749739a782 Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Tue, 8 Sep 2026 20:30:58 +0300 Subject: [PATCH] fix: don't crash the UI on output files with custom names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit create_text2music_ui() sorted the saved *_input_params.json files with int(name.split('_')[1]), which assumes the generated output___ shape. Output names are user-controlled — via infer.py --output_path or a save_path from the UI — so any other name raised ValueError while the Blocks were being built and took the whole interface down before it could start: ValueError: invalid literal for int() with base 10: 'base' Sort by mtime instead. That is what "previous generated input params" means anyway (newest first) and it works for any filename; a file that disappears between listdir() and getmtime() sorts last rather than raising. Co-Authored-By: Claude Opus 5 --- acestep/ui/components.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/acestep/ui/components.py b/acestep/ui/components.py index b85d841..aec2e4a 100644 --- a/acestep/ui/components.py +++ b/acestep/ui/components.py @@ -101,7 +101,17 @@ def create_text2music_ui( if not os.path.isdir(output_file_dir): os.makedirs(output_file_dir, exist_ok=True) json_files = [f for f in os.listdir(output_file_dir) if f.endswith('.json')] - json_files.sort(reverse=True, key=lambda x: int(x.split('_')[1])) + + def _mtime(name): + # Output filenames are user-controlled (infer.py --output_path, or the + # save_path passed from the UI), so a timestamp cannot be parsed out of + # them: doing so used to raise ValueError and take the whole UI down. + try: + return os.path.getmtime(os.path.join(output_file_dir, name)) + except OSError: + return 0.0 + + json_files.sort(key=_mtime, reverse=True) output_files = gr.Dropdown(choices=json_files, label="Select previous generated input params", scale=9, interactive=True) load_bnt = gr.Button("Load", variant="primary", scale=1)