SuriRaja commited on
Commit
86ac17e
·
verified ·
1 Parent(s): 15091ab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -0
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import tempfile
5
+ import cv2
6
+ import os
7
+
8
+ st.set_page_config(page_title="AI Health Lab", layout="wide")
9
+
10
+ st.title("🧬 Face-based Health Lab")
11
+ st.markdown("Upload a **facial image** (for Hb) and a **20-30 s face video** (for HR).\n\n"
12
+ "This is a baseline app – models will be added for each test step-by-step.")
13
+
14
+ # -------------------------------------------------
15
+ # Sidebar instructions
16
+ # -------------------------------------------------
17
+ st.sidebar.header("Instructions")
18
+ st.sidebar.info(
19
+ "1. Upload a good quality **face / eye image** for Hemoglobin.\n"
20
+ "2. Upload a **20-30 s face video** for Heart-Rate.\n"
21
+ "3. Click **Run Analysis** to see test results.\n\n"
22
+ "Later we will add more tests and replace the dummy predictions with real models."
23
+ )
24
+
25
+ # -------------------------------------------------
26
+ # Input widgets
27
+ # -------------------------------------------------
28
+ uploaded_img = st.file_uploader("Upload Face / Eye Image for Hemoglobin", type=["jpg","jpeg","png"])
29
+ uploaded_vid = st.file_uploader("Upload Face Video for Heart-Rate (20-30 s)", type=["mp4","avi","mov"])
30
+
31
+ run_btn = st.button("Run Analysis")
32
+
33
+ # -------------------------------------------------
34
+ # Placeholder prediction functions
35
+ # -------------------------------------------------
36
+ def predict_hemoglobin(image: np.ndarray) -> float:
37
+ # TODO: replace with actual Hb model
38
+ return float(np.random.uniform(11.0,15.0))
39
+
40
+ def predict_heart_rate(video_path: str) -> float:
41
+ # TODO: replace with real rPPG inference
42
+ return float(np.random.uniform(65,85))
43
+
44
+ # -------------------------------------------------
45
+ # Run inference
46
+ # -------------------------------------------------
47
+ if run_btn:
48
+ results = []
49
+
50
+ # ---- Hemoglobin ----
51
+ if uploaded_img is not None:
52
+ file_bytes = np.asarray(bytearray(uploaded_img.read()), dtype=np.uint8)
53
+ img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
54
+ hb = predict_hemoglobin(img)
55
+ results.append({"Test": "Hemoglobin", "Result": f"{hb:.2f} g/dL"})
56
+ else:
57
+ results.append({"Test": "Hemoglobin", "Result": "No image uploaded"})
58
+
59
+ # ---- Heart Rate ----
60
+ if uploaded_vid is not None:
61
+ # save video temporarily
62
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmpf:
63
+ tmpf.write(uploaded_vid.read())
64
+ tmp_path = tmpf.name
65
+
66
+ hr = predict_heart_rate(tmp_path)
67
+ results.append({"Test": "Heart Rate", "Result": f"{hr:.1f} bpm"})
68
+
69
+ # clean up
70
+ os.remove(tmp_path)
71
+ else:
72
+ results.append({"Test": "Heart Rate", "Result": "No video uploaded"})
73
+
74
+ # ---- Future tests placeholders ----
75
+ results.append({"Test": "SpO₂", "Result": "—"})
76
+ results.append({"Test": "Respiration Rate", "Result": "—"})
77
+ # ... add more as needed later
78
+
79
+ # -------------------------------------------------
80
+ # Show results table
81
+ # -------------------------------------------------
82
+ df = pd.DataFrame(results)
83
+ st.subheader("🩺 Test Results")
84
+ st.table(df)
85
+
86
+ else:
87
+ st.info("⬆ Upload image and/or video, then click **Run Analysis**.")