Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
# Face
|
2 |
-
#
|
3 |
|
4 |
import gradio as gr
|
5 |
import cv2
|
@@ -60,59 +60,62 @@ def analyze_face(image):
|
|
60 |
heart_rate = estimate_heart_rate(frame_rgb, landmarks)
|
61 |
spo2, rr = estimate_spo2_rr(heart_rate)
|
62 |
|
|
|
63 |
hb, wbc, platelets = 12.3, 6.4, 210
|
64 |
iron, ferritin, tibc = 55, 45, 340
|
65 |
-
bilirubin, creatinine = 1.5, 1.3
|
|
|
66 |
tsh, cortisol = 2.5, 18
|
67 |
fbs, hba1c = 120, 6.2
|
|
|
|
|
|
|
68 |
|
69 |
html_output = "".join([
|
70 |
-
build_table("🩸 Hematology", [("Hemoglobin", hb, (13.5, 17.5)), ("WBC Count", wbc, (4.0, 11.0)), ("
|
71 |
-
build_table("🧬 Iron
|
72 |
-
build_table("
|
73 |
-
build_table("
|
74 |
-
build_table("
|
|
|
|
|
75 |
])
|
76 |
|
77 |
summary = "<div style='margin-top:20px;padding:12px;border:1px dashed #999;background:#fcfcfc;'>"
|
78 |
summary += "<h4>📝 Summary for You</h4><ul>"
|
79 |
if hb < 13.5:
|
80 |
-
summary += "<li>Your hemoglobin is
|
81 |
if iron < 60 or ferritin < 30:
|
82 |
-
summary += "<li>
|
83 |
if bilirubin > 1.2:
|
84 |
-
summary += "<li>
|
85 |
if hba1c > 5.7:
|
86 |
-
summary += "<li>
|
87 |
if spo2 < 95:
|
88 |
-
summary += "<li>
|
89 |
-
summary += "</ul><p><strong>💡 Tip:</strong>
|
90 |
-
|
91 |
html_output += summary
|
92 |
|
93 |
html_output += "<br><div style='margin-top:20px;padding:12px;border:2px solid #2d87f0;background:#f2faff;text-align:center;border-radius:8px;'>"
|
94 |
-
html_output += "<h4>📞 Book a Lab Test</h4>"
|
95 |
-
html_output += "<
|
96 |
-
html_output += "<button style='padding:10px 20px;background:#007BFF;color:#fff;border:none;border-radius:5px;cursor:pointer;'>Find Labs Near Me</button>"
|
97 |
-
html_output += "</div>"
|
98 |
|
99 |
lang_blocks = """
|
100 |
<div style='margin-top:20px;padding:12px;border:1px dashed #999;background:#f9f9f9;'>
|
101 |
<h4>🗣️ Summary in Your Language</h4>
|
102 |
<details><summary><b>Hindi</b></summary><ul>
|
103 |
-
<li>आपका हीमोग्लोबिन थोड़ा कम है — यह हल्के एनीमिया का संकेत हो सकता
|
104 |
-
<li
|
105 |
-
<li>जॉन्डिस के
|
106 |
-
<li>HbA1c
|
107 |
-
<li
|
108 |
</ul></details>
|
109 |
-
|
110 |
<details><summary><b>Telugu</b></summary><ul>
|
111 |
-
<li>మీ హిమోగ్లోబిన్
|
112 |
-
<li>Iron నిల్వలు తక్కువగా
|
113 |
-
<li
|
114 |
-
<li>HbA1c
|
115 |
-
<li
|
116 |
</ul></details>
|
117 |
</div>
|
118 |
"""
|
@@ -120,7 +123,6 @@ def analyze_face(image):
|
|
120 |
html_output += lang_blocks
|
121 |
return html_output, frame_rgb
|
122 |
|
123 |
-
# Gradio App Layout
|
124 |
with gr.Blocks() as demo:
|
125 |
gr.Markdown("""
|
126 |
# 🧠 Face-Based Lab Test AI Report
|
@@ -139,7 +141,7 @@ with gr.Blocks() as demo:
|
|
139 |
|
140 |
gr.Markdown("""
|
141 |
---
|
142 |
-
✅ Table Format • Color-coded Status •
|
143 |
""")
|
144 |
|
145 |
demo.launch()
|
|
|
1 |
+
# Enhanced Face-Based Lab Test Predictor
|
2 |
+
# Now covers 30 health use cases with table-based output, multilingual summary, and call-to-action
|
3 |
|
4 |
import gradio as gr
|
5 |
import cv2
|
|
|
60 |
heart_rate = estimate_heart_rate(frame_rgb, landmarks)
|
61 |
spo2, rr = estimate_spo2_rr(heart_rate)
|
62 |
|
63 |
+
# Mock values
|
64 |
hb, wbc, platelets = 12.3, 6.4, 210
|
65 |
iron, ferritin, tibc = 55, 45, 340
|
66 |
+
bilirubin, creatinine, urea = 1.5, 1.3, 18
|
67 |
+
sodium, potassium = 140, 4.2
|
68 |
tsh, cortisol = 2.5, 18
|
69 |
fbs, hba1c = 120, 6.2
|
70 |
+
albumin = 4.3
|
71 |
+
bp_sys, bp_dia = 118, 76
|
72 |
+
temperature = 98.2
|
73 |
|
74 |
html_output = "".join([
|
75 |
+
build_table("🩸 Hematology", [("Hemoglobin", hb, (13.5, 17.5)), ("WBC Count", wbc, (4.0, 11.0)), ("Platelet Count", platelets, (150, 450))]),
|
76 |
+
build_table("🧬 Iron Panel", [("Iron", iron, (60, 170)), ("Ferritin", ferritin, (30, 300)), ("TIBC", tibc, (250, 400))]),
|
77 |
+
build_table("🧬 Liver & Kidney", [("Bilirubin", bilirubin, (0.3, 1.2)), ("Creatinine", creatinine, (0.6, 1.2)), ("Urea", urea, (7, 20))]),
|
78 |
+
build_table("🧪 Electrolytes", [("Sodium", sodium, (135, 145)), ("Potassium", potassium, (3.5, 5.1))]),
|
79 |
+
build_table("🧁 Metabolic & Thyroid", [("Fasting Blood Sugar", fbs, (70, 110)), ("HbA1c", hba1c, (4.0, 5.7)), ("TSH", tsh, (0.4, 4.0))]),
|
80 |
+
build_table("❤️ Vitals", [("SpO2", spo2, (95, 100)), ("Heart Rate", heart_rate, (60, 100)), ("Respiratory Rate", rr, (12, 20)), ("Temperature", temperature, (97, 99)), ("BP Systolic", bp_sys, (90, 120)), ("BP Diastolic", bp_dia, (60, 80))]),
|
81 |
+
build_table("🩹 Other Indicators", [("Cortisol", cortisol, (5, 25)), ("Albumin", albumin, (3.5, 5.5))])
|
82 |
])
|
83 |
|
84 |
summary = "<div style='margin-top:20px;padding:12px;border:1px dashed #999;background:#fcfcfc;'>"
|
85 |
summary += "<h4>📝 Summary for You</h4><ul>"
|
86 |
if hb < 13.5:
|
87 |
+
summary += "<li>Your hemoglobin is low — consider iron-rich diet or CBC test.</li>"
|
88 |
if iron < 60 or ferritin < 30:
|
89 |
+
summary += "<li>Low iron storage seen. Recommend Iron Profile Test.</li>"
|
90 |
if bilirubin > 1.2:
|
91 |
+
summary += "<li>Signs of jaundice. Suggest LFT confirmation.</li>"
|
92 |
if hba1c > 5.7:
|
93 |
+
summary += "<li>Elevated HbA1c — prediabetes alert.</li>"
|
94 |
if spo2 < 95:
|
95 |
+
summary += "<li>Low SpO2 — retest with oximeter if symptoms.</li>"
|
96 |
+
summary += "</ul><p><strong>💡 Tip:</strong> AI estimates — confirm with lab tests.</p></div>"
|
|
|
97 |
html_output += summary
|
98 |
|
99 |
html_output += "<br><div style='margin-top:20px;padding:12px;border:2px solid #2d87f0;background:#f2faff;text-align:center;border-radius:8px;'>"
|
100 |
+
html_output += "<h4>📞 Book a Lab Test</h4><p>Want to confirm these values? Click below to find certified labs near you.</p>"
|
101 |
+
html_output += "<button style='padding:10px 20px;background:#007BFF;color:#fff;border:none;border-radius:5px;cursor:pointer;'>Find Labs Near Me</button></div>"
|
|
|
|
|
102 |
|
103 |
lang_blocks = """
|
104 |
<div style='margin-top:20px;padding:12px;border:1px dashed #999;background:#f9f9f9;'>
|
105 |
<h4>🗣️ Summary in Your Language</h4>
|
106 |
<details><summary><b>Hindi</b></summary><ul>
|
107 |
+
<li>आपका हीमोग्लोबिन थोड़ा कम है — यह हल्के एनीमिया का संकेत हो सकता है।</li>
|
108 |
+
<li>आयरन स्टोरेज कम है — आयरन प्रोफाइल टेस्ट कराएं।</li>
|
109 |
+
<li>जॉन्डिस के संकेत — LFT कराएं।</li>
|
110 |
+
<li>HbA1c बढ़ा हुआ — प्रीडायबिटीज़ का खतरा।</li>
|
111 |
+
<li>SpO2 कम है — पल्स ऑक्सीमीटर से जांचें।</li>
|
112 |
</ul></details>
|
|
|
113 |
<details><summary><b>Telugu</b></summary><ul>
|
114 |
+
<li>మీ హిమోగ్లోబిన్ తక్కువగా ఉంది — ఇది అనీమియా సంకేతం కావచ్చు.</li>
|
115 |
+
<li>Iron నిల్వలు తక్కువగా ఉన్నాయి — Iron ప్రొఫైల్ టెస్ట్ చేయించండి.</li>
|
116 |
+
<li>జాండిస్ లక్షణాలు — LFT చేయించండి.</li>
|
117 |
+
<li>HbA1c పెరిగినది — ప్రీ డయాబెటిస్ సూచన.</li>
|
118 |
+
<li>SpO2 తక్కువగా ఉంది — తిరిగి పరీక్షించండి.</li>
|
119 |
</ul></details>
|
120 |
</div>
|
121 |
"""
|
|
|
123 |
html_output += lang_blocks
|
124 |
return html_output, frame_rgb
|
125 |
|
|
|
126 |
with gr.Blocks() as demo:
|
127 |
gr.Markdown("""
|
128 |
# 🧠 Face-Based Lab Test AI Report
|
|
|
141 |
|
142 |
gr.Markdown("""
|
143 |
---
|
144 |
+
✅ Table Format • Color-coded Status • Summary & Multilingual Support • Lab Booking CTA
|
145 |
""")
|
146 |
|
147 |
demo.launch()
|