A comprehensive, multi-layered AI system for sleep analysis, diagnosis, and optimization using machine learning, reinforcement learning, and real-time data processing.
SleepPilot is a cutting-edge sleep optimization platform that combines multiple AI technologies to provide personalized sleep insights and recommendations. The system processes sleep data through three distinct layers, each specializing in different aspects of sleep analysis and optimization.
The project is structured in three main layers, each serving a specific purpose in the sleep optimization pipeline:
ignition/
βββ layer1/ # ML-based sleep quality scoring
βββ layer2RLdiagnosis-v1/ # RL-based apnea diagnosis
βββ layer3rl/ # RL environment optimization & API
βββ frontend2/ # React Native mobile application
Location: layer1/
Purpose: Initial sleep quality assessment using machine learning models.
Key Features:
- Sleep quality scoring based on audio and environmental data
- Pre-trained models for rapid analysis
- Baseline sleep pattern recognition
Technologies:
- PyTorch
- Audio processing with librosa
- Machine learning models for sleep classification
Files:
sleep_quality_scorer.py- Main scoring algorithmlarger_trainer.py- Model training scriptsfinal_larger_model.pth- Pre-trained model weights
Location: layer2RLdiagnosis-v1/
Purpose: Advanced sleep apnea detection using reinforcement learning.
Key Features:
- Real-time apnea event detection
- RL agent training for diagnosis optimization
- Multi-parameter sleep analysis
- Confidence scoring for medical applications
Technologies:
- PyTorch
- Gymnasium (OpenAI Gym)
- Stable-Baselines3
- Reinforcement Learning algorithms (PPO, SAC)
Key Components:
apnea_env.py- Custom RL environment for sleep apnea detectiondiagnose_agent.py- RL agent implementationrl_agent.py- Core RL algorithmsmain.py- Training and evaluation scripts
Dependencies:
pip install -r requirements.txtLocation: layer3rl/
Purpose: Real-time environment optimization and API services for the frontend.
Key Features:
- RESTful API for sleep data processing
- Real-time environment optimization using RL
- Sleep quality improvement recommendations
- Audio analysis and processing
Technologies:
- FastAPI
- PyTorch
- Gymnasium
- Stable-Baselines3
- Audio processing libraries
API Endpoints:
/analyze- Sleep data analysis/optimize- Environment optimization/recommendations- Personalized sleep recommendations
Dependencies:
pip install -r requirements.txtLocation: frontend2/
Purpose: Cross-platform mobile application for user interaction and data visualization.
Key Features:
- Beautiful, modern UI with dark theme
- Real-time sleep data visualization
- Interactive charts and graphs
- Personalized recommendations display
- Layer 3 RL analytics dashboard
Technologies:
- React Native
- Expo
- Victory Native (charts)
- React Navigation
- Linear gradients and animations
Screens:
- Landing Screen: Interactive cloud animations and app introduction
- Dashboard: Sleep data input and processing
- Trends: Sleep pattern visualization with 5 distinct peaks
- Recommendations: Personalized tips with RL training analytics
- Risks: Sleep risk assessment
- Profile: User settings and preferences
- Python 3.8+
- Node.js 16+
- Expo CLI
- iOS Simulator or Android Emulator (for mobile development)
git clone https://github.com/yourusername/ignition.git
cd ignitioncd layer1
pip install torch torchaudio librosa numpy scipy
# Run training or use pre-trained models
python larger_trainer.pycd ../layer2RLdiagnosis-v1
pip install -r requirements.txt
# Train the RL agent
python main.pycd ../layer3rl
pip install -r requirements.txt
# Start the API server
uvicorn api:app --reload --host 0.0.0.0 --port 8000cd ../frontend2
npm install
npm start-
Start Layer 3 API:
cd layer3rl uvicorn api:app --reload -
Start Frontend:
cd frontend2 npm start -
Access the App:
- Use Expo Go app on your mobile device
- Scan the QR code from the terminal
- Or run on iOS/Android simulators
- Audio Processing: Real-time sleep audio analysis
- Pattern Recognition: ML-based sleep pattern identification
- Quality Scoring: Comprehensive sleep quality metrics
- Event Detection: Apnea and sleep disturbance detection
- Reinforcement Learning: Continuous environment optimization
- Personalized Recommendations: User-specific sleep improvements
- Real-time Adaptation: Dynamic adjustment based on user feedback
- Multi-parameter Optimization: Temperature, light, noise, humidity, airflow
- Interactive Charts: Victory Native-powered visualizations
- Real-time Updates: Live data streaming and updates
- Trend Analysis: Historical sleep pattern analysis
- Performance Metrics: RL training progress and convergence
- Intuitive Interface: Modern, accessible design
- Responsive Design: Optimized for all screen sizes
- Smooth Animations: Engaging user interactions
- Offline Capability: Core functionality without internet
Create .env files in each layer directory:
Layer 3 API:
API_HOST=0.0.0.0
API_PORT=8000
MODEL_PATH=./models/
DEBUG_MODE=trueFrontend:
API_BASE_URL=http://localhost:8000
ENABLE_ANALYTICS=true
DEBUG_MODE=trueEach layer can be configured through JSON configuration files:
- Layer 1:
config.jsonfor ML model parameters - Layer 2:
config.pyfor RL environment settings - Layer 3:
config.pyfor API and optimization parameters
- Model Quantization: Optimized inference for mobile devices
- Batch Processing: Efficient handling of multiple sleep sessions
- Caching: Intelligent data caching for improved performance
- Async Processing: Non-blocking API operations
- Microservices Architecture: Independent layer scaling
- Load Balancing: Distributed API handling
- Database Optimization: Efficient data storage and retrieval
- Mobile Optimization: Lightweight models for edge devices
# Layer 1
cd layer1
python -m pytest tests/
# Layer 2
cd ../layer2RLdiagnosis-v1
python -m pytest tests/
# Layer 3
cd ../layer3rl
python -m pytest tests/# Test API endpoints
cd layer3rl
python test_api.py
# Test frontend components
cd ../frontend2
npm test# Load testing for API
cd layer3rl
python performance_test.pyAnalyze sleep data and return quality metrics.
Request Body:
{
"audio_data": "base64_encoded_audio",
"environmental_data": {
"temperature": 22.5,
"humidity": 45.0,
"light_level": 0.1,
"noise_level": 0.2
},
"user_metrics": {
"hours_slept": 7.5,
"sleep_rating": 8,
"stress_level": "medium"
}
}Response:
{
"sleep_score": 85,
"quality_category": "good",
"confidence": 0.92,
"recommendations": [
"Optimize room temperature to 20Β°C",
"Reduce ambient light exposure"
]
}Get RL-optimized environment recommendations.
Request Body:
{
"current_environment": {
"temperature": 24.0,
"humidity": 50.0,
"light_level": 0.8,
"noise_level": 0.6
},
"sleep_history": [...],
"user_preferences": {...}
}- Model Loading Errors: Ensure PyTorch version compatibility
- Audio Processing: Check librosa and soundfile installations
- RL Training: Verify Gymnasium and Stable-Baselines3 versions
- Environment Errors: Check custom environment implementation
- API Connection: Verify FastAPI server is running
- Model Loading: Check model file paths and permissions
- Build Errors: Clear npm cache and reinstall dependencies
- Chart Rendering: Ensure Victory Native is properly linked
- Navigation: Check React Navigation configuration
Enable debug mode in each layer for detailed logging:
# Python layers
import logging
logging.basicConfig(level=logging.DEBUG)
# Frontend
console.log('Debug mode enabled');We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Code Style: Follow PEP 8 for Python, ESLint for JavaScript
- Testing: Write tests for new features
- Documentation: Update README and code comments
- Performance: Consider mobile device limitations
This project is licensed under the MIT License - see the LICENSE file for details.
- Research Community: Sleep science and AI research papers
- Open Source: PyTorch, React Native, and other libraries
- Medical Advisors: Sleep medicine professionals
- Beta Testers: Early users and feedback providers
- β Basic ML sleep scoring
- β RL apnea detection
- β Environment optimization API
- β Mobile frontend
- π Multi-user support
- π Cloud deployment
- π Advanced analytics
- π Medical device integration
- π FDA approval for medical use
- π Enterprise solutions
- π Research partnerships
- π Global expansion
SleepPilot - Revolutionizing sleep optimization through AI innovation.