IDKHowToCodeFr commited on
Commit
d4454fd
·
verified ·
1 Parent(s): 244a440

Upload folder using huggingface_hub

Browse files
backend/database.py CHANGED
@@ -65,7 +65,7 @@ def log_prediction(data, prediction_label, confidence):
65
  INSERT INTO predictions (timestamp, heart_rate, spo2, sys_bp, dia_bp, temp, fall_detection, prediction_label, confidence)
66
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
67
  ''', (
68
- datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
69
  data.Heart_Rate,
70
  data.SpO2_Level,
71
  data.Systolic_BP,
 
65
  INSERT INTO predictions (timestamp, heart_rate, spo2, sys_bp, dia_bp, temp, fall_detection, prediction_label, confidence)
66
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
67
  ''', (
68
+ datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"),
69
  data.Heart_Rate,
70
  data.SpO2_Level,
71
  data.Systolic_BP,
backend/patient_history.db CHANGED
Binary files a/backend/patient_history.db and b/backend/patient_history.db differ
 
frontend/pages/4_Patient_History.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import requests
3
  import pandas as pd
4
  import os
 
5
 
6
  st.set_page_config(page_title="Patient History", page_icon="🗄️", layout="wide")
7
  API_URL = os.getenv("API_URL", "http://localhost:8000")
@@ -9,7 +10,15 @@ if "hf.space" in os.getenv("SPACE_ID", ""):
9
  API_URL = "http://localhost:8000"
10
 
11
  st.title("🗄️ Patient Prediction History")
12
- st.markdown("Live database of all patient predictions and vitals logged by the system. Auto-refreshes every 5 seconds.")
 
 
 
 
 
 
 
 
13
 
14
  DISEASE_COLORS = {
15
  "Healthy": "background-color: rgba(0, 204, 150, 0.15); color: #00cc96;",
@@ -43,6 +52,9 @@ def live_history_table():
43
  return
44
 
45
  df = pd.DataFrame(history_data)
 
 
 
46
  cols = ['id', 'timestamp', 'prediction_label', 'confidence', 'heart_rate', 'spo2', 'sys_bp', 'dia_bp', 'temp', 'fall_detection']
47
  df = df[[c for c in cols if c in df.columns]]
48
  df.rename(columns=COLUMN_RENAME, inplace=True)
 
2
  import requests
3
  import pandas as pd
4
  import os
5
+ from datetime import datetime, timedelta
6
 
7
  st.set_page_config(page_title="Patient History", page_icon="🗄️", layout="wide")
8
  API_URL = os.getenv("API_URL", "http://localhost:8000")
 
10
  API_URL = "http://localhost:8000"
11
 
12
  st.title("🗄️ Patient Prediction History")
13
+ st.markdown("Live database of all patient predictions and vitals logged by the system. Times shown in **IST (UTC+5:30)**.")
14
+
15
+ def convert_to_ist(utc_time_str):
16
+ try:
17
+ utc_dt = datetime.strptime(utc_time_str, "%Y-%m-%d %H:%M:%S")
18
+ ist_dt = utc_dt + timedelta(hours=5, minutes=30)
19
+ return ist_dt.strftime("%Y-%m-%d %H:%M:%S")
20
+ except:
21
+ return utc_time_str
22
 
23
  DISEASE_COLORS = {
24
  "Healthy": "background-color: rgba(0, 204, 150, 0.15); color: #00cc96;",
 
52
  return
53
 
54
  df = pd.DataFrame(history_data)
55
+ if "timestamp" in df.columns:
56
+ df["timestamp"] = df["timestamp"].apply(convert_to_ist)
57
+
58
  cols = ['id', 'timestamp', 'prediction_label', 'confidence', 'heart_rate', 'spo2', 'sys_bp', 'dia_bp', 'temp', 'fall_detection']
59
  df = df[[c for c in cols if c in df.columns]]
60
  df.rename(columns=COLUMN_RENAME, inplace=True)
seed_db.py CHANGED
@@ -33,9 +33,9 @@ def seed_data():
33
  labels = ["Healthy", "At Risk"]
34
  fall_options = ["No Fall", "Fall Detected"]
35
 
36
- now = datetime.now()
37
 
38
- print("Seeding 30 sample predictions...")
39
  for i in range(30):
40
  timestamp = (now - timedelta(minutes=i*15)).strftime("%Y-%m-%d %H:%M:%S")
41
  hr = round(random.uniform(60, 110), 1)
 
33
  labels = ["Healthy", "At Risk"]
34
  fall_options = ["No Fall", "Fall Detected"]
35
 
36
+ now = datetime.utcnow()
37
 
38
+ print("Seeding 30 sample predictions (UTC)...")
39
  for i in range(30):
40
  timestamp = (now - timedelta(minutes=i*15)).strftime("%Y-%m-%d %H:%M:%S")
41
  hr = round(random.uniform(60, 110), 1)