Repository navigation
Refactor: Modularize EcoWatch AI into package structure - #1
Open
Super-cloud0 wants to merge 1 commit into
Open
Super-cloud0 wants to merge 1 commit into
Super-cloud0 wants to merge 1 commit into
Conversation
- Split the 870-line main.py into the ecowatch/ package: detector, tracker, monitor, sources, storage, notifier, recorder, overlay, ui, cli - Remove the hardcoded Telegram bot token; secrets now come from .env - Temporal smoothing (EMA) plus hysteresis turns frames into incidents with onset and end, escalating from smoke to fire within one incident - Monitoring runs in a background thread; the UI polls it from a Streamlit fragment, so switching tabs or reloading the page doesn't stop it - Live cameras use a latest-frame grabber that reconnects on drops - SQLite incident journal with snapshots and clips; the legacy JSON history is imported automatically - Telegram sending moved to a background queue with cooldown - Incident clips include pre-roll frames from before the alert - Headless CLI mode: python -m ecowatch <source> - Map shows real camera coordinates instead of random points - train.py: argparse, classify and detect modes, backs up the old model - Tests (pytest), ruff config and a GitHub Actions workflow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PKYmgFdxkcjGu11gXfcToj
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
This is a major refactoring that transforms EcoWatch AI from a monolithic 873-line Streamlit script into a well-organized Python package with clear separation of concerns. The application logic is now split into focused modules, enabling better testability, reusability, and maintainability.
Key Changes
Package Structure
ecowatch/package with modular components:config.py— Settings, detection parameters, environment loadingdetector.py— YOLO model wrapper (unified interface for classify/detect)hazards.py— Hazard catalog with metadata (icons, colors, severity)tracker.py— Temporal smoothing and hysteresis (frames → incidents)sources.py— Frame sources (webcam, RTSP, file, screen capture)storage.py— SQLite-based incident journal (replaces JSON)recorder.py— Video clip recording with pre-roll buffernotifier.py— Async Telegram notificationsoverlay.py— Frame annotation with Cyrillic supportmonitor.py— Background monitoring thread orchestrating the pipelineui.py— Streamlit web interface (extracted from main.py)cli.py— Console mode for headless operationEntry Points
main.py— Now a minimal entry point that imports and runs the UIecowatch/__main__.py— Enablespython -m ecowatchfor CLI moderun_app.bat— Updated Windows launcherTesting & Quality
tests/directory with unit tests for core modules:test_detector.py— YOLO result parsingtest_tracker.py— Decision logic and hysteresistest_storage.py— Incident persistencetest_notifier.py— Telegram formattingtest_recorder.py— Clip recording with pre-rolltest_config_sources.py— Configuration and source parsing.github/workflows/tests.ymlfor CIpyproject.tomlwith ruff linting configrequirements-dev.txtfor development dependenciesConfiguration & Deployment
.env.example— Template for secrets (token, chat ID, coordinates).streamlit/config.toml— Streamlit theme and server settings.gitignoreto exclude data, cache, and secretsrequirements.txtwith pinned versionsDocumentation
README.mdwith feature highlights, installation, and usage examplestrain.pywith clearer docstring and refactored dataset validationNotable Implementation Details
Migration Notes
detection_history.jsonis automatically imported intodata/incidents.dbon first run.envfile or environment variables (never hardcoded)python -m ecowatch 0) enables 24/7 headless operation on servershttps://claude.ai/code/session_01PKYmgFdxkcjGu11gXfcToj