Spaces:
Sleeping
Sleeping
File size: 5,836 Bytes
7690851 1538836 7690851 52f3cd7 92c73c1 52f3cd7 7690851 52f3cd7 7690851 921c0d5 d8c5e83 52f3cd7 7690851 52f3cd7 d8c5e83 52f3cd7 7690851 92c73c1 7690851 92c73c1 7690851 92c73c1 7690851 52f3cd7 92c73c1 d8c5e83 52f3cd7 92c73c1 52f3cd7 d8c5e83 92c73c1 52f3cd7 d8c5e83 52f3cd7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | ---
title: Solar PV Predictive Maintenance
emoji: ☀️
colorFrom: blue
colorTo: gray
sdk: docker
app_port: 7860
pinned: false
---
# Solar PV Predictive Maintenance API
AI-powered predictive maintenance for solar PV inverters using ML models and LLM-based diagnosis.
## Features
- **Advanced Anomaly Detection**: Isolation Forest + LSTM Autoencoder with reconstruction error analysis
- **Comprehensive Health Monitoring**: Real-time health scoring, anomaly detection, and trend analysis
- **Fault Classification**: Multi-class fault type prediction (Normal, Short Circuit, Degradation, Open Circuit, Shadowing)
- **Predictive Maintenance**: XGBoost models for time-to-failure, remaining useful life, and failure probability
- **AI Diagnosis**: Gemini LLM provides detailed maintenance recommendations with urgency levels
- **REST API**: FastAPI-based service with automatic documentation and validation
## Quick Start
### Installation
```bash
git clone <repository-url>
cd pdm-agent
pip install -r requirements.txt
```
### Environment Setup
Set your Google API key for LLM features:
```bash
export GOOGLE_API_KEY=your_api_key_here
```
### Run
```bash
uvicorn app:app --host 0.0.0.0 --port 7860 --reload
```
## API Usage
### POST /analyze
Analyzes sensor data and returns ML predictions with optional AI diagnosis.
**Request:**
```json
{
"vdc1": [600.0, 601.0, 602.0],
"idc1": [10.0, 10.1, 10.2],
"pvt": [25.0, 25.1, 25.2],
"api_key": "your_google_api_key_here",
"asset_id": "PV_INVERTER_001"
}
```
**Parameters:**
- `vdc1`, `idc1`: Voltage and current sensor readings
- `pvt`: PV temperature readings (required)
- `api_key`: Optional Google API key for AI diagnosis
- `asset_id`: Optional asset identifier (auto-generated if not provided)
**Response:**
```json
{
"ml_output": {
"asset_id": "PV_INVERTER_001",
"health_score": 0.892,
"anomaly_score": 0.0342,
"health_trend_200step": -0.0123,
"failure_probability": 0.12,
"expected_ttf_days": 450.5,
"expected_rul_days": 9800.0,
"predicted_fault_type": "Normal",
"fault_confidence": 0.78,
"confidence": 0.85
},
"agent_output": {
"system_health": {
"status": "Good",
"health_score_explanation": "Health score of 0.892 indicates good system performance at 89% of optimal",
"anomaly_analysis": "Anomaly score of 0.0342 shows normal operation with minimal deviations",
"trend_assessment": "Slight negative trend (-0.0123) suggests gradual performance decline to monitor"
},
"failure_risk": {
"probability_assessment": "12% failure probability within 30 days represents low risk",
"time_to_failure_analysis": "450 days until predicted failure allows time for scheduled maintenance",
"remaining_life_summary": "9,800 days remaining useful life indicates good system longevity"
},
"fault_diagnosis": {
"primary_fault": "System classified as 'Normal' with 78% confidence, no major faults detected",
"confidence_interpretation": "85% overall confidence provides reliable analysis for decision making"
},
"maintenance_recommendations": {
"urgency_level": "Low",
"immediate_actions": [
"Continue routine performance monitoring",
"Schedule panel inspection within 3 months"
],
"monitoring_schedule": "Next comprehensive inspection in 90 days",
"preventive_measures": "Implement quarterly maintenance checks"
},
"key_insights": [
"System health is good but showing early degradation signs",
"No immediate action required, continue standard monitoring",
"Schedule maintenance before 450 days to prevent issues"
]
}
}
```
### Data Processing Pipeline
1. **Input Validation**: Ensures voltage/current/temperature arrays match and contain sufficient data points
2. **Data Preparation**: Filters active periods and downsamples for efficient processing
3. **Feature Engineering**: Creates 10 statistical features using rolling window analysis:
- Voltage mean/standard deviation
- Power mean/standard deviation
- Power delta and slope
- Normalized efficiency
- Temperature mean/standard deviation/delta
4. **ML Inference**:
- Anomaly detection via Isolation Forest + LSTM reconstruction error
- Health scoring and trend analysis
- Fault type classification (5 classes)
- Time-to-failure and remaining useful life prediction
- Failure probability calculation with weighted risk factors
5. **Agent Analysis**: LLM analyzes all ML metrics for comprehensive maintenance diagnosis (if API key provided)
## Configuration
- `GOOGLE_API_KEY`: Required for AI diagnosis features
- Models: Gemini 2.5 Flash Lite, XGBoost, LSTM Autoencoder
- Port: 7860 (configurable)
## Docker
```bash
docker build -t pdm-agent .
docker run -p 7860:7860 -e GOOGLE_API_KEY=your_key pdm-agent
```
## Testing
```bash
# Test the API
curl -X POST "http://localhost:7860/analyze" \
-H "Content-Type: application/json" \
-d '{
"vdc1": [600.0, 601.0, 602.0],
"idc1": [10.0, 10.1, 10.2],
"pvt": [25.0, 25.1, 25.2],
"api_key": "your_api_key",
"asset_id": "PV_INVERTER_001"
}'
```
## 📊 ML Models
### Anomaly Detection
- **Isolation Forest**: Unsupervised outlier detection
- **LSTM Autoencoder**: Sequence-based anomaly scoring
### Predictive Models
- **XGBoost Classifier**: Failure probability prediction
- **XGBoost Regressor**: Time-to-failure estimation
### LLM Agent
- **Gemini 2.5 Flash Lite**: Diagnostic reasoning and recommendations
## 🤝 Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
MIT License
|