Spaces:
Runtime error
Runtime error
|
Download README_PRODUCTION.md from happynickamazon/zenvolt-api: direct link, hf CLI and curl.
- Browser
- Download file 5.66 kB
-
https://huggingface.co/spaces/happynickamazon/zenvolt-api/resolve/main/README_PRODUCTION.md
- Command line
-
hf download hf://spaces/happynickamazon/zenvolt-api/README_PRODUCTION.md
-
curl -L -o README_PRODUCTION.md https://huggingface.co/spaces/happynickamazon/zenvolt-api/resolve/main/README_PRODUCTION.md
5.66 kB
NASA SOH Production Pipeline - Documentation
Overview
This is the production-ready NASA battery State of Health (SOH) prediction pipeline with:
- β Causal features only (no data leakage)
- β Transparent methodology (full audit reports)
- β Uncertainty quantification (95% prediction intervals)
- β FastAPI service (ready for frontend integration)
- β Honest metrics (RΒ² reported accurately, not inflated)
Quick Start
1. Install Dependencies
pip install -r requirements.txt
2. Run Feature Audit
python feature_audit.py
This generates data_leakage_audit.txt documenting all features and fixing leakage.
3. Train Production Model
python production_pipeline.py
This will:
- Load causal features (no leakage)
- Train Random Forest model
- Save
nasa_soh_model.pklandfeature_pipeline_causal.pkl - Generate
nasa_model_validation.csv
4. Generate Visualizations
python generate_app_visualizations.py
Creates 3 app-ready plots:
health_forecast.png- Past + Future with uncertaintyerror_growth.png- Error vs forecast horizonmodel_simplicity.png- Performance vs complexity
5. Generate Transparency Reports
python transparency_reports.py
Generates:
data_leakage_audit.txt- Feature causality audituncertainty_methodology.txt- How intervals are calculatedfailure_cases.csv- Where model performs worst
6. Start API Service
python api_service.py
Or using uvicorn directly:
uvicorn api_service:app --host 0.0.0.0 --port 8000 --reload
API available at: http://localhost:8000
API Endpoints
POST /api/predict
Predict battery health from BMS data.
Request:
{
"data": [
{
"cycle_index": 1,
"voltage": 4.2,
"current": 1.5,
"temperature": 25.0,
"capacity": 2.0
}
],
"initial_capacity": 2.0,
"forecast_horizons": [10, 50, 100]
}
Response:
{
"current_soh": {
"point_estimate": 0.95,
"lower_95": 0.93,
"upper_95": 0.97
},
"health_score": 95.0,
"remaining_life": {
"cycles": 500,
"years": 1.37
},
"forecasts": {...},
"data_quality": {...},
"model_info": {...}
}
GET /api/model-info
Get model information for Trust Engine proof.
GET /api/visualizations/{plot_name}
Get visualization images (base64 encoded) for PDF reports.
File Structure
proofstack/
βββ feature_audit.py # Feature leakage detection
βββ feature_engineering_causal.py # Fixed feature engineering (no leakage)
βββ production_pipeline.py # Train production model
βββ predict_soh.py # Production prediction function
βββ generate_app_visualizations.py # Generate 3 app-ready plots
βββ transparency_reports.py # Generate audit & methodology docs
βββ api_service.py # FastAPI service
βββ health_certificate.html # Certificate template
βββ models/
β βββ nasa_soh_model.pkl # Production model (Random Forest)
β βββ feature_pipeline_causal.pkl # Feature pipeline metadata
βββ plots/
β βββ health_forecast.png # Past + Future forecast
β βββ error_growth.png # Error vs horizon
β βββ model_simplicity.png # Performance vs complexity
βββ data/
βββ nasa_model_validation.csv # Cycle-by-cycle validation
βββ failure_cases.csv # Worst prediction cases
Key Features
1. Causal Features Only
All features use only data β€ current cycle:
- β
cycles_from_start(past cycles) - β
soh_rolling_mean_5(backward window only) - β
cycles_to_end(REMOVED - used future data)
2. Transparent Reporting
- Full feature audit report
- Uncertainty methodology documented
- Failure cases identified
- Honest RΒ² scores (even if lower after fixing leakage)
3. Production-Ready
- FastAPI service with CORS
- Error handling
- Data validation
- Health checks
- Base64 image serving for PDFs
Integration with Frontend
Monitor App (OnboardingFlow.tsx)
const response = await fetch('http://localhost:8000/api/predict', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
data: bmsData,
forecast_horizons: [10, 50, 100]
})
});
const predictions = await response.json();
// Use: predictions.health_score, predictions.remaining_life, etc.
PDF Reports (pdfReportGenerator.tsx)
// Get visualization images
const vizResponse = await fetch('http://localhost:8000/api/all-visualizations');
const visualizations = await vizResponse.json();
// Embed in PDF
<Image src={visualizations.visualizations.health_forecast} />
Model Performance
After fixing data leakage:
- Training RΒ²: ~0.998 (on NASA B0005, B0006)
- Validation RΒ²: ~0.95-0.97 (on NASA B0007)
- Honest Reporting: Lower than original 0.998, but validated and credible
Trust Engine Credibility
ZenVolt positions transparency as a differentiator:
- β NASA-trained model
- β Full causality audit (no leakage)
- β Uncertainty quantification
- β Failure case documentation
- β Honest metrics reporting
Credibility > Perfect Numbers
Next Steps
- Train model:
python production_pipeline.py - Generate plots:
python generate_app_visualizations.py - Start API:
python api_service.py - Integrate with frontend apps
- Embed visualizations in PDF reports
License
For research and commercial use within ZenVolt platform.