SuriRaja commited on
Commit
8449117
·
verified ·
1 Parent(s): 9e64c66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -32
app.py CHANGED
@@ -1,5 +1,5 @@
1
- # Face Detection-Based AI Automation of Lab Tests
2
- # Redesigned UI using Clean Table Format for Results with Language Summary & Lab Booking
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)), ("Platelets", platelets, (150, 450))]),
71
- build_table("🧬 Iron & Liver Panel", [("Iron", iron, (60, 170)), ("Ferritin", ferritin, (30, 300)), ("TIBC", tibc, (250, 400)), ("Bilirubin", bilirubin, (0.3, 1.2))]),
72
- build_table("🧪 Kidney, Thyroid & Stress", [("Creatinine", creatinine, (0.6, 1.2)), ("TSH", tsh, (0.4, 4.0)), ("Cortisol", cortisol, (5, 25))]),
73
- build_table("🧁 Metabolic Panel", [("Fasting Blood Sugar", fbs, (70, 110)), ("HbA1c", hba1c, (4.0, 5.7))]),
74
- build_table("❤️ Vital Signs", [("SpO2", spo2, (95, 100)), ("Heart Rate", heart_rate, (60, 100)), ("Respiratory Rate", rr, (12, 20))])
 
 
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 a bit low — this could mean mild anemia. Consider a CBC test and iron supplements.</li>"
81
  if iron < 60 or ferritin < 30:
82
- summary += "<li>Signs of low iron storage detected. An iron profile blood test is recommended.</li>"
83
  if bilirubin > 1.2:
84
- summary += "<li>Some signs of jaundice were detected. Please consult for a Liver Function Test (LFT).</li>"
85
  if hba1c > 5.7:
86
- summary += "<li>Your HbA1c is slightly elevated this can signal pre-diabetes. A fasting glucose test may help.</li>"
87
  if spo2 < 95:
88
- summary += "<li>Oxygen levels appear below normal. Please recheck with a pulse oximeter if symptoms persist.</li>"
89
- summary += "</ul><p><strong>💡 Tip:</strong> This is an AI-based screening and should be followed up with a lab visit for confirmation.</p></div>"
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 += "<p>Prefer to get your tests confirmed at a nearby center? Click below to find certified labs in your area.</p>"
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>आपका हीमोग्लोबिन थोड़ा कम है — यह हल्के एनीमिया का संकेत हो सकता है। कृपया CBC और आयरन टेस्ट करवाएं।</li>
104
- <li>लो आयरन स्टोरेज देखा गया है। एक आयरन प्रोफाइल टेस्ट की सिफारिश की जाती है।</li>
105
- <li>जॉन्डिस के लक्षण देखे गए हैं। कृपया LFT करवाएं।</li>
106
- <li>HbA1c थोड़ा बढ़ा हुआ है यह प्री-डायबिटीज़ का संकेत हो सकता है।</li>
107
- <li>ऑक्सीजन स्तर कम दिख रहा है। पल्स ऑक्सीमीटर से दोबारा जांचें।</li>
108
  </ul></details>
109
-
110
  <details><summary><b>Telugu</b></summary><ul>
111
- <li>మీ హిమోగ్లోబిన్ కొంచెం తక్కువగా ఉంది — ఇది తేలికపాటి అనీమియా సూచించవచ్చు. CBC, Iron పరీక్ష చేయించండి.</li>
112
- <li>Iron నిల్వలు తక్కువగా కనిపించాయి. Iron ప్రొఫైల్ బ్లడ్ టెస్ట్ చేయించండి.</li>
113
- <li>జాండీస్ సంకేతాలు గుర్తించబడ్డాయి. LFT చేయించండి.</li>
114
- <li>HbA1c కొంచెం పెరిగింది ఇది ప్రీ-డయాబెటిస్ సూచించవచ్చు.</li>
115
- <li>ఆక్సిజన్ స్థాయి తక్కువగా ఉంది. తిరిగి పరీక్షించండి.</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 • Normal Range View • Multilingual Summary • Booking Prompt
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 SupportLab Booking CTA
145
  """)
146
 
147
  demo.launch()