Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,6 +75,37 @@ def health():
|
|
| 75 |
@app.post("/predict")
|
| 76 |
def predict(data: Features):
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
features = transform_features(data)
|
| 79 |
|
| 80 |
columns = [
|
|
|
|
| 75 |
@app.post("/predict")
|
| 76 |
def predict(data: Features):
|
| 77 |
|
| 78 |
+
if not data.relay:
|
| 79 |
+
# No power → skip prediction
|
| 80 |
+
|
| 81 |
+
appliance = "NoPower"
|
| 82 |
+
confidence = 1.0
|
| 83 |
+
|
| 84 |
+
energy = 0.0 # no energy usage
|
| 85 |
+
|
| 86 |
+
# store in DB
|
| 87 |
+
supabase.table("energy_logs").insert({
|
| 88 |
+
"timestamp": datetime.utcnow().isoformat(),
|
| 89 |
+
"appliance": appliance,
|
| 90 |
+
"confidence": confidence,
|
| 91 |
+
"mean": data.mean,
|
| 92 |
+
"max": data.max,
|
| 93 |
+
"min": data.min,
|
| 94 |
+
"std": data.std,
|
| 95 |
+
"range": data.range,
|
| 96 |
+
"peak_count": data.peak_count,
|
| 97 |
+
"slope": data.slope,
|
| 98 |
+
"energy": energy,
|
| 99 |
+
"power": 0.0,
|
| 100 |
+
"relay": data.relay
|
| 101 |
+
}).execute()
|
| 102 |
+
|
| 103 |
+
return {
|
| 104 |
+
"appliance": appliance,
|
| 105 |
+
"confidence": confidence,
|
| 106 |
+
"relay": data.relay
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
features = transform_features(data)
|
| 110 |
|
| 111 |
columns = [
|