Skip to content

Commit

Permalink
added some validation to the gui and fixed folder selection issues fo…
Browse files Browse the repository at this point in the history
…r training cache (#491)
  • Loading branch information
max-mauermann authored Oct 30, 2024
1 parent 505fe19 commit bac36f6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions birdnet_analyzer/gui/multi_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import birdnet_analyzer.localization as loc
import birdnet_analyzer.gui.utils as gu
import birdnet_analyzer.gui.analysis as ga
import birdnet_analyzer.config as cfg


OUTPUT_TYPE_MAP = {
Expand Down Expand Up @@ -44,6 +45,9 @@ def runBatchAnalysis(

if species_list_choice == gu._CUSTOM_SPECIES:
gu.validate(species_list_file, loc.localize("validation-no-species-list-selected"))

if fmin is None or fmax is None or fmin < cfg.SIG_FMIN or fmax > cfg.SIG_FMAX or fmin > fmax:
raise gr.Error(f"{loc.localize('validation-no-valid-frequency')} [{cfg.SIG_FMIN}, {cfg.SIG_FMAX}]")

return ga.runAnalysis(
None,
Expand Down
7 changes: 7 additions & 0 deletions birdnet_analyzer/gui/single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import birdnet_analyzer.localization as loc
import birdnet_analyzer.gui.utils as gu
import birdnet_analyzer.gui.analysis as ga
import birdnet_analyzer.config as cfg


def runSingleFileAnalysis(
Expand All @@ -27,7 +28,13 @@ def runSingleFileAnalysis(
import csv
from datetime import timedelta

if species_list_choice == gu._CUSTOM_SPECIES:
gu.validate(species_list_file, loc.localize("validation-no-species-list-selected"))

gu.validate(input_path, loc.localize("validation-no-file-selected"))

if fmin is None or fmax is None or fmin < cfg.SIG_FMIN or fmax > cfg.SIG_FMAX or fmin > fmax:
raise gr.Error(f"{loc.localize('validation-no-valid-frequency')} [{cfg.SIG_FMIN}, {cfg.SIG_FMAX}]")

result_filepath = ga.runAnalysis(
input_path,
Expand Down
2 changes: 1 addition & 1 deletion birdnet_analyzer/gui/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def select_directory_and_update_tb(name_tb):
loc.set_state("species-output-dir", dir_name)
return (
dir_name,
gr.Textbox(label=dir_name[0] + os.sep, visible=True, value=name_tb),
gr.Textbox(label=dir_name, visible=True, value=name_tb),
)

return None, name_tb
Expand Down
6 changes: 3 additions & 3 deletions birdnet_analyzer/gui/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def select_directory_and_update_tb():
if dir_name:
return (
dir_name,
gr.Textbox(label=dir_name + os.sep, visible=True),
gr.Textbox(label=dir_name, visible=True),
gr.Radio(visible=True, interactive=True),
)

Expand Down Expand Up @@ -401,8 +401,8 @@ def select_directory_and_update():

if dir_name:
return (
dir_name[0],
gr.Textbox(label=dir_name[0] + "\\", visible=True),
dir_name,
gr.Textbox(label=dir_name, visible=True),
)

return None, None
Expand Down

0 comments on commit bac36f6

Please sign in to comment.