Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -137,6 +137,7 @@ def analyze_face(image):
|
|
137 |
features = extract_features(frame_rgb, landmarks)
|
138 |
test_values = {}
|
139 |
r2_scores = {}
|
|
|
140 |
for label in models:
|
141 |
if label == "Hemoglobin":
|
142 |
prediction = models[label].predict([features])[0]
|
@@ -146,6 +147,7 @@ def analyze_face(image):
|
|
146 |
value = models[label].predict([[random.uniform(0.2, 0.5) for _ in range(7)]])[0]
|
147 |
test_values[label] = value
|
148 |
r2_scores[label] = 0.0 # simulate other 7D inputs
|
|
|
149 |
gray = cv2.cvtColor(frame_rgb, cv2.COLOR_RGB2GRAY)
|
150 |
green_std = np.std(frame_rgb[:, :, 1]) / 255
|
151 |
brightness_std = np.std(gray) / 255
|
@@ -158,17 +160,32 @@ def analyze_face(image):
|
|
158 |
spo2_features = [heart_rate, brightness_variation, skin_tone_index]
|
159 |
spo2 = spo2_model.predict([spo2_features])[0]
|
160 |
rr = int(12 + abs(heart_rate % 5 - 2))
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
summary = "<ul><li>Your hemoglobin is a bit low — this could mean mild anemia.</li><li>Low iron storage detected — consider an iron profile test.</li><li>Elevated bilirubin — possible jaundice. Recommend LFT.</li><li>High HbA1c — prediabetes indication. Recommend glucose check.</li><li>Low SpO₂ — suggest retesting with a pulse oximeter.</li></ul>"
|
170 |
-
|
171 |
-
|
|
|
172 |
return health_card_html
|
173 |
|
174 |
# Create Gradio interface
|
|
|
137 |
features = extract_features(frame_rgb, landmarks)
|
138 |
test_values = {}
|
139 |
r2_scores = {}
|
140 |
+
|
141 |
for label in models:
|
142 |
if label == "Hemoglobin":
|
143 |
prediction = models[label].predict([features])[0]
|
|
|
147 |
value = models[label].predict([[random.uniform(0.2, 0.5) for _ in range(7)]])[0]
|
148 |
test_values[label] = value
|
149 |
r2_scores[label] = 0.0 # simulate other 7D inputs
|
150 |
+
|
151 |
gray = cv2.cvtColor(frame_rgb, cv2.COLOR_RGB2GRAY)
|
152 |
green_std = np.std(frame_rgb[:, :, 1]) / 255
|
153 |
brightness_std = np.std(gray) / 255
|
|
|
160 |
spo2_features = [heart_rate, brightness_variation, skin_tone_index]
|
161 |
spo2 = spo2_model.predict([spo2_features])[0]
|
162 |
rr = int(12 + abs(heart_rate % 5 - 2))
|
163 |
+
|
164 |
+
# Prepare the test results
|
165 |
+
test_results = {
|
166 |
+
"Hematology": build_table("🩸 Hematology", [("Hemoglobin", test_values["Hemoglobin"], (13.5, 17.5)),
|
167 |
+
("WBC Count", test_values["WBC Count"], (4.0, 11.0)),
|
168 |
+
("Platelet Count", test_values["Platelet Count"], (150, 450))]),
|
169 |
+
"Iron Panel": build_table("🧬 Iron Panel", [("Iron", test_values["Iron"], (60, 170)),
|
170 |
+
("Ferritin", test_values["Ferritin"], (30, 300)),
|
171 |
+
("TIBC", test_values["TIBC"], (250, 400))]),
|
172 |
+
"Liver & Kidney": build_table("🧬 Liver & Kidney", [("Bilirubin", test_values["Bilirubin"], (0.3, 1.2)),
|
173 |
+
("Creatinine", test_values["Creatinine"], (0.6, 1.2)),
|
174 |
+
("Urea", test_values["Urea"], (7, 20))]),
|
175 |
+
"Electrolytes": build_table("🧪 Electrolytes", [("Sodium", test_values["Sodium"], (135, 145)),
|
176 |
+
("Potassium", test_values["Potassium"], (3.5, 5.1))]),
|
177 |
+
"Vitals": build_table("❤️ Vitals", [("SpO2", spo2, (95, 100)),
|
178 |
+
("Heart Rate", heart_rate, (60, 100)),
|
179 |
+
("Respiratory Rate", rr, (12, 20)),
|
180 |
+
("Temperature", test_values["Temperature"], (97, 99)),
|
181 |
+
("BP Systolic", test_values["BP Systolic"], (90, 120)),
|
182 |
+
("BP Diastolic", test_values["BP Diastolic"], (60, 80))])
|
183 |
+
}
|
184 |
+
|
185 |
summary = "<ul><li>Your hemoglobin is a bit low — this could mean mild anemia.</li><li>Low iron storage detected — consider an iron profile test.</li><li>Elevated bilirubin — possible jaundice. Recommend LFT.</li><li>High HbA1c — prediabetes indication. Recommend glucose check.</li><li>Low SpO₂ — suggest retesting with a pulse oximeter.</li></ul>"
|
186 |
+
|
187 |
+
# Generate Health Card HTML
|
188 |
+
health_card_html = build_health_card("profile_image_placeholder_base64", test_results, summary)
|
189 |
return health_card_html
|
190 |
|
191 |
# Create Gradio interface
|