Keep heavy imports off the GUI startup path - #981
Open
Josef-Haupt wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates BirdNET-Analyzer’s handling of “sensitivity” to reflect BirdNET 3.0 behavior (sigmoid applied inside the model), ensuring analyses and the GUI don’t crash or misrepresent an unused setting, while also guarding GUI startup against heavy imports.
Changes:
- Add
supports_sensitivity()/effective_sensitivity()and apply coercion tosigmoid_sensitivityin inference and analysis orchestration. - Disable/reset the GUI sensitivity slider when the selected model doesn’t support it; defer some imports to keep GUI startup light.
- Add tests and documentation covering sensitivity behavior and GUI startup/import constraints.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_model_utils.py | Adds unit tests for sensitivity support logic and inference coercion for BirdNET 3.0. |
| tests/gui/test_startup_imports.py | New test to prevent heavy modules from being imported during GUI tab import/build. |
| tests/gui/test_settings.py | Adds coverage for stdout/stderr diversion behavior in frozen builds. |
| docs/breaking-changes.rst | Documents that sensitivity is ignored for BirdNET 3.0 and how to tune detections instead. |
| birdnet_analyzer/settings.py | Refactors frozen stdout/stderr diversion decision into _divert_output_to_log(). |
| birdnet_analyzer/model_utils.py | Introduces sensitivity support/coercion helpers and applies them before inference session creation. |
| birdnet_analyzer/gui/utils.py | Disables/enables sensitivity slider based on selected model and avoids initial map-plot creation. |
| birdnet_analyzer/gui/search.py | Moves heavyweight imports into inner functions to reduce tab build/import cost. |
| birdnet_analyzer/cli.py | Updates --sensitivity help text and fixes a typo. |
| birdnet_analyzer/analyze/core.py | Ensures recorded/serialized analysis params reflect the effective sensitivity actually used. |
| AGENTS.md | Adds contributor guidance about GUI state dependencies (build time, user edits, programmatic updates). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+87
to
+89
| assert result.returncode == 0, result.stderr | ||
| loaded = json.loads(result.stdout.splitlines()[-1]) | ||
|
|
The search tab imported birdnet_analyzer.audio (scipy.signal, librosa) while building, and every species-list coordinates block rendered a plotly map figure that open_window's demo.load regenerates on page load anyway. Both now happen lazily; GUI startup to server-up drops from ~6.2 s to ~4.5 s. A test imports all tab modules and builds the full Blocks in a subprocess, asserting tensorflow, scipy, librosa, plotly and sklearn stay unloaded. AGENTS.md: two conventions - the three ways a persisted GUI control gets its value (build, user, preset/params load) and the code-comment rule. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The webview import moves from module level into the dialog functions and open_window, and the _WINDOW annotation becomes a string under TYPE_CHECKING. CI's gui-tests extra has no pywebview, so tests that reach gui.utils had to stub sys.modules["webview"] first; those stubs are removed so CI exercises the guarantee. AGENTS.md updated: no plotly in that environment either. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Josef-Haupt
force-pushed
the
startup-time
branch
from
August 17, 2026 19:04
a44b00a to
a57a399
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
birdnet_analyzer.audio(scipy.signal, librosa) while building, and every species-list coordinates block rendered a plotly map figure thatopen_window'sdemo.loadregenerates on page load anyway. Both are now lazy. GUI startup to server-up drops from ~6.2 s to ~4.5 s locally.tests/gui/test_startup_imports.pyimports all tab modules and builds the full Blocks in a subprocess, asserting tensorflow, scipy, librosa, plotly and sklearn stay unloaded.gui.utilsimportable without pywebview: thewebviewimport moves into the dialog functions andopen_window; the_WINDOWannotation is a string underTYPE_CHECKING. Thesys.modules["webview"]stubs in the tests are removed so CI exercises this. (Raised by Copilot on Download progress #984; deferred there as out of scope.)Verification
tests/guipass withwebviewandplotlymade unimportable (CI'sgui-testscondition), no stubs.This PR was originally the combined "General cleanup" draft; the frozen-CLI, sensitivity and download-progress parts landed separately as #982, #983 and #984.
🤖 Generated with Claude Code