Skip to content

aishux/LumaAi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Luma AI – Dementia Care Companion

Luma AI is a dementia care companion platform built for caregivers and patients. It combines AI agents, serverless workflows, and real-time monitoring to support memory assistance, medication reminders, wandering alerts, and MRI-based cognitive insights. The system is designed to run on DigitalOcean (App Platform, Functions, Spaces, Managed Postgres, Managed Valkey/Redis, OpenSearch).

Disclaimer
This is a research prototype, not a diagnostic medical tool. Do not use for real medical decision-making. All interfaces must display: "This is a research prototype, not a diagnostic medical tool."


Table of Contents


Features

Feature Description
Memory companion Store and search memories (text + images) with semantic search via Gemini embeddings and OpenSearch. Caretaker-defined β€œusual spots” are merged into search results.
Caregiver intelligence Chat and weekly risk summaries: MRI analysis, wandering/memory patterns, and actionable next steps. Powered by configurable AI agents (e.g. Gradient/DO Agents).
MRI analysis Upload brain MRI scans; images are stored in DO Spaces, analyzed by a GPU inference service (ONNX ViT), and results are persisted and summarized by the caregiver agent.
Medication reminders Timezone-aware medication schedules in Postgres; DigitalOcean Functions + Twilio send SMS reminders and update last_sent_at.
Wandering detection GPS events streamed to Valkey (Redis); a detector compares distance from a safe zone and triggers Twilio SMS alerts + logs to Postgres for risk scoring.
Dashboard Caretaker dashboard with per-patient charts: wandering counts, memory search success/failure, medication distribution, and setup metrics (meds, usual spots, MRIs).

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           Caregiver / Patient                                β”‚
β”‚                         (Browser β†’ Django App)                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  luma_web (Django)                                                           β”‚
β”‚  β€’ Auth (caretaker vs patient), sessions, patient CRUD                       β”‚
β”‚  β€’ Proxies: /agents/mri, /agents/memory/store, /agents/memory/search,       β”‚
β”‚    /agents/chat β†’ DO Agents (BASE_URL + ACCESS_TOKEN)                        β”‚
β”‚  β€’ Uploads to DO Spaces (memories, MRI studies)                              β”‚
β”‚  β€’ Dashboard data from Postgres (wander_alerts, memory_retrieval_logs,      β”‚
β”‚    medication_schedules, mri_studies, usual_spots)                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                    β”‚                    β”‚                    β”‚
         β–Ό                    β–Ό                    β–Ό                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ DO Agents    β”‚    β”‚ DO Serverless   β”‚   β”‚ DO Spaces    β”‚   β”‚ Managed         β”‚
β”‚ (Caregiver,  β”‚    β”‚ Functions       β”‚   β”‚ (S3-compat)  β”‚   β”‚ Postgres        β”‚
β”‚ Memory, Chat)β”‚    β”‚ (see below)     β”‚   β”‚              β”‚   β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                    β”‚                                      β”‚
         β”‚                    β”‚  memory_store, memory_retrieve,       β”‚
         β”‚                    β”‚  mri_analysis, medication_worker,     β”‚
         β”‚                    β”‚  risk_analyser                        β”‚
         β”‚                    β–Ό                                      β”‚
         β”‚           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
         β”‚           β”‚ OpenSearch      β”‚   β”‚ MRI Inference    β”‚       β”‚
         β”‚           β”‚ (embeddings,    β”‚   β”‚ (FastAPI+ONNX   β”‚       β”‚
         β”‚           β”‚  patient-memories)β”‚   β”‚  on GPU VM)     β”‚       β”‚
         β”‚           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
         β”‚                                                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”                                                    β”‚
β”‚ Wandering       β”‚  Valkey (Redis) streams ← simulator / GPS          β”‚
β”‚ detector        β”‚  β†’ Twilio SMS + INSERT into wander_alerts β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Django is the main web app: auth, dashboard, patient management, and proxy to AI agents.
  • DigitalOcean Agents (Caregiver, Memory, Chat) are invoked by Django via DO_*_AGENT_BASE_URL and DO_*_AGENT_ACCESS_TOKEN. Agents can call serverless functions and tools.
  • Serverless functions handle: memory store/retrieve (Gemini + OpenSearch + Spaces), MRI pipeline (Spaces β†’ inference URL β†’ Postgres), medication SMS (Postgres + Twilio), risk summary (Postgres aggregations).
  • MRI inference is a separate FastAPI service (e.g. on a GPU droplet) exposing /predict; the mri_analysis function calls it via INFERENCE_URL.

Project Structure

