File size: 3,603 Bytes
7690851
 
 
1538836
 
7690851
 
 
 
 
 
 
 
 
52f3cd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7690851
 
52f3cd7
 
7690851
 
 
 
 
921c0d5
52f3cd7
 
7690851
 
 
52f3cd7
 
 
 
 
7690851
 
 
 
 
 
 
 
 
 
 
52f3cd7
7690851
52f3cd7
 
7690851
 
 
 
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
---
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

- **Anomaly Detection**: Isolation Forest + LSTM Autoencoder
- **Failure Forecasting**: XGBoost models for time-to-failure and failure probability
- **AI Diagnosis**: Gemini LLM provides maintenance recommendations
- **REST API**: FastAPI-based service with automatic documentation

## 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],
  "api_key": "your_google_api_key_here",
  "asset_id": "PV_INVERTER_001"
}
```

**Parameters:**
- `vdc1`, `idc1`: Voltage and current sensor readings
- `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",
    "failure_probability": 0.12,
    "expected_ttf_days": 450.5,
    "expected_rul_days": 9800.0,
    "confidence": 0.85
  },
  "agent_output": {
    "diagnosis": "Minor voltage fluctuations detected...",
    "urgency": "Low",
    "recommended_action": "Continue monitoring...",
    "justification": ["Voltage within range", "Current stable"]
  }
}
```

### Data Processing Pipeline

1. **Input Validation**: Ensures voltage/current arrays match and contain sufficient data points
2. **Data Preparation**: Pads input to 100 data points for consistent processing
3. **Feature Engineering**: Creates 7 statistical features using rolling window analysis:
   - Voltage mean/standard deviation
   - Power mean/standard deviation
   - Power delta and slope
   - Normalized efficiency
4. **ML Inference**: Processes features through anomaly detection and prediction models
5. **Agent Analysis**: LLM analyzes ML results for human-readable 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],
    "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