Skip to content

Commit

Permalink
fixed matrix overflow issue + limit number of files searched for batc…
Browse files Browse the repository at this point in the history
…h analysis file matrix (#399)

Co-authored-by: Josef Haupt <josef.haupt@phil.tu-chemnitz.de>
  • Loading branch information
Josef-Haupt and Josef Haupt authored Aug 6, 2024
1 parent 6b8fc6b commit 5345886
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
18 changes: 9 additions & 9 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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"))
Expand All @@ -1028,15 +1028,15 @@ 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"),
],
)

def select_directory_on_empty():
res = select_directory()
res = select_directory(max_files=101)

if res[1]:
if len(res[1]) > 100:
Expand All @@ -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():
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions gui/gui.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)


Expand Down

0 comments on commit 5345886

Please sign in to comment.