LumaAI/
β”œβ”€β”€ luma_web/                    # Django application (main web app)
β”‚   β”œβ”€β”€ luma_web/                # Project settings, urls, wsgi
β”‚   β”œβ”€β”€ luma_app/                # App: models, views, services, templates
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ env-example              # Example environment variables
β”‚   └── Dockerfile               # For App Platform / GHCR
β”‚
β”œβ”€β”€ functions/                   # DigitalOcean Serverless Functions
β”‚   β”œβ”€β”€ memory_store/            # Store memory (text/image β†’ Gemini β†’ OpenSearch)
β”‚   β”œβ”€β”€ memory_retrieve/         # Semantic + keyword search, usual spots, logging
β”‚   β”œβ”€β”€ mri_analysis/            # Fetch image from Spaces β†’ inference β†’ Postgres
β”‚   β”œβ”€β”€ medication_worker/       # Cron: due meds β†’ Twilio SMS, update last_sent_at
β”‚   └── risk_analyser/           # Aggregates logs for caregiver agent (wander, memory, MRI)
β”‚
β”œβ”€β”€ mri_detection/               # Standalone MRI inference API (FastAPI + ONNX)
β”‚   β”œβ”€β”€ app.py                   # /predict endpoint (ViT model)
β”‚   β”œβ”€β”€ alzheimer_onnx/          # ONNX model (or restore from alzheimer_onnx_backup.tar.gz)
β”‚   └── commands.txt             # Setup and curl examples
β”‚
β”œβ”€β”€ wandering_notice/            # Wandering alert pipeline
β”‚   β”œβ”€β”€ simulator.py             # Pushes GPS events to Valkey stream (patient:2:gps_stream)
β”‚   └── detector.py             # Consumes stream, geodesic distance, Twilio SMS + Postgres
β”‚
β”œβ”€β”€ agents/                      # Agent prompts / instructions (for Gradient/DO Agents)
β”‚   β”œβ”€β”€ Luma_AI_Caregiver_Agent.md
β”‚   β”œβ”€β”€ Luma_AI_Patient_Intelligence_Agent.md
β”‚   └── Luma_AI_Supervisor_Agent.md
β”‚
β”œβ”€β”€ frontend/                    # Static HTML/CSS reference (dashboard, chat, memories, MRI, etc.)
β”œβ”€β”€ KnowledgeBases/              # PDFs for agent context (e.g. NIA caregiver guides)
└── .github/workflows/           # CI (e.g. build and push luma_web to GHCR)

Prerequisites

  • Python 3.10+ (3.11 for luma_web Dockerfile)
  • PostgreSQL (e.g. DigitalOcean Managed Database)
  • Redis/Valkey (e.g. DO Managed Valkey) for wandering streams
  • OpenSearch (for memory embeddings index patient-memories)
  • S3-compatible storage (e.g. DO Spaces) for images and MRI studies
  • Twilio account (SMS for medication reminders and wandering alerts)
  • Google Gemini API key (embeddings and vision in memory store/retrieve)
  • DigitalOcean Agents (or compatible OpenAI-style API) for Caregiver, Memory, and Chat
  • doctl and DigitalOcean Serverless plugin for deploying functions

Getting Started

1. Clone and enter the repo

git clone <repo-url>
cd LumaAI

2. Django web app (luma_web)

cd luma_web
python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp env-example .env
# Edit .env with your DATABASE_*, SPACES_*, and DO_*_AGENT_* variables
python manage.py migrate
python manage.py runserver

3. MRI inference (mri_detection) – optional for full pipeline

Used by the mri_analysis function. Run on a machine with GPU for best performance:

cd mri_detection
python3 -m venv alz_env && source alz_env/bin/activate
pip install "numpy==1.26.4" optimum[onnxruntime] transformers fastapi uvicorn python-multipart Pillow torch torchvision accelerate
# If you have alzheimer_onnx_backup.tar.gz: tar -xzf alzheimer_onnx_backup.tar.gz
python app.py

4. Wandering pipeline (wandering_notice)

  • Simulator (sends fake GPS to Valkey):

    cd wandering_notice
    pip install redis python-dotenv
    # Set VALKEY_URL in .env
    python simulator.py
  • Detector (consumes stream, sends SMS and writes to Postgres):

    pip install redis psycopg geopy python-dotenv twilio
    # Set VALKEY_URL, DATABASE_URL, TWILIO_*, CAREGIVER_PHONE in .env
    python detector.py

5. DigitalOcean Serverless Functions

From the root of each function (e.g. functions/memory_retrieve):

doctl serverless connect
doctl serverless deploy . --env .env --remote-build

Deploy each of: memory_store, memory_retrieve, mri_analysis, medication_worker, risk_analyser. Ensure their .env (or DO namespace env) has the required keys (e.g. DATABASE_URL, OS_*, SPACES_*, GEMINI_API_KEY, TWILIO_*, INFERENCE_URL for mri_analysis).


Configuration & Environment

