Update app.py
Browse files
app.py
CHANGED
@@ -70,6 +70,30 @@ def generate_pdf_report(image, results_dict, summary_text):
|
|
70 |
pdf.output(output_path)
|
71 |
return output_path
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
# Gradio UI (app launcher)
|
74 |
def app():
|
75 |
def process(image):
|
@@ -85,23 +109,7 @@ def app():
|
|
85 |
heart_rate = estimate_heart_rate(frame_rgb, landmarks)
|
86 |
spo2, rr = estimate_spo2_rr(heart_rate)
|
87 |
|
88 |
-
results_dict =
|
89 |
-
'Hemoglobin': 12.3,
|
90 |
-
'WBC Count': 6.4,
|
91 |
-
'Platelets': 210,
|
92 |
-
'Iron': 55,
|
93 |
-
'Ferritin': 45,
|
94 |
-
'TIBC': 340,
|
95 |
-
'Bilirubin': 1.5,
|
96 |
-
'Creatinine': 1.3,
|
97 |
-
'TSH': 2.5,
|
98 |
-
'Cortisol': 18,
|
99 |
-
'Fasting Blood Sugar': 120,
|
100 |
-
'HbA1c': 6.2,
|
101 |
-
'SpO2': spo2,
|
102 |
-
'Heart Rate': heart_rate,
|
103 |
-
'Respiratory Rate': rr
|
104 |
-
}
|
105 |
|
106 |
summary_text = "<li>Your hemoglobin is a bit low...</li><li>Consider iron tests.</li>" # Placeholder
|
107 |
pdf_path = generate_pdf_report(image, results_dict, summary_text)
|
|
|
70 |
pdf.output(output_path)
|
71 |
return output_path
|
72 |
|
73 |
+
def infer_lab_results(image, landmarks):
|
74 |
+
h, w, _ = image.shape
|
75 |
+
forehead = image[int(0.1*h):int(0.25*h), int(0.35*w):int(0.65*w)]
|
76 |
+
mean_intensity = np.mean(cv2.cvtColor(forehead, cv2.COLOR_BGR2GRAY))
|
77 |
+
skin_redness = np.mean(image[:, :, 2]) - np.mean(image[:, :, 1])
|
78 |
+
|
79 |
+
return {
|
80 |
+
'Hemoglobin': round(10 + (mean_intensity / 255.0) * 7, 1),
|
81 |
+
'WBC Count': round(4 + (1 - mean_intensity / 255.0) * 7, 1),
|
82 |
+
'Platelets': int(150 + (mean_intensity / 255.0) * 150),
|
83 |
+
'Iron': round(40 + (skin_redness / 50.0) * 40, 1),
|
84 |
+
'Ferritin': round(25 + (skin_redness / 50.0) * 70, 1),
|
85 |
+
'TIBC': round(250 + ((255 - mean_intensity) / 255.0) * 150, 1),
|
86 |
+
'Bilirubin': round(0.5 + (255 - mean_intensity) / 255.0 * 1.5, 2),
|
87 |
+
'Creatinine': round(0.8 + (skin_redness / 255.0) * 0.6, 2),
|
88 |
+
'TSH': round(1.0 + (skin_redness / 255.0) * 2.0, 2),
|
89 |
+
'Cortisol': round(12 + (skin_redness / 255.0) * 10, 2),
|
90 |
+
'Fasting Blood Sugar': int(80 + (skin_redness / 255.0) * 60),
|
91 |
+
'HbA1c': round(5.0 + (skin_redness / 255.0) * 1.5, 2),
|
92 |
+
'SpO2': round(97 - (255 - mean_intensity) / 255.0 * 5, 1),
|
93 |
+
'Heart Rate': estimate_heart_rate(image, landmarks),
|
94 |
+
'Respiratory Rate': estimate_spo2_rr(estimate_heart_rate(image, landmarks))[1]
|
95 |
+
}
|
96 |
+
|
97 |
# Gradio UI (app launcher)
|
98 |
def app():
|
99 |
def process(image):
|
|
|
109 |
heart_rate = estimate_heart_rate(frame_rgb, landmarks)
|
110 |
spo2, rr = estimate_spo2_rr(heart_rate)
|
111 |
|
112 |
+
results_dict = infer_lab_results(frame_rgb, landmarks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
summary_text = "<li>Your hemoglobin is a bit low...</li><li>Consider iron tests.</li>" # Placeholder
|
115 |
pdf_path = generate_pdf_report(image, results_dict, summary_text)
|