diff --git a/gui.py b/gui.py index b5f6775c..e65f2625 100644 --- a/gui.py +++ b/gui.py @@ -506,7 +506,7 @@ def format_seconds(secs: float): return f"{hours:2.0f}:{minutes:02.0f}:{secs:06.3f}" -def select_directory(collect_files=True): +def select_directory(collect_files=True, max_files=None): """Shows a directory selection system dialog. Uses the pywebview to create a system dialog. @@ -525,7 +525,7 @@ def select_directory(collect_files=True): if not dir_name: return None, None - files = utils.collect_audio_files(dir_name[0]) + files = utils.collect_audio_files(dir_name[0], max_files=max_files) return dir_name[0], [ [os.path.relpath(file, dir_name[0]), format_seconds(librosa.get_duration(filename=file))] for file in files @@ -1011,7 +1011,7 @@ def get_audio_path(i): loc.localize("single-tab-output-header-common-name"), loc.localize("single-tab-output-header-confidence"), ], - elem_classes="mh-200", + elem_classes="matrix-mh-200", ) single_file_analyze = gr.Button(loc.localize("analyze-start-button-label")) @@ -1028,7 +1028,7 @@ def build_multi_analysis_tab(): select_directory_btn = gr.Button(loc.localize("multi-tab-input-selection-button-label")) directory_input = gr.Matrix( interactive=False, - elem_classes="mh-200", + elem_classes="matrix-mh-200", headers=[ loc.localize("multi-tab-samples-dataframe-column-subpath-header"), loc.localize("multi-tab-samples-dataframe-column-duration-header"), @@ -1036,7 +1036,7 @@ def build_multi_analysis_tab(): ) def select_directory_on_empty(): - res = select_directory() + res = select_directory(max_files=101) if res[1]: if len(res[1]) > 100: @@ -1047,7 +1047,7 @@ def select_directory_on_empty(): return [res[0], [[loc.localize("multi-tab-samples-dataframe-no-files-found")]]] select_directory_btn.click( - select_directory_on_empty, outputs=[input_directory_state, directory_input], show_progress=False + select_directory_on_empty, outputs=[input_directory_state, directory_input], show_progress=True ) with gr.Column(): @@ -1156,7 +1156,7 @@ def on_combine_tables_change(value): loc.localize("multi-tab-result-dataframe-column-file-header"), loc.localize("multi-tab-result-dataframe-column-execution-header"), ], - elem_classes="mh-200", + elem_classes="matrix-mh-200", ) inputs = [ @@ -1197,7 +1197,7 @@ def build_train_tab(): directory_input = gr.List( headers=[loc.localize("training-tab-classes-dataframe-column-classes-header")], interactive=False, - elem_classes="mh-200", + elem_classes="matrix-mh-200", ) select_directory_btn.click( select_subdirectories, outputs=[input_directory_state, directory_input], show_progress=False @@ -1554,7 +1554,7 @@ def select_directory_to_state_and_tb(): loc.localize("segments-tab-result-dataframe-column-file-header"), loc.localize("segments-tab-result-dataframe-column-execution-header"), ], - elem_classes="mh-200", + elem_classes="matrix-mh-200", ) extract_segments_btn.click( diff --git a/gui/gui.css b/gui/gui.css index 62354269..d906dba9 100644 --- a/gui/gui.css +++ b/gui/gui.css @@ -2,6 +2,15 @@ display: block !important; } +.matrix-mh-200, .matrix-mh-200 table { + max-height: 300px; + overflow-y: auto !important; +} + +.matrix-mh-200 .table-wrap { + max-height: 300px; +} + .mh-200 { max-height: 300px; overflow-y: auto !important; diff --git a/utils.py b/utils.py index a771ea08..b5c834bf 100644 --- a/utils.py +++ b/utils.py @@ -33,7 +33,7 @@ def spectrogram_from_file(path, fig_num=None): return librosa.display.specshow(S_db, ax=ax, n_fft=1024, hop_length=512).figure -def collect_audio_files(path: str): +def collect_audio_files(path: str, max_files: int = None): """Collects all audio files in the given directory. Args: @@ -50,6 +50,9 @@ def collect_audio_files(path: str): if not f.startswith(".") and f.rsplit(".", 1)[-1].lower() in cfg.ALLOWED_FILETYPES: files.append(os.path.join(root, f)) + if max_files and len(files) >= max_files: + return sorted(files) + return sorted(files)