mirror of
https://github.com/macaodha/batdetect2.git
synced 2025-06-29 22:51:58 +02:00
Merge pull request #8 from macaodha/feat/GH-7-filename-in-console-output
feat: added filename to console output in cli
This commit is contained in:
commit
69c087bc20
@ -5,6 +5,7 @@ import click
|
|||||||
|
|
||||||
from batdetect2 import api
|
from batdetect2 import api
|
||||||
from batdetect2.detector.parameters import DEFAULT_MODEL_PATH
|
from batdetect2.detector.parameters import DEFAULT_MODEL_PATH
|
||||||
|
from batdetect2.types import ProcessingConfiguration
|
||||||
from batdetect2.utils.detector_utils import save_results_to_file
|
from batdetect2.utils.detector_utils import save_results_to_file
|
||||||
|
|
||||||
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -104,17 +105,23 @@ def detect(
|
|||||||
**{
|
**{
|
||||||
**params,
|
**params,
|
||||||
**args,
|
**args,
|
||||||
'time_expansion': time_expansion_factor,
|
"time_expansion": time_expansion_factor,
|
||||||
"spec_slices": False,
|
"spec_slices": False,
|
||||||
"chunk_size": 2,
|
"chunk_size": 2,
|
||||||
"detection_threshold": detection_threshold,
|
"detection_threshold": detection_threshold,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not args["quiet"]:
|
||||||
|
print_config(config)
|
||||||
|
|
||||||
# process files
|
# process files
|
||||||
error_files = []
|
error_files = []
|
||||||
for audio_file in files:
|
for index, audio_file in enumerate(files):
|
||||||
try:
|
try:
|
||||||
|
if not args["quiet"]:
|
||||||
|
click.echo(f"\n{index} {audio_file}")
|
||||||
|
|
||||||
results = api.process_file(audio_file, model, config=config)
|
results = api.process_file(audio_file, model, config=config)
|
||||||
|
|
||||||
if args["save_preds_if_empty"] or (
|
if args["save_preds_if_empty"] or (
|
||||||
@ -135,5 +142,12 @@ def detect(
|
|||||||
click.echo(f" {err}")
|
click.echo(f" {err}")
|
||||||
|
|
||||||
|
|
||||||
|
def print_config(config: ProcessingConfiguration):
|
||||||
|
"""Print the processing configuration."""
|
||||||
|
click.echo("\nProcessing Configuration:")
|
||||||
|
click.echo(f"Time Expansion Factor: {config.get('time_expansion')}")
|
||||||
|
click.echo(f"Detection Threshold: {config.get('detection_threshold')}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli()
|
||||||
|
@ -731,7 +731,6 @@ def process_file(
|
|||||||
spec_slices = []
|
spec_slices = []
|
||||||
|
|
||||||
# load audio file
|
# load audio file
|
||||||
print("time_exp_fact", config.get("time_expansion", 1) or 1)
|
|
||||||
sampling_rate, audio_full = au.load_audio(
|
sampling_rate, audio_full = au.load_audio(
|
||||||
audio_file,
|
audio_file,
|
||||||
time_exp_fact=config.get("time_expansion", 1) or 1,
|
time_exp_fact=config.get("time_expansion", 1) or 1,
|
||||||
|
2
pdm.lock
generated
2
pdm.lock
generated
@ -453,7 +453,7 @@ summary = "Backport of pathlib-compatible object wrapper for zip files"
|
|||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
lock_version = "4.1"
|
lock_version = "4.1"
|
||||||
content_hash = "sha256:2401b930c14b3b7e107372f0103cccebff74691b6bcd54148d832ce847df5673"
|
content_hash = "sha256:667d4d2891fb85565cb04d84d0970eaac799bf272e3c4d7e4e6fea0b33c241fb"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
"appdirs 1.4.4" = [
|
"appdirs 1.4.4" = [
|
||||||
|
@ -66,4 +66,4 @@ def test_cli_detect_command_with_non_trivial_time_expansion(tmp_path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert 'time_exp_fact 10' in result.stdout
|
assert 'Time Expansion Factor: 10' in result.stdout
|
||||||
|
Loading…
Reference in New Issue
Block a user