Spaces:
Sleeping
Sleeping
File size: 5,123 Bytes
991ba9c |
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# Energy ML API Documentation
## Overview
This API provides machine learning predictions for industrial energy management with three separate endpoints for different models.
## Base URL
```
https://your-space-name.hf.space
```
## Endpoints
### 1. Energy Prediction - Random Forest
**Endpoint:** `/api/predict` (Tab 0)
**Method:** POST
**Description:** Predicts daily average energy consumption using Random Forest
#### Request Body
```json
[
{
"data": "2025-01-01",
"boosting": 0.0,
"cor": "incolor",
"espessura": 8.0,
"extracao_forno": 750.0,
"porcentagem_caco": 15.0,
"extracao_boosting": 1.5
}
]
```
#### Response
```json
[
{
"data": "01-01-2025",
"predicted_energy": 5.234,
"note": "Add boosting energy separately to get final consumption"
}
]
```
### 2. Energy Prediction - XGBoost
**Endpoint:** `/api/predict` (Tab 1)
**Method:** POST
**Description:** Predicts daily average energy consumption using XGBoost (best model)
#### Request Body
```json
[
{
"data": "2025-01-01",
"boosting": 0.0,
"cor": "incolor",
"espessura": 8.0,
"extracao_forno": 750.0,
"porcentagem_caco": 15.0,
"extracao_boosting": 1.5
}
]
```
#### Response
```json
[
{
"data": "01-01-2025",
"predicted_energy": 5.187,
"note": "Add boosting energy separately to get final consumption"
}
]
```
### 3. Threshold Detection
**Endpoint:** `/api/predict` (Tab 2)
**Method:** POST
**Description:** Predicts probability of exceeding 8300 and 9000 consumption thresholds
#### Request Body
```json
{
"data": "2025-01-01",
"cor": "incolor",
"espessura": 8.0,
"ext_boosting": 1.5,
"extracao_forno": 750.0,
"porcentagem_caco": 15.0,
"prod_e": 1,
"prod_l": 0,
"autoclave": 1
}
```
#### Response
```json
{
"predictions": {
"prediction_1": [
{
"datetime": "2025-01-01",
"threshold": 8300,
"probabilidade_de_estouro": 0.1234,
"estouro_previsto": 0
}
],
"prediction_2": [
{
"datetime": "2025-01-01",
"threshold": 9000,
"probabilidade_de_estouro": 0.0567,
"estouro_previsto": 0
}
]
}
}
```
## Input Parameters
### Energy Prediction Models
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `data` | string | Yes | Date in YYYY-MM-DD format |
| `boosting` | float | Yes | Always set to 0.0 (compatibility) |
| `cor` | string | Yes | Glass color: "incolor", "verde", "cinza", "bronze" |
| `espessura` | float | Yes | Glass thickness (mm) |
| `extracao_forno` | float | Yes | Furnace extraction rate |
| `porcentagem_caco` | float | Yes | Glass cullet percentage (%) |
| `extracao_boosting` | float | Yes | External boosting parameter |
### Threshold Detection Model
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `data` | string | Yes | Date in YYYY-MM-DD format |
| `cor` | string | Yes | Glass color: "incolor", "verde", "cinza", "bronze" |
| `espessura` | float | Yes | Glass thickness (mm) |
| `ext_boosting` | float | Yes | External boosting parameter |
| `extracao_forno` | float | Yes | Furnace extraction rate |
| `porcentagem_caco` | float | Yes | Glass cullet percentage (%) |
| `prod_e` | int | Yes | Production E (0 or 1) |
| `prod_l` | int | Yes | Production L (0 or 1) |
| `autoclave` | int | Yes | Autoclave usage (0 or 1) |
## Usage Examples
### Python
```python
import requests
import json
# Energy Prediction (XGBoost)
url = "https://your-space-name.hf.space/api/predict"
headers = {"Content-Type": "application/json"}
data = [
{
"data": "2025-01-01",
"boosting": 0.0,
"cor": "verde",
"espessura": 10.0,
"extracao_forno": 849.0,
"porcentagem_caco": 45.0,
"extracao_boosting": 54.0
}
]
response = requests.post(url, json=data, headers=headers)
prediction = response.json()
print(f"Predicted energy: {prediction[0]['predicted_energy']} MWh")
```
### cURL
```bash
# Threshold Detection
curl -X POST https://your-space-name.hf.space/api/predict \
-H "Content-Type: application/json" \
-d '{
"data": "2025-01-01",
"cor": "incolor",
"espessura": 8.0,
"ext_boosting": 1.5,
"extracao_forno": 750.0,
"porcentagem_caco": 15.0,
"prod_e": 1,
"prod_l": 0,
"autoclave": 1
}'
```
## Model Performance
- **Random Forest Energy**: R² = 0.50, MAE = 0.24 MWh
- **XGBoost Energy**: R² = 0.53, MAE = 0.24 MWh (recommended)
- **Threshold Detection**: 98.9% accuracy (8300), 100% accuracy (9000)
## Notes
- **Energy models predict base consumption** - add actual boosting energy separately
- **No temporal features** - models work for any date/time period
- **Real-time prediction** - sub-second response times
- **Batch processing** - energy models accept arrays of inputs
- **Threshold models** output probabilities (0-1) and binary predictions (>0.5)
## Error Handling
- Invalid JSON: Returns error message
- Missing parameters: Uses default values where possible
- Model errors: Returns error description with context |