Update app.py
Browse files
app.py
CHANGED
|
@@ -32,6 +32,10 @@ def train_model(output_range):
|
|
| 32 |
import joblib
|
| 33 |
hemoglobin_model = joblib.load("hemoglobin_model_from_anemia_dataset.pkl")
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
models = {
|
| 36 |
"Hemoglobin": hemoglobin_model,
|
| 37 |
"WBC Count": train_model((4.0, 11.0)),
|
|
@@ -86,15 +90,25 @@ def analyze_face(image):
|
|
| 86 |
landmarks = result.multi_face_landmarks[0].landmark
|
| 87 |
features = extract_features(frame_rgb, landmarks)
|
| 88 |
test_values = {}
|
|
|
|
| 89 |
for label in models:
|
| 90 |
if label == "Hemoglobin":
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
else:
|
| 93 |
-
|
|
|
|
|
|
|
| 94 |
heart_rate = int(60 + 30 * np.sin(np.mean(frame_rgb) / 255.0 * np.pi))
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
rr = int(12 + abs(heart_rate % 5 - 2))
|
| 97 |
html_output = "".join([
|
|
|
|
| 98 |
build_table("🩸 Hematology", [("Hemoglobin", test_values["Hemoglobin"], (13.5, 17.5)), ("WBC Count", test_values["WBC Count"], (4.0, 11.0)), ("Platelet Count", test_values["Platelet Count"], (150, 450))]),
|
| 99 |
build_table("🧬 Iron Panel", [("Iron", test_values["Iron"], (60, 170)), ("Ferritin", test_values["Ferritin"], (30, 300)), ("TIBC", test_values["TIBC"], (250, 400))]),
|
| 100 |
build_table("🧬 Liver & Kidney", [("Bilirubin", test_values["Bilirubin"], (0.3, 1.2)), ("Creatinine", test_values["Creatinine"], (0.6, 1.2)), ("Urea", test_values["Urea"], (7, 20))]),
|
|
|
|
| 32 |
import joblib
|
| 33 |
hemoglobin_model = joblib.load("hemoglobin_model_from_anemia_dataset.pkl")
|
| 34 |
|
| 35 |
+
hemoglobin_r2 = 0.385
|
| 36 |
+
import joblib
|
| 37 |
+
spo2_model = joblib.load("spo2_model_simulated.pkl")
|
| 38 |
+
|
| 39 |
models = {
|
| 40 |
"Hemoglobin": hemoglobin_model,
|
| 41 |
"WBC Count": train_model((4.0, 11.0)),
|
|
|
|
| 90 |
landmarks = result.multi_face_landmarks[0].landmark
|
| 91 |
features = extract_features(frame_rgb, landmarks)
|
| 92 |
test_values = {}
|
| 93 |
+
r2_scores = {}
|
| 94 |
for label in models:
|
| 95 |
if label == "Hemoglobin":
|
| 96 |
+
prediction = models[label].predict([features])[0]
|
| 97 |
+
test_values[label] = prediction
|
| 98 |
+
r2_scores[label] = hemoglobin_r2
|
| 99 |
else:
|
| 100 |
+
value = models[label].predict([[random.uniform(0.2, 0.5) for _ in range(7)]])[0]
|
| 101 |
+
test_values[label] = value
|
| 102 |
+
r2_scores[label] = 0.0 # simulate other 7D inputs
|
| 103 |
heart_rate = int(60 + 30 * np.sin(np.mean(frame_rgb) / 255.0 * np.pi))
|
| 104 |
+
skin_patch = frame_rgb[100:150, 100:150]
|
| 105 |
+
skin_tone_index = np.mean(skin_patch) / 255 if skin_patch.size else 0.5
|
| 106 |
+
brightness_variation = np.std(cv2.cvtColor(frame_rgb, cv2.COLOR_RGB2GRAY)) / 255
|
| 107 |
+
spo2_features = [heart_rate, brightness_variation, skin_tone_index]
|
| 108 |
+
spo2 = spo2_model.predict([spo2_features])[0]
|
| 109 |
rr = int(12 + abs(heart_rate % 5 - 2))
|
| 110 |
html_output = "".join([
|
| 111 |
+
f'<div style="font-size:14px;color:#888;margin-bottom:10px;">Hemoglobin R² Score: {r2_scores.get("Hemoglobin", "NA"):.2f}</div>',
|
| 112 |
build_table("🩸 Hematology", [("Hemoglobin", test_values["Hemoglobin"], (13.5, 17.5)), ("WBC Count", test_values["WBC Count"], (4.0, 11.0)), ("Platelet Count", test_values["Platelet Count"], (150, 450))]),
|
| 113 |
build_table("🧬 Iron Panel", [("Iron", test_values["Iron"], (60, 170)), ("Ferritin", test_values["Ferritin"], (30, 300)), ("TIBC", test_values["TIBC"], (250, 400))]),
|
| 114 |
build_table("🧬 Liver & Kidney", [("Bilirubin", test_values["Bilirubin"], (0.3, 1.2)), ("Creatinine", test_values["Creatinine"], (0.6, 1.2)), ("Urea", test_values["Urea"], (7, 20))]),
|