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.
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
The platform consists of three integrated components:
- Interactive web dashboard built with golem framework
- Real-time biometric data visualization
- Integration with ML prediction API
- bs4Dash modern UI components
- 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)
- Chart.js-based real-time monitoring dashboard
- Standalone biometric visualization interface
- R (β₯ 4.0) with packages:
shiny,bs4Dash,golem,echarts4r - Python (β₯ 3.8) with
pip - Modern web browser
-
Clone the repository
git clone https://github.com/yourusername/junctionHack2023.git cd junctionHack2023 -
Setup Python environment
pip install -r requirements.txt
-
Install R dependencies
# In R console install.packages(c("shiny", "bs4Dash", "golem", "echarts4r", "ggplot2"))
-
Start Python API server
cd app python main.pyAPI will be available at
http://localhost:8000 -
Launch R Shiny Dashboard
# In R console from project root junctionHack2023::run_app()
Python API only:
uvicorn app.main:app --host 0.0.0.0 --port 8000JavaScript Dashboard only:
cd jsEx
python -m http.server 8080
# Open http://localhost:8080POST /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)
| 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 |
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
Input(6) β Linear(16) β ReLU β Linear(16) β ReLU β Linear(3)
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
- New Biometric Input: Update
Statemodel inapp/main.pyand retrain DQN - UI Modifications: Edit R Shiny modules in
/R/directory - Visualization: Extend Chart.js implementation in
/jsEx/
# 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())
"The application is configured for Heroku deployment with the included Procfile:
# Deploy Python API
heroku create your-app-name
git push heroku main- R Shiny: Deploy to shinyapps.io or RStudio Connect
- Python API: Deploy to AWS Lambda, Google Cloud Run, or any container platform
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project was developed for Junction Hack 2023. Please ensure responsible use of addiction recovery technology.
- 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.