AlyMaged commited on
Commit
f89035d
Β·
verified Β·
1 Parent(s): d15722a
Files changed (1) hide show
  1. app/main.py +6 -4
app/main.py CHANGED
@@ -35,13 +35,15 @@ async def predict(request: Request):
35
  # soil_raw, air_temp, soil_temp, humidity = data["data"]
36
  # soil_pct = round(((1023 - soil_raw) / 1023) * 100 ,2)
37
  # features = np.array([[soil_pct, air_temp, soil_temp, humidity]])
38
- features = np.array([[soil_pct, soil_temp, air_temp, humidity]])
 
39
  scaled = scaler.transform(features)
40
  prediction = (model.predict(scaled) > 0.5).astype(int)
41
  result = "Needs Watering πŸ’§" if prediction[0] == 1 else "No Water Needed 🌿"
42
 
43
  print("πŸ” Prediction:", prediction[0], "-", result)
44
-
 
45
  # Log to prediction_logs/{timestamp}
46
  timestamp = str(int(time.time()))
47
  try:
@@ -50,7 +52,7 @@ async def predict(request: Request):
50
  "airTemperature": air_temp,
51
  "soilTemperature": soil_temp,
52
  "airHumidity": humidity,
53
- "prediction": prediction[0]
54
  })
55
  print("πŸ“€ Logged to prediction_logs.")
56
  except Exception as log_error:
@@ -58,7 +60,7 @@ async def predict(request: Request):
58
 
59
  # Update last_prediction
60
  try:
61
- db.reference("last_prediction").set(prediction[0])
62
  print("πŸ“€ last_prediction updated.")
63
  except Exception as lp_error:
64
  print("❌ Error writing last_prediction:", lp_error)
 
35
  # soil_raw, air_temp, soil_temp, humidity = data["data"]
36
  # soil_pct = round(((1023 - soil_raw) / 1023) * 100 ,2)
37
  # features = np.array([[soil_pct, air_temp, soil_temp, humidity]])
38
+ # features = np.array([[soil_pct, soil_temp, air_temp, humidity]])
39
+ features = np.array([[soil_pct, air_temp, soil_temp, humidity]])
40
  scaled = scaler.transform(features)
41
  prediction = (model.predict(scaled) > 0.5).astype(int)
42
  result = "Needs Watering πŸ’§" if prediction[0] == 1 else "No Water Needed 🌿"
43
 
44
  print("πŸ” Prediction:", prediction[0], "-", result)
45
+ prediction_value = int(prediction[0])
46
+
47
  # Log to prediction_logs/{timestamp}
48
  timestamp = str(int(time.time()))
49
  try:
 
52
  "airTemperature": air_temp,
53
  "soilTemperature": soil_temp,
54
  "airHumidity": humidity,
55
+ "prediction": prediction_value
56
  })
57
  print("πŸ“€ Logged to prediction_logs.")
58
  except Exception as log_error:
 
60
 
61
  # Update last_prediction
62
  try:
63
+ db.reference("last_prediction").set(prediction_value)
64
  print("πŸ“€ last_prediction updated.")
65
  except Exception as lp_error:
66
  print("❌ Error writing last_prediction:", lp_error)