Skip to content

cewinharhar/junctionHack2023

Repository files navigation

BioPrevention: AI-Powered Addiction Recovery Platform

Developed at Junction Hack 2023

An intelligent biohacking platform that leverages machine learning and real-time biometric monitoring to provide personalized intervention strategies for opioid addiction recovery. The system combines physiological data analysis with reinforcement learning to predict optimal intervention timing and intensity.

🎯 Overview

BioPrevention uses a multi-modal approach to addiction recovery support:

  • Real-time Biometric Monitoring: Tracks heart rate, HRV, sleep patterns, and mood indicators
  • AI-Driven Predictions: Deep Q-Network (DQN) model predicts intervention needs
  • Personalized Interventions: Three-tier support system from gentle notifications to professional help
  • Interactive Dashboard: Real-time visualization of physiological state and recommendations

πŸ—οΈ Architecture

The platform consists of three integrated components:

1. R Shiny Dashboard (/R/)

  • Interactive web dashboard built with golem framework
  • Real-time biometric data visualization
  • Integration with ML prediction API
  • bs4Dash modern UI components

2. Python ML Backend (/app/)

  • FastAPI server with PyTorch DQN model
  • Processes 6 biometric features: heart rate, HRV bands, sleep, mood
  • Returns intervention recommendations (1: notification, 2: activity, 3: professional help)

3. JavaScript Visualization (/jsEx/)

  • Chart.js-based real-time monitoring dashboard
  • Standalone biometric visualization interface

πŸš€ Quick Start

Prerequisites

  • R (β‰₯ 4.0) with packages: shiny, bs4Dash, golem, echarts4r
  • Python (β‰₯ 3.8) with pip
  • Modern web browser

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/junctionHack2023.git
    cd junctionHack2023
  2. Setup Python environment

    pip install -r requirements.txt
  3. Install R dependencies

    # In R console
    install.packages(c("shiny", "bs4Dash", "golem", "echarts4r", "ggplot2"))

Running the Application

Option 1: Full Stack (Recommended)

  1. Start Python API server

    cd app
    python main.py

    API will be available at http://localhost:8000

  2. Launch R Shiny Dashboard

    # In R console from project root
    junctionHack2023::run_app()

Option 2: Individual Components

Python API only:

uvicorn app.main:app --host 0.0.0.0 --port 8000

JavaScript Dashboard only:

cd jsEx
python -m http.server 8080
# Open http://localhost:8080

πŸ“Š API Usage

Prediction Endpoint

POST /prevent

Predicts intervention level based on current biometric state.

curl -X POST "http://localhost:8000/prevent" \
     -H "Content-Type: application/json" \
     -d '{
       "heartrate": 0.7,
       "lowFreq": 0.3,
       "highFreq": 0.8,
       "ratio": 0.4,
       "sleep": 0.6,
       "mood": 0.5
     }'

Response:

{
  "action": 2
}

Action Codes:

  • 1: Light intervention (positive reinforcement notification)
  • 2: Moderate intervention (social activity, exercise)
  • 3: Strong intervention (contact healthcare provider)

Input Parameters

Parameter Type Range Description
heartrate float 0.0-1.0 Normalized heart rate
lowFreq float 0.0-1.0 HRV low frequency component
highFreq float 0.0-1.0 HRV high frequency component
ratio float 0.0-1.0 LF/HF ratio
sleep float 0.0-1.0 Sleep quality score
mood float 0.0-1.0 Mood indicator

🧠 Machine Learning Model

The core ML component uses a Deep Q-Network (DQN) architecture:

  • Input Layer: 6 biometric features
  • Hidden Layers: 16 neurons each with ReLU activation
  • Output Layer: 3 action classes
  • Framework: PyTorch
  • Training: Reinforcement learning for optimal intervention timing

Model Architecture

Input(6) β†’ Linear(16) β†’ ReLU β†’ Linear(16) β†’ ReLU β†’ Linear(3)

πŸ› οΈ Development

Project Structure

junctionHack2023/
β”œβ”€β”€ R/                  # Shiny application modules
β”‚   β”œβ”€β”€ app_ui.R       # UI definition
β”‚   β”œβ”€β”€ app_server.R   # Server logic
β”‚   └── mod_mainDash.R # Main dashboard module
β”œβ”€β”€ app/               # Python ML backend
β”‚   β”œβ”€β”€ main.py        # FastAPI server
β”‚   β”œβ”€β”€ DQN.py         # Neural network model
β”‚   └── modelInit.py   # Model initialization
β”œβ”€β”€ jsEx/              # JavaScript visualization
β”‚   β”œβ”€β”€ index.html     # Dashboard HTML
β”‚   β”œβ”€β”€ script20.js    # Chart.js logic
β”‚   └── styles.css     # Styling
β”œβ”€β”€ biohacker.pt       # Pre-trained model weights
└── requirements.txt   # Python dependencies

Adding New Features

  1. New Biometric Input: Update State model in app/main.py and retrain DQN
  2. UI Modifications: Edit R Shiny modules in /R/ directory
  3. Visualization: Extend Chart.js implementation in /jsEx/

Testing

# Test API endpoint
python -c "
import requests
response = requests.post('http://localhost:8000/prevent',
                        json={'heartrate': 0.5, 'lowFreq': 0.3, 'highFreq': 0.7, 'ratio': 0.4, 'sleep': 0.8, 'mood': 0.6})
print(response.json())
"

πŸš€ Deployment

Heroku Deployment

The application is configured for Heroku deployment with the included Procfile:

# Deploy Python API
heroku create your-app-name
git push heroku main

Alternative Deployment

  • R Shiny: Deploy to shinyapps.io or RStudio Connect
  • Python API: Deploy to AWS Lambda, Google Cloud Run, or any container platform

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“œ License

This project was developed for Junction Hack 2023. Please ensure responsible use of addiction recovery technology.

πŸ™ Acknowledgments

  • Junction Hack 2023 organizers and participants
  • PyTorch and R Shiny communities
  • Healthcare professionals who provided domain expertise

For technical questions or collaboration opportunities, please open an issue or contact the development team.

About

Biohacking group

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors