IDKHowToCodeFr commited on
Commit
72f5b06
·
verified ·
1 Parent(s): f511ff7

Upload folder using huggingface_hub

Browse files
backend/database.py CHANGED
@@ -82,11 +82,13 @@ async def init_db() -> None:
82
 
83
  async def log_prediction(data: Any, prediction_label: str, confidence: float) -> None:
84
  async with aiosqlite.connect(DB_PATH) as db:
 
 
85
  await db.execute('''
86
  INSERT INTO predictions (timestamp, heart_rate, spo2, sys_bp, dia_bp, temp, fall_detection, prediction_label, confidence)
87
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
88
  ''', (
89
- datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"),
90
  data.Heart_Rate,
91
  data.SpO2_Level,
92
  data.Systolic_BP,
 
82
 
83
  async def log_prediction(data: Any, prediction_label: str, confidence: float) -> None:
84
  async with aiosqlite.connect(DB_PATH) as db:
85
+ from datetime import timezone, timedelta
86
+ ist = timezone(timedelta(hours=5, minutes=30))
87
  await db.execute('''
88
  INSERT INTO predictions (timestamp, heart_rate, spo2, sys_bp, dia_bp, temp, fall_detection, prediction_label, confidence)
89
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
90
  ''', (
91
+ datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S"),
92
  data.Heart_Rate,
93
  data.SpO2_Level,
94
  data.Systolic_BP,
backend/ensemble.py CHANGED
@@ -50,4 +50,8 @@ class EnsembleModel:
50
  for i, prob in enumerate(weighted_probs)
51
  }
52
 
53
- return final_pred, confidence, individual_preds, class_probs, self.weights
 
 
 
 
 
50
  for i, prob in enumerate(weighted_probs)
51
  }
52
 
53
+ individual_conf = {
54
+ name: float(np.max(probs)) for name, probs in individual_probs.items()
55
+ }
56
+
57
+ return final_pred, confidence, individual_preds, class_probs, self.weights, individual_conf
backend/inference.py CHANGED
@@ -31,7 +31,7 @@ def evaluate(ensemble_model, data) -> Dict[str, Any]:
31
  return {"error": "Ensemble model not loaded"}
32
 
33
  # Ensemble Prediction
34
- disease_label, conf, ind_preds, class_probs, weights = ensemble_model.predict(processed_df)
35
  is_at_risk = (disease_label.lower() not in ["healthy", "normal", "none"])
36
 
37
  return {
@@ -40,6 +40,7 @@ def evaluate(ensemble_model, data) -> Dict[str, Any]:
40
  "probability": float(conf),
41
  "ensemble_prediction": is_at_risk,
42
  "model_outputs": ind_preds,
 
43
  "disease_probs": class_probs,
44
  "weights": weights
45
  }
 
31
  return {"error": "Ensemble model not loaded"}
32
 
33
  # Ensemble Prediction
34
+ disease_label, conf, ind_preds, class_probs, weights, ind_conf = ensemble_model.predict(processed_df)
35
  is_at_risk = (disease_label.lower() not in ["healthy", "normal", "none"])
36
 
37
  return {
 
40
  "probability": float(conf),
41
  "ensemble_prediction": is_at_risk,
42
  "model_outputs": ind_preds,
43
+ "model_probs": ind_conf,
44
  "disease_probs": class_probs,
45
  "weights": weights
46
  }
backend/main.py CHANGED
@@ -77,8 +77,11 @@ def health_check():
77
 
78
  def log_alert_sync(data: PatientData, conf: float):
79
  try:
 
 
 
80
  with open("alerts.log", "a") as f:
81
- f.write(f"ALERT: Patient at risk! HR: {data.Heart_Rate}, SpO2: {data.SpO2_Level}, Confidence: {conf:.2f}\n")
82
  except Exception:
83
  pass
84
 
 
77
 
78
  def log_alert_sync(data: PatientData, conf: float):
79
  try:
80
+ from datetime import datetime, timezone, timedelta
81
+ ist = timezone(timedelta(hours=5, minutes=30))
82
+ timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S")
83
  with open("alerts.log", "a") as f:
84
+ f.write(f"[{timestamp}] ALERT: Patient at risk! HR: {data.Heart_Rate}, SpO2: {data.SpO2_Level}, Confidence: {conf:.2f}\n")
85
  except Exception:
86
  pass
87