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)