luma_web (Django)

Copy luma_web/env-example to luma_web/.env and set:

Variable Purpose
DJANGO_SECRET_KEY Django secret key
DATABASE_PASSWORD, DATABASE_HOST Postgres (DB name/user/port in settings.py)
SPACES_BUCKET, SPACES_REGION, SPACES_ACCESS_KEY, SPACES_SECRET_KEY, SPACES_BASE_URL, SPACES_ENDPOINT DO Spaces for uploads
DO_CAREGIVER_AGENT_BASE_URL, DO_CAREGIVER_AGENT_ACCESS_TOKEN Caregiver agent (MRI + risk summary)
DO_MEMORY_AGENT_BASE_URL, DO_MEMORY_AGENT_ACCESS_TOKEN Memory store/search agent
DO_CHAT_AGENT_BASE_URL, DO_CHAT_AGENT_ACCESS_TOKEN Chat agent

Serverless functions

Each function’s environment typically needs:

  • memory_store / memory_retrieve: OS_HOST, OS_USER, OS_PASS, GEMINI_API_KEY, SPACES_*, DATABASE_URL (retrieve also logs to memory_retrieval_logs and uses usual_spots).
  • mri_analysis: SPACES_*, DATABASE_URL, INFERENCE_URL (e.g. http://<mri-detection-host>:8000/predict).
  • medication_worker: DATABASE_URL, TWILIO_SID, TWILIO_AUTH_TOKEN (and Twilio β€œfrom” number in code if different).
  • risk_analyser: DATABASE_URL.

Wandering

  • simulator: VALKEY_URL
  • detector: VALKEY_URL, DATABASE_URL, TWILIO_SID, TWILIO_AUTH_TOKEN, CAREGIVER_PHONE

Components in Detail

luma_web (Django)

  • Models: Patient, MedicationSchedules, MemoryRetrievalLogs, MriStudies, UsualSpots, WanderAlerts (most unmanaged, mapping to existing tables).
  • Views: Login/signup, dashboard, patient CRUD, memories page, MRI upload, chat. Agent proxies build prompts (with patient_id, image URLs, etc.) and call invoke_agent(prefix, payload) from services.py.
  • Agent integration: services.invoke_agent(prefix, payload) uses {prefix}_BASE_URL and {prefix}_ACCESS_TOKEN, POSTs to an OpenAI-compatible /api/v1/chat/completions endpoint, returns markdown and raw JSON.

DigitalOcean Functions

  • memory_store: Input: patient_id, text_note, image_url. Fetches image from Spaces if present, describes with Gemini vision, builds unified text, embeds with Gemini, indexes in OpenSearch patient-memories.
  • memory_retrieve: Input: patient_id, query. Embeds query, runs OpenSearch k-NN + keyword, merges caretaker β€œusual spots” from Postgres, logs to memory_retrieval_logs, returns combined results with optional presigned image URLs.
  • mri_analysis: Input: patient_id, image_url. Fetches image from Spaces, normalizes, calls INFERENCE_URL for prediction, writes row to mri_studies.
  • medication_worker: Runs on schedule; selects rows from medication_schedules where reminder time (in patient timezone) is due and not yet sent today, sends Twilio SMS, updates last_sent_at.
  • risk_analyser: Input: patient_id, days. Returns recent memory retrievals, wander alerts, and latest MRI for the caregiver agent.

mri_detection

  • FastAPI app loading an ONNX Vision Transformer from ./alzheimer_onnx, exposes POST /predict (image file) and returns prediction, confidence, and disclaimer text.

wandering_notice

  • simulator: Appends GPS-like entries to Valkey stream patient:2:gps_stream.
  • detector: Reads stream, computes geodesic distance from SAFE_ZONE_CENTER; if > SAFE_RADIUS_METERS, sends Twilio SMS and inserts into wander_alerts.

Deployment

  • Django: The repo includes a Dockerfile under luma_web/. GitHub Actions (e.g. .github/workflows/publish-ghcr.yml) can build and push the image to GHCR; point DigitalOcean App Platform at that image and set env vars.
  • Functions: Deploy with doctl serverless deploy . --env .env --remote-build from each function directory; configure triggers (e.g. cron for medication_worker) and wire agent tools to the function endpoints.
  • MRI inference: Deploy mri_detection on a VM or GPU instance; set INFERENCE_URL in the mri_analysis function.
  • Wandering: Run detector.py as a long-lived process (e.g. systemd or container) with access to Valkey and Postgres.

Healthcare Disclaimer

All interfaces and outputs in this project must clearly state:

"This is a research prototype, not a diagnostic medical tool."

Do not use this system for real medical decision-making. Ensure compliance with local regulations and clinical validation before any clinical or diagnostic use.


License

See repository license file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors