Jamorham
Nightscout용 xDrip+ 버전
AI Research tracking and Machine Learning to filter relevant content and accelerate scientific research
저장소 README에서 가져옴
README 전체를 불러오는 중입니다. 아래는 저장된 발췌입니다.
Gregory is an AI system that uses Machine Learning and Natural Language Processing to track
clinical research and identify papers which improves the wellbeing of patients.
Sources for research can be added by RSS feed or manually.
The output can be seen in a static site, using build.py or via the api provided by the Django Rest Framework.
The docker compose file also includes a Metabase container which is used to build dashboards and manage notifications.
Sources can also be added to monitor Clinical Trials, in which case Gregory can notify a list of email subscribers.README 전문 보기 ↗[TOC]
Gregory is an AI system that uses Machine Learning and Natural Language Processing to track clinical research and identify papers which improves the wellbeing of patients.
Sources for research can be added by RSS feed or manually.
The output can be seen in a static site, using build.py or via the api provided by the Django Rest Framework.
The docker compose file also includes a Metabase container which is used to build dashboards and manage notifications.
Sources can also be added to monitor Clinical Trials, in which case Gregory can notify a list of email subscribers.
https://brain-regeneration.com
Issues labeled codex are automatically assigned to the openai-codex user.
The workflow then invokes the Codex GitHub App, which proposes a pull request
with changes that address the issue.
Clone the repository and configure your environment:
git clone <repository_url>
cd <repository_directory>
cp example.env .env # fill in your values before continuing
Pull the image and start:
docker compose pull
docker compose up -d
The container entrypoint automatically runs migrate and collectstatic on startup, waiting for Postgres to be ready before proceeding.
Create the cache table (one-time, required for the /stats/ endpoint):
docker exec gregory python manage.py createcachetable gregory_cache
Create a superuser:
docker exec gregory python manage.py createsuperuser
Once the server is set up, deploying a new version requires no git pull or manual commands:
docker compose pull && docker compose up -d
migrate and collectstatic run automatically on startup.
api.domain.etcapi.domain.etc pointing to your server's IP address.GregoryAI uses Postmark for transactional emails (newsletters, admin digests, clinical trial notifications).
The preferred approach is to configure Postmark credentials per-team in
the Django admin (Team → postmark_api_token / postmark_api_url). You can
also set global fallback values via environment variables — see step 5.1.
.env file..envDeveloper Tools and create an API client..env file:
ORCID_CLIENT_ID=your_orcid_client_id
ORCID_CLIENT_SECRET=your_orcid_client_secret
DOMAIN_NAME=DOMAIN.COM
# Optional: comma-separated extra hostnames/IPs added to ALLOWED_HOSTS.
# Include your server's IP and any additional domains pointing at this instance.
EXTRA_ALLOWED_HOSTS=203.0.113.1,otherdomain.com
# --- PostgreSQL ---
POSTGRES_DB=
POSTGRES_PASSWORD=
POSTGRES_USER=
# --- Django ---
# Generate with: python -c "import secrets; print(secrets.token_urlsafe(50))"
SECRET_KEY=''
# Generate with: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
FERNET_SECRET_KEY=
# --- Email / SMTP ---
# These variables are only needed if you plan to send notification emails.
EMAIL_DOMAIN=
EMAIL_HOST=
EMAIL_HOST_PASSWORD=
EMAIL_HOST_USER=
EMAIL_PORT=587
EMAIL_USE_TLS=True
# Postmark (fallback; per-team config in Django admin is preferred)
EMAIL_POSTMARK_API_KEY=
EMAIL_POSTMARK_API_URL=
# --- ORCID API ---
ORCID_CLIENT_ID=
ORCID_CLIENT_SECRET=
sudo apt-get update
sudo apt-get install nginx
sudo nano /etc/nginx/sites-available/default
sudo nginx -t
sudo systemctl restart nginx
sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d domain.etc -d www.domain.etc
sudo ufw allow 'Nginx Full'
sudo ufw enable
Sites and click Create Site.Teams and click Create Team.Teams, select the team, and click Add User.Sources and click Add Source.RSS method and provide the necessary configuration.# Every 2 days at 8:00
0 8 */2 * * /usr/bin/docker exec gregory python manage.py send_admin_summary
# Every Tuesday at 8:05
5 8 * * 2 docker exec gregory python manage.py send_weekly_summary
# Every 12 hours, at minute 25
25 */12 * * * /usr/bin/flock -n /tmp/pipeline /usr/bin/docker exec gregory python manage.py pipeline
To keep API access logs under control, schedule the API log pruning command with one retention policy.
# Keep only the last 30 days (run daily)
40 2 * * * /usr/bin/docker exec gregory python manage.py prune_api_access_scheme_logs --window 30d
# Keep only the last 90 days (run weekly)
45 2 * * 0 /usr/bin/docker exec gregory python manage.py prune_api_access_scheme_logs --window 90d
# Keep only the last 1 year (run monthly)
50 2 1 * * /usr/bin/docker exec gregory python manage.py prune_api_access_scheme_logs --window 1y
Use only one of the three prune schedules above based on your retention policy.
python3 scripts/bootstrap.py.The script checks if you have all the requirements and run to help you setup the containers.
Once finished, login at https://api.DOMAIN.TLD/admin or wherever your reverse proxy is listening on.
*/3 * * * * /usr/bin/docker exec -t gregory python manage.py runcrons
Most of the logic is inside Django, the gregory container provides the Django Rest Framework, manages subscriptions, and sends emails.
The following subscriptions are available:
Admin digest
This is sent every 48 hours with the latest articles and their machine learning prediction. Allows the admin access to an Edit link where the article can be edited and tagged as relevant.
Weekly digest
This is sent every Tuesday, it lists the relevant articles discovered in the last week.
Clinical Trials
This is sent every 12 hours if a new clinical trial was posted.
The title of the email footer for these emails needs to be set in the Custom Settings section of the admin backoffice.
Django also allows you to add new sources from where to fetch articles. Take a look at /admin/gregory/sources/
Emails are sent from the gregory container using Postmark.
The preferred approach is to configure Postmark credentials per-team in the
Django admin (Team → postmark_api_token / postmark_api_url). This allows
different teams to use separate Postmark servers.
Global fallback environment variables can be set in .env:
EMAIL_USE_TLS=true
EMAIL_POSTMARK_API_KEY='YOUR SERVER API TOKEN'
EMAIL_POSTMARK_API_URL='https://api.postmarkapp.com/email'
EMAIL_DOMAIN='YOURDOMAIN'
As an alternative, you can configure Django to use any other SMTP email server
via the EMAIL_HOST* variables.
Gregory has the concept of 'subject'. In this case, Multiple Sclerosis is the only subject configured. A Subject is a group of Sources and their respective articles. There are also categories that can be created. A category is a group of articles whose title matches at least one keyword in list for that category. Categories can include articles across subjects.
There are options to filter lists of articles by their category or subject in the format articles/category/<category> and articles/subject/<subject> where and is the lowercase name with spaces replaced by dashes.
/feed/latest/articles//feed/articles/subject/<subject>//feed/articles/category/<category>//feed/latest/trials//feed/machine-learning//feed/twitter/. This includes all relevant articles by manual selection and machine learning prediction. It's read by Zapier so that we can post on twitter automatically.It's useful to re-train the machine learning models once you have a good number of articles flagged as relevant.
Gregory AI now includes a powerful Django management command for training ML models, with support for different algorithms, verbosity levels, and more.
# Train all algorithms for a specific team and subject
python manage.py train_models --team research --subject oncology
# Train all models for the 'clinical' team with maximum verbosity
python manage.py train_models --team clinical --verbose 3
# Train only LGBM model for a specific team and subject
python manage.py train_models --team research --subject cardiology --algo lgbm_tfidf
| Option | Description |
|---|---|
--team TEAM_SLUG | Team slug to train models for |
--all-teams | Train models for all teams |
--subject SUBJECT_SLUG | Subject slug within the chosen team (if not specified, train for all subjects) |
--all-articles | Use all labeled articles (ignores 90-day window) |
--lookback-days DAYS | Override the default 90-day window for article discovery |
--algo ALGORITHMS | Comma-separated list of algorithms to train (pubmed_bert,lgbm_tfidf,lstm) |
--prob-threshold THRESHOLD | Probability threshold for classification (default: 0.8) |
--version VERSION | Manual version tag (default: auto-generated YYYYMMDD with optional _n suffix) |
--pseudo-label | Run BERT self-training loop before final training |
--verbose LEVEL | Verbosity level (0: quiet, 1: progress, 2: +warnings, 3: +summary) |
In production, it's recommended to run the command on a scheduled basis (e.g., monthly) with the appropriate verbosity level:
# Example for production cron job
docker exec -it gregory-django python manage.py train_models --all-teams --verbose 1
For development and testing, you may want to see detailed training information:
# Example for development
python manage.py train_models --team research --subject test --verbose 3
Gregory AI includes a comprehensive test suite. To run tests:
# Run all tests
cd django
python manage.py test
# Run specific test files or modules
python manage.py test gregory.tests.test_filename
# Run standalone test files (for tests that avoid Django dependencies)
cd django
python gregory/tests/test_train_models_standalone.py
Gregory AI includes a powerful Django management command for training ML models, with support for different algorithms, verbosity levels, and more.
# Train all algorithms for a specific team and subject
python manage.py train_models --team research --subject oncology
# Train only BERT for all subjects in the clinical team
python manage.py train_models --team clinical --algo pubmed_bert
# Train all models for all teams with verbose output
python manage.py train_models --all-teams --verbose 3
# Run with pseudo-labeling and custom threshold
python manage.py train_models --team research --subject cardiology --pseudo-label --prob-threshold 0.75
| Option | Description |
|---|---|
--team TEAM_SLUG | Team slug to train models for |
--all-teams | Train models for all teams |
--subject SUBJECT_SLUG | Subject slug within the chosen team (if not specified, train for all subjects) |
--all-articles | Use all labeled articles (ignores 90-day window) |
--lookback-days DAYS | Override the default 90-day window for article discovery |
--algo ALGORITHMS | Comma-separated list of algorithms to train (pubmed_bert, lgbm_tfidf, lstm) |
--prob-threshold VALUE | Probability threshold for classification (default: 0.8) |
--version TAG | Manual version tag (default: auto-generated YYYYMMDD) |
--pseudo-label | Run BERT self-training loop before final training |
--verbose LEVEL | Verbosity level (0-3, where 0=quiet, 3=summary) |
When developing or testing, consider:
# Use minimal data for quick testing
python manage.py train_models --team test-team --subject test-subject --lookback-days 30 --algo pubmed_bert --verbose 3
# Skip pseudo-labeling in development to speed up training
python manage.py train_models --team research --subject oncology --algo pubmed_bert --verbose 2
In production environments:
# Train all algorithms with default settings
python manage.py train_models --team production --subject main
# Use custom version tag for tracking specific runs
python manage.py train_models --team clinical --subject cardiology --version v1.2.3_special
# Use pseudo-labeling for improved performance with unlabeled data
python manage.py train_models --team research --all-articles --pseudo-label
cp example.env .env # fill in your values
cp docker-compose.override.yaml.example docker-compose.override.yaml
The override file mounts ./django:/code so code changes are reflected immediately without rebuilding the image. Set DJANGO_DEBUG=True in .env and the entrypoint will start runserver instead of gunicorn.
docker compose up -d
And the Lobsters at One Over Zero