feat: added filename to console output in cli

This commit is contained in:
Santiago Martinez 2023-05-01 17:51:18 +01:00
parent 2ddd2c022e
commit 327f741aa2
4 changed files with 18 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import click
from batdetect2 import api
from batdetect2.detector.parameters import DEFAULT_MODEL_PATH
from batdetect2.types import ProcessingConfiguration
from batdetect2.utils.detector_utils import save_results_to_file
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
@ -104,17 +105,23 @@ def detect(
**{
**params,
**args,
'time_expansion': time_expansion_factor,
"time_expansion": time_expansion_factor,
"spec_slices": False,
"chunk_size": 2,
"detection_threshold": detection_threshold,
}
)
if not args["quiet"]:
print_config(config)
# process files
error_files = []
for audio_file in files:
for index, audio_file in enumerate(files):
try:
if not args["quiet"]:
click.echo(f"\n{index} {audio_file}")
results = api.process_file(audio_file, model, config=config)
if args["save_preds_if_empty"] or (
@ -135,5 +142,12 @@ def detect(
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__":
cli()

View File

@ -731,7 +731,6 @@ def process_file(
spec_slices = []
# load audio file
print("time_exp_fact", config.get("time_expansion", 1) or 1)
sampling_rate, audio_full = au.load_audio(
audio_file,
time_exp_fact=config.get("time_expansion", 1) or 1,

2
pdm.lock generated
View File

@ -453,7 +453,7 @@ summary = "Backport of pathlib-compatible object wrapper for zip files"
[metadata]
lock_version = "4.1"
content_hash = "sha256:2401b930c14b3b7e107372f0103cccebff74691b6bcd54148d832ce847df5673"
content_hash = "sha256:667d4d2891fb85565cb04d84d0970eaac799bf272e3c4d7e4e6fea0b33c241fb"
[metadata.files]
"appdirs 1.4.4" = [

View File

@ -66,4 +66,4 @@ def test_cli_detect_command_with_non_trivial_time_expansion(tmp_path):
)
assert result.exit_code == 0
assert 'time_exp_fact 10' in result.stdout
assert 'Time Expansion Factor: 10' in result.stdout