Update app.py
Browse files
app.py
CHANGED
@@ -69,3 +69,58 @@ def generate_pdf_report(image, results_dict, summary_text):
|
|
69 |
output_path = "/mnt/data/SL_Diagnostics_Face_Scan_Report.pdf"
|
70 |
pdf.output(output_path)
|
71 |
return output_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
output_path = "/mnt/data/SL_Diagnostics_Face_Scan_Report.pdf"
|
70 |
pdf.output(output_path)
|
71 |
return output_path
|
72 |
+
|
73 |
+
# Gradio UI (app launcher)
|
74 |
+
def app():
|
75 |
+
def process(image):
|
76 |
+
if image is None:
|
77 |
+
return "Please upload a face image.", None, None
|
78 |
+
|
79 |
+
frame_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
80 |
+
result = face_mesh.process(frame_rgb)
|
81 |
+
if not result.multi_face_landmarks:
|
82 |
+
return "Face not detected.", None, None
|
83 |
+
|
84 |
+
landmarks = result.multi_face_landmarks[0].landmark
|
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)
|
108 |
+
|
109 |
+
return "Preview complete. You can download your report.", frame_rgb, pdf_path
|
110 |
+
|
111 |
+
with gr.Blocks() as demo:
|
112 |
+
gr.Markdown("""# 🧠 Face-Based Lab Test AI Report""")
|
113 |
+
with gr.Row():
|
114 |
+
with gr.Column():
|
115 |
+
image = gr.Image(label="📸 Upload Face", type="numpy")
|
116 |
+
button = gr.Button("🔍 Run Analysis")
|
117 |
+
pdf_output = gr.File(label="📄 Download Report")
|
118 |
+
with gr.Column():
|
119 |
+
note = gr.Textbox(label="Status")
|
120 |
+
preview = gr.Image(label="Scan Preview")
|
121 |
+
|
122 |
+
button.click(fn=process, inputs=image, outputs=[note, preview, pdf_output])
|
123 |
+
|
124 |
+
demo.launch()
|
125 |
+
|
126 |
+
app()
|