Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- backend/patient_history.db +0 -0
- frontend/Home.py +4 -0
- frontend/pages/2_Data_Analytics.py +2 -0
- seed_db.py +66 -0
backend/patient_history.db
CHANGED
|
Binary files a/backend/patient_history.db and b/backend/patient_history.db differ
|
|
|
frontend/Home.py
CHANGED
|
@@ -7,6 +7,10 @@ import plotly.graph_objects as go
|
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
API_URL = os.getenv("API_URL", "http://localhost:8000")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
st.set_page_config(page_title="TinyML Heart Health Monitoring", page_icon="π«", layout="wide")
|
| 12 |
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
API_URL = os.getenv("API_URL", "http://localhost:8000")
|
| 10 |
+
if "hf.space" in os.getenv("SPACE_ID", ""):
|
| 11 |
+
# On HF Spaces, the backend might be on a subpath or the same port
|
| 12 |
+
# But for this setup, we assume it's running on localhost:8000 internally as per app.py
|
| 13 |
+
API_URL = "http://localhost:8000"
|
| 14 |
|
| 15 |
st.set_page_config(page_title="TinyML Heart Health Monitoring", page_icon="π«", layout="wide")
|
| 16 |
|
frontend/pages/2_Data_Analytics.py
CHANGED
|
@@ -10,6 +10,8 @@ st.set_page_config(page_title="Advanced Analytics", page_icon="π", layout="wi
|
|
| 10 |
st.title("π Population Analytics Deep Dive")
|
| 11 |
|
| 12 |
API_URL = os.getenv("API_URL", "http://localhost:8000")
|
|
|
|
|
|
|
| 13 |
|
| 14 |
@st.cache_data(ttl=3600)
|
| 15 |
def load_data():
|
|
|
|
| 10 |
st.title("π Population Analytics Deep Dive")
|
| 11 |
|
| 12 |
API_URL = os.getenv("API_URL", "http://localhost:8000")
|
| 13 |
+
if "hf.space" in os.getenv("SPACE_ID", ""):
|
| 14 |
+
API_URL = "http://localhost:8000"
|
| 15 |
|
| 16 |
@st.cache_data(ttl=3600)
|
| 17 |
def load_data():
|
seed_db.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from datetime import datetime, timedelta
|
| 5 |
+
|
| 6 |
+
DB_NAME = 'patient_history.db'
|
| 7 |
+
DB_PATH = os.path.join('backend', DB_NAME)
|
| 8 |
+
|
| 9 |
+
def seed_data():
|
| 10 |
+
if not os.path.exists('backend'):
|
| 11 |
+
os.makedirs('backend')
|
| 12 |
+
|
| 13 |
+
conn = sqlite3.connect(DB_PATH)
|
| 14 |
+
cursor = conn.cursor()
|
| 15 |
+
|
| 16 |
+
# Ensure table exists
|
| 17 |
+
cursor.execute('''
|
| 18 |
+
CREATE TABLE IF NOT EXISTS predictions (
|
| 19 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 20 |
+
timestamp DATETIME,
|
| 21 |
+
heart_rate REAL,
|
| 22 |
+
spo2 REAL,
|
| 23 |
+
sys_bp REAL,
|
| 24 |
+
dia_bp REAL,
|
| 25 |
+
temp REAL,
|
| 26 |
+
fall_detection TEXT,
|
| 27 |
+
prediction_label TEXT,
|
| 28 |
+
confidence REAL
|
| 29 |
+
)
|
| 30 |
+
''')
|
| 31 |
+
|
| 32 |
+
# Sample data generation
|
| 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)
|
| 42 |
+
spo2 = round(random.uniform(92, 99), 1)
|
| 43 |
+
sys = round(random.uniform(110, 150), 1)
|
| 44 |
+
dia = round(random.uniform(70, 95), 1)
|
| 45 |
+
temp = round(random.uniform(36.1, 37.8), 1)
|
| 46 |
+
fall = random.choice(fall_options) if hr > 100 else "No Fall"
|
| 47 |
+
|
| 48 |
+
# Simple logic for label
|
| 49 |
+
if hr > 100 or spo2 < 94 or sys > 140:
|
| 50 |
+
label = "At Risk"
|
| 51 |
+
conf = random.uniform(0.7, 0.95)
|
| 52 |
+
else:
|
| 53 |
+
label = "Healthy"
|
| 54 |
+
conf = random.uniform(0.85, 0.99)
|
| 55 |
+
|
| 56 |
+
cursor.execute('''
|
| 57 |
+
INSERT INTO predictions (timestamp, heart_rate, spo2, sys_bp, dia_bp, temp, fall_detection, prediction_label, confidence)
|
| 58 |
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 59 |
+
''', (timestamp, hr, spo2, sys, dia, temp, fall, label, conf))
|
| 60 |
+
|
| 61 |
+
conn.commit()
|
| 62 |
+
conn.close()
|
| 63 |
+
print("Done seeding.")
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
seed_data()
|