Skip to content

Commit b5561be

Browse files
initial commit 💥 🍀 🌴
1 parent 7feb662 commit b5561be

37 files changed

+5892
-0
lines changed

.gitignore

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Virtual environment
7+
venv/
8+
ENV/
9+
10+
# OS generated files
11+
.DS_Store
12+
.DS_Store?
13+
._*
14+
.Spotlight-V100
15+
.Trashes
16+
ehthumbs.db
17+
Thumbs.db
18+
19+
# Editor directories and files
20+
.vscode/
21+
.idea/
22+
*.sw[lmnopqrst]
23+
*~
24+
.project
25+
.settings/
26+
27+
# Python cache and temporary files
28+
*.py[cod]
29+
*.pyc
30+
*.pyo
31+
*.pyd
32+
.Python
33+
build/
34+
develop-eggs/
35+
dist/
36+
downloads/
37+
eggs/
38+
.eggs/
39+
lib/
40+
lib64/
41+
parts/
42+
sdist/
43+
var/
44+
wheels/
45+
pip-wheel-metadata/
46+
share/python-wheels/
47+
*.egg-info/
48+
.installed.cfg
49+
*.egg
50+
MANIFEST
51+
52+
# Distribution / packaging
53+
.Python
54+
env/
55+
build/
56+
develop-eggs/
57+
dist/
58+
downloads/
59+
eggs/
60+
.eggs/
61+
lib/
62+
lib64/
63+
parts/
64+
sdist/
65+
var/
66+
wheels/
67+
pip-wheel-metadata/
68+
share/python-wheels/
69+
*.egg-info/
70+
.installed.cfg
71+
*.egg
72+
MANIFEST
73+
*.manifest
74+
*.spec
75+
76+
# PyInstaller
77+
# Usually these files are written by a python script from a template
78+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
79+
*.manifest
80+
*.spec
81+
82+
# Installer logs
83+
pip-log.txt
84+
pip-delete-this-directory.txt
85+
86+
# Unit test / coverage reports
87+
htmlcov/
88+
.tox/
89+
.nox/
90+
.coverage
91+
.coverage.*
92+
.cache
93+
nosetests.xml
94+
coverage.xml
95+
*.cover
96+
.hypothesis/
97+
.pytest_cache/
98+
.coverage
99+
instance/
100+
.webassets-cache
101+
102+
# Flask stuff:
103+
instance/
104+
.web
105+
templates.json
106+
screenshots/
107+
data/
108+
glimpser.log
109+
.idea
110+
auth.py
111+
*.old
112+
*.tmp
113+
logs/*
114+
scratch/*
115+
*.tsv

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.8-slim
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Copy the current directory contents into the container at /app
8+
COPY . /app
9+
10+
# Install any needed packages specified in requirements.txt
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# Make port 5000 available to the world outside this container
14+
EXPOSE 5000
15+
16+
# Define environment variable
17+
ENV FLASK_APP=main.py
18+
ENV FLASK_RUN_HOST=0.0.0.0
19+
20+
# Run app.py when the container launches
21+
CMD ["flask", "run"]
22+

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Kristopher Kubicki
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Glimpser
2+
3+
## Introduction
4+
Glimpser is a straightforward yet powerful real-time monitoring application designed to capture, analyze, and summarize live data from various sources such as cameras, dashboards, and video streams. Utilizing advanced image processing techniques and AI models, Glimpser provides insightful summaries and alerts. It’s highly configurable, allowing users to tailor it to their specific monitoring needs through an easy-to-use interface.
5+
6+
![Peek2024-08-0721-25-ezgif com-optimize](https://github.com/user-attachments/assets/d0335f5a-7d80-4895-b3fd-a94ad0af276c)
7+
8+
9+
## Features
10+
- **Real-time Monitoring**: Continuously captures data from multiple sources. Whether it's a traffic camera or a weather dashboard, Glimpser ensures you’re always up-to-date with the latest information.
11+
12+
- **Image Processing**: Employs advanced techniques to compare images and detect even subtle changes, making it ideal for monitoring evolving situations effectively.
13+
14+
- **Motion Detection**: Automatically detects motion in the captured images and videos, triggering alerts and actions as configured by the user.
15+
16+
- **AI Integration**: Integrates with models like LLaVA and ChatGPT to provide intelligent insights. It can summarize data, detect anomalies, and generate alerts based on predefined rules.
17+
18+
- **Auto-captioning**: Automatically generates concise and informative captions for images and videos, providing quick insights into the content.
19+
20+
- **Auto-summarization**: Summarizes data from multiple sources into a coherent and concise format, highlighting the most important information.
21+
22+
- **Customizable Configuration**: Easily configure different data sources and processing rules through the user-friendly interface. Glimpser’s configuration is fully database-driven, ensuring flexibility and ease of use.
23+
24+
- **Data Retention Policies**: Automatically manages storage by cleaning up old data, ensuring the system remains efficient without requiring constant manual intervention.
25+
26+
- **Web Interface**: A user-friendly web interface allows for easy monitoring and configuration. Users can view live feeds, summaries, and configure settings without delving into the code.
27+
28+
## Installation
29+
30+
### Prerequisites
31+
- Python 3.8 or higher
32+
33+
### Steps
34+
1. **Clone the Repository**
35+
```sh
36+
git clone https://github.com/yourusername/glimpser.git
37+
cd glimpser
38+
```
39+
40+
2. **Install Dependencies**
41+
```sh
42+
pip install -r requirements.txt
43+
```
44+
45+
3. **Run the Application**
46+
```sh
47+
python3 main.py
48+
```
49+
50+
You will be prompted to create a secret key to initialize the local sqlite database. Follow the rest of the guided setup and then direct your browser to http://127.0.0.1:8082 to finish the rest of the setup.
51+
52+
## Usage
53+
54+
### Configuration
55+
Glimpser uses a database-driven configuration to manage data sources and processing rules. Users can easily add, update, or remove configurations through the web interface.
56+
57+
### Capturing Screenshots
58+
The preferred method for capturing screenshots is through the Glimpser web interface. Simply navigate to the capture section, select your desired source, and click the capture button. This ensures a seamless and user-friendly experience.
59+
60+
### Running Tests
61+
To ensure everything works as expected, you can run the included unit tests:
62+
```sh
63+
python -m unittest discover tests
64+
```
65+
66+
### Motion Detection
67+
Glimpser automatically detects motion in the captured images and videos. When motion is detected, the system can trigger alerts, capture additional data, and generate relevant summaries and captions.
68+
69+
### Auto-captioning
70+
Using advanced AI models, Glimpser generates concise and informative captions for images and videos. This feature helps users quickly understand the content and context of the captured data.
71+
72+
### Auto-summarization
73+
Glimpser can summarize data from multiple sources into a coherent and concise format. The summaries highlight the most important information, making it easier for users to stay informed.
74+
75+
## Contributing
76+
Contributions are always welcome. If you have an idea to improve Glimpser, feel free to fork the repository and submit a pull request.
77+
78+
### Steps to Contribute
79+
1. Fork the repository.
80+
2. Create a feature branch.
81+
```sh
82+
git checkout -b feature-branch
83+
```
84+
3. Commit your changes.
85+
```sh
86+
git commit -m "Description of changes"
87+
```
88+
4. Push to the branch.
89+
```sh
90+
git push origin feature-branch
91+
```
92+
5. Open a pull request.
93+
94+
## License
95+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
96+
97+
## Acknowledgements
98+
We are grateful to the contributors and the open-source community. Special thanks to OpenAI for their powerful models that enable Glimpser's advanced features.

app/__init__.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# app/__init__.py
2+
3+
import logging
4+
import os
5+
6+
from flask import Flask, current_app
7+
from flask_apscheduler import APScheduler
8+
9+
from config import DevelopmentConfig, SCREENSHOT_DIRECTORY, VIDEO_DIRECTORY, SECRET_KEY
10+
from .utils.video_archiver import archive_screenshots, compile_to_teaser
11+
from .utils.video_compressor import compress_and_cleanup
12+
from .utils.retention_policy import retention_cleanup
13+
from .utils.scheduling import scheduler, schedule_crawlers, schedule_summarization
14+
15+
# needed for the llava compare
16+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
17+
18+
def create_app():
19+
app = Flask(__name__)
20+
app.config.from_object(DevelopmentConfig)
21+
app.secret_key = SECRET_KEY
22+
23+
# Ensure the screenshot directory exists
24+
os.makedirs(SCREENSHOT_DIRECTORY, exist_ok=True)
25+
os.makedirs(VIDEO_DIRECTORY, exist_ok=True)
26+
27+
from .routes import init_routes
28+
init_routes(app)
29+
30+
# Set the executor configuration in the Flask app's config
31+
# should be at least as many sources
32+
#app.config['SCHEDULER_EXECUTORS'] = {
33+
# 'default': {'type': 'threadpool', 'max_workers': 100} # Increase the number of threads here
34+
#}
35+
36+
app.config['SCHEDULER_EXECUTORS'] = {
37+
'default': {'type': 'processpool', 'max_workers': 8} # todo: read this from a config. by default, each thread is 6gb. So don't do more than what the machine can hande
38+
# allow to be configurable by the database
39+
}
40+
41+
scheduler.init_app(app)
42+
43+
# Scheduler setup
44+
if os.environ.get('WERKZEUG_RUN_MAIN') == 'true' or not app.debug:
45+
scheduler.start()
46+
logging.info('initializing...')
47+
48+
# Schedule the crawlers upon app start
49+
with app.app_context():
50+
51+
# remove existing schedules, particularly if the app reloads (which it does in debug mode)
52+
scheduler.remove_all_jobs()
53+
54+
schedule_crawlers()
55+
# Additional scheduler setup for video archiving
56+
scheduler.add_job(id='compile_to_teaser', func=compile_to_teaser, trigger='interval', minutes=3)
57+
scheduler.add_job(id='archive_screenshots', func=archive_screenshots, trigger='interval', minutes=1)
58+
#scheduler.add_job(id='compress_and_cleanup', func=compress_and_cleanup, trigger='interval', hours=1)
59+
scheduler.add_job(id='retention_cleanup', func=retention_cleanup, trigger='cron', day='*')
60+
schedule_summarization()
61+
62+
# one time cleanup..
63+
retention_cleanup()
64+
logging.info('initialization complete')
65+
66+
return app

0 commit comments

Comments
 (0)