Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# Face Detection-Based AI Automation of Lab Tests
|
2 |
-
# Redesigned UI using
|
3 |
|
4 |
import gradio as gr
|
5 |
import cv2
|
@@ -28,11 +28,22 @@ def estimate_spo2_rr(heart_rate):
|
|
28 |
def get_risk_color(value, normal_range):
|
29 |
low, high = normal_range
|
30 |
if value < low:
|
31 |
-
return ("
|
32 |
elif value > high:
|
33 |
-
return ("
|
34 |
else:
|
35 |
-
return ("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def analyze_face(image):
|
38 |
if image is None:
|
@@ -53,28 +64,18 @@ def analyze_face(image):
|
|
53 |
tsh, cortisol = 2.5, 18
|
54 |
fbs, hba1c = 120, 6.2
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
html += '</div>'
|
63 |
-
return html
|
64 |
-
|
65 |
-
report = "".join([
|
66 |
-
section("π©Έ Hematology", [("Hemoglobin", hb, (13.5, 17.5)), ("WBC Count", wbc, (4.0, 11.0)), ("Platelets", platelets, (150, 450))]),
|
67 |
-
section("𧬠Iron & Liver Panel", [("Iron", iron, (60, 170)), ("Ferritin", ferritin, (30, 300)), ("TIBC", tibc, (250, 400)), ("Bilirubin", bilirubin, (0.3, 1.2))]),
|
68 |
-
section("π§ͺ Kidney, Thyroid & Stress", [("Creatinine", creatinine, (0.6, 1.2)), ("TSH", tsh, (0.4, 4.0)), ("Cortisol", cortisol, (5, 25))]),
|
69 |
-
section("π§ Metabolic Panel", [("Fasting Blood Sugar", fbs, (70, 110)), ("HbA1c", hba1c, (4.0, 5.7))]),
|
70 |
-
section("β€οΈ Vital Signs", [("SpO2", spo2, (95, 100)), ("Heart Rate", heart_rate, (60, 100)), ("Respiratory Rate", rr, (12, 20))])
|
71 |
])
|
72 |
|
73 |
-
return
|
74 |
|
75 |
-
# Gradio App Layout
|
76 |
-
|
77 |
-
with demo:
|
78 |
gr.Markdown("""
|
79 |
# π§ Face-Based Lab Test AI Report
|
80 |
Upload a face photo to infer health diagnostics with AI-based visual markers.
|
@@ -85,13 +86,14 @@ with demo:
|
|
85 |
image_input = gr.Image(type="numpy", label="πΈ Upload Face Image")
|
86 |
submit_btn = gr.Button("π Analyze")
|
87 |
with gr.Column(scale=2):
|
88 |
-
result_html = gr.HTML(label="π§ͺ
|
89 |
result_image = gr.Image(label="π· Face Scan Annotated")
|
90 |
|
91 |
-
submit_btn.click(
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
96 |
|
97 |
demo.launch()
|
|
|
1 |
# Face Detection-Based AI Automation of Lab Tests
|
2 |
+
# Redesigned UI using Clean Table Format for Results
|
3 |
|
4 |
import gradio as gr
|
5 |
import cv2
|
|
|
28 |
def get_risk_color(value, normal_range):
|
29 |
low, high = normal_range
|
30 |
if value < low:
|
31 |
+
return ("Low", "π»", "#FFCCCC")
|
32 |
elif value > high:
|
33 |
+
return ("High", "πΊ", "#FFE680")
|
34 |
else:
|
35 |
+
return ("Normal", "β
", "#CCFFCC")
|
36 |
+
|
37 |
+
def build_table(title, rows):
|
38 |
+
html = f'<div style="margin-bottom: 24px;">
|
39 |
+
<h4 style="margin: 8px 0;">{title}</h4>
|
40 |
+
<table style="width:100%; border-collapse:collapse;">
|
41 |
+
<thead><tr style="background:#f0f0f0;"><th style="padding:8px;border:1px solid #ccc;">Test</th><th style="padding:8px;border:1px solid #ccc;">Result</th><th style="padding:8px;border:1px solid #ccc;">Expected Range</th><th style="padding:8px;border:1px solid #ccc;">Level</th></tr></thead><tbody>'
|
42 |
+
for label, value, ref in rows:
|
43 |
+
level, icon, bg = get_risk_color(value, ref)
|
44 |
+
html += f'<tr style="background:{bg};"><td style="padding:6px;border:1px solid #ccc;">{label}</td><td style="padding:6px;border:1px solid #ccc;">{value}</td><td style="padding:6px;border:1px solid #ccc;">{ref[0]} β {ref[1]}</td><td style="padding:6px;border:1px solid #ccc;">{icon} {level}</td></tr>'
|
45 |
+
html += '</tbody></table></div>'
|
46 |
+
return html
|
47 |
|
48 |
def analyze_face(image):
|
49 |
if image is None:
|
|
|
64 |
tsh, cortisol = 2.5, 18
|
65 |
fbs, hba1c = 120, 6.2
|
66 |
|
67 |
+
html_output = "".join([
|
68 |
+
build_table("π©Έ Hematology", [("Hemoglobin", hb, (13.5, 17.5)), ("WBC Count", wbc, (4.0, 11.0)), ("Platelets", platelets, (150, 450))]),
|
69 |
+
build_table("𧬠Iron & Liver Panel", [("Iron", iron, (60, 170)), ("Ferritin", ferritin, (30, 300)), ("TIBC", tibc, (250, 400)), ("Bilirubin", bilirubin, (0.3, 1.2))]),
|
70 |
+
build_table("π§ͺ Kidney, Thyroid & Stress", [("Creatinine", creatinine, (0.6, 1.2)), ("TSH", tsh, (0.4, 4.0)), ("Cortisol", cortisol, (5, 25))]),
|
71 |
+
build_table("π§ Metabolic Panel", [("Fasting Blood Sugar", fbs, (70, 110)), ("HbA1c", hba1c, (4.0, 5.7))]),
|
72 |
+
build_table("β€οΈ Vital Signs", [("SpO2", spo2, (95, 100)), ("Heart Rate", heart_rate, (60, 100)), ("Respiratory Rate", rr, (12, 20))])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
])
|
74 |
|
75 |
+
return html_output, frame_rgb
|
76 |
|
77 |
+
# Gradio App Layout
|
78 |
+
with gr.Blocks() as demo:
|
|
|
79 |
gr.Markdown("""
|
80 |
# π§ Face-Based Lab Test AI Report
|
81 |
Upload a face photo to infer health diagnostics with AI-based visual markers.
|
|
|
86 |
image_input = gr.Image(type="numpy", label="πΈ Upload Face Image")
|
87 |
submit_btn = gr.Button("π Analyze")
|
88 |
with gr.Column(scale=2):
|
89 |
+
result_html = gr.HTML(label="π§ͺ Health Report Table")
|
90 |
result_image = gr.Image(label="π· Face Scan Annotated")
|
91 |
|
92 |
+
submit_btn.click(fn=analyze_face, inputs=image_input, outputs=[result_html, result_image])
|
93 |
+
|
94 |
+
gr.Markdown("""
|
95 |
+
---
|
96 |
+
β
Table Format β’ Color-coded Status β’ Normal Range View
|
97 |
+
""")
|
98 |
|
99 |
demo.launch()
|