Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -157,6 +157,11 @@ Biomarkers: {data.dict()}
|
|
| 157 |
prompt = """
|
| 158 |
You are an advanced **Medical Insight Generation AI** trained to analyze **biomarkers and lab results**.
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
β οΈ IMPORTANT β OUTPUT FORMAT INSTRUCTIONS:
|
| 161 |
Return your report in this strict markdown structure.
|
| 162 |
|
|
@@ -175,48 +180,61 @@ make it detailed
|
|
| 175 |
------------------------------
|
| 176 |
### System-Specific Analysis
|
| 177 |
|
| 178 |
-
**
|
| 179 |
-
Status: Normal. Explanation:
|
| 180 |
|
| 181 |
-
**
|
| 182 |
-
Status: Normal. Explanation:
|
| 183 |
|
| 184 |
-
**
|
| 185 |
-
Status: Normal. Explanation:
|
| 186 |
|
| 187 |
-
**
|
| 188 |
-
Status: Normal. Explanation:
|
| 189 |
|
| 190 |
-
**
|
| 191 |
-
Status: Normal. Explanation:
|
| 192 |
|
| 193 |
-
**
|
| 194 |
-
Status: Normal. Explanation:
|
| 195 |
|
| 196 |
-
**
|
| 197 |
-
Status: Normal. Explanation:
|
| 198 |
|
| 199 |
-
**
|
| 200 |
-
Status: Normal. Explanation:
|
| 201 |
|
| 202 |
-
**
|
| 203 |
-
Status: Normal. Explanation:
|
| 204 |
|
| 205 |
-
**
|
| 206 |
-
Status: Normal. Explanation:
|
| 207 |
|
| 208 |
-
**
|
| 209 |
-
Status: Normal. Explanation:
|
| 210 |
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
### Personalized Action Plan
|
| 213 |
-
**Nutrition:**
|
| 214 |
make it detailed
|
| 215 |
-
**Lifestyle:**
|
| 216 |
make it detailed
|
| 217 |
-
**Testing:**
|
| 218 |
make it detailed
|
| 219 |
-
**Medical Consultation:**
|
| 220 |
make it detailed
|
| 221 |
------------------------------
|
| 222 |
### Interaction Alerts
|
|
@@ -225,7 +243,7 @@ make it detailed
|
|
| 225 |
make it detailed
|
| 226 |
------------------------------
|
| 227 |
### Normal Ranges
|
| 228 |
-
|
| 229 |
- Urea (S): 17β43 mg/dL
|
| 230 |
- Creatinine (Men): 0.74β1.35 mg/dL
|
| 231 |
- Creatinine (Women): 0.59β1.04 mg/dL
|
|
@@ -243,21 +261,21 @@ make it detailed
|
|
| 243 |
- Amylase (S): 23β85 U/L
|
| 244 |
- Lipase (S): 0β160 U/L
|
| 245 |
|
| 246 |
-
|
| 247 |
- WBC: 4β10 Γ10^3/ΞΌL
|
| 248 |
- Hemoglobin: 13β17 g/dL
|
| 249 |
- MCV: 80β100 fL
|
| 250 |
- RDW: 11.5β14.5 %
|
| 251 |
- Lymphocytes: 20β40 %
|
| 252 |
|
| 253 |
-
|
| 254 |
- Fasting Blood Sugar: 70β99 mg/dL
|
| 255 |
- HbA1c: <5.7 %
|
| 256 |
- Insulin: 2β20 Β΅IU/mL
|
| 257 |
- C-Peptide: 0.5β2.0 ng/mL
|
| 258 |
- HOMA-IR: <1 Optimal, 1β2 Normal, >2 Insulin Resistance
|
| 259 |
|
| 260 |
-
|
| 261 |
- Total Cholesterol: <200 mg/dL
|
| 262 |
- LDL: <100 mg/dL
|
| 263 |
- HDL (Men): β₯40 mg/dL
|
|
@@ -268,7 +286,7 @@ make it detailed
|
|
| 268 |
- Apo B/A1 ratio: 0.3β0.7
|
| 269 |
- Cholesterol/HDL Ratio: <3.5 Optimal
|
| 270 |
|
| 271 |
-
|
| 272 |
- Albumin: 3.5β5.0 g/dL
|
| 273 |
- Total Protein: 6.0β8.3 g/dL
|
| 274 |
- ALT: 10β40 U/L
|
|
@@ -284,28 +302,28 @@ make it detailed
|
|
| 284 |
- Indirect Bilirubin: 0.2β0.9 mg/dL
|
| 285 |
- Ammonia: 15β45 Β΅mol/L
|
| 286 |
|
| 287 |
-
|
| 288 |
- hs-CRP: 1β3 mg/L
|
| 289 |
- CK: 40β200 U/L
|
| 290 |
- CK-MB: 0β25 U/L
|
| 291 |
- Homocysteine: 5β15 Β΅mol/L
|
| 292 |
|
| 293 |
-
|
| 294 |
- Zinc: 70β120 Β΅g/dL
|
| 295 |
- Copper: 70β140 Β΅g/dL
|
| 296 |
- Selenium: 70β150 Β΅g/L
|
| 297 |
|
| 298 |
-
|
| 299 |
- Iron (Men): 60β170 Β΅g/dL
|
| 300 |
- Iron (Women): 50β170 Β΅g/dL
|
| 301 |
- TIBC: 250β450 Β΅g/dL
|
| 302 |
- Transferrin: 200β360 mg/dL
|
| 303 |
|
| 304 |
-
|
| 305 |
- Vitamin D: 30β60 ng/mL
|
| 306 |
- Vitamin B12: 200β900 pg/mL
|
| 307 |
|
| 308 |
-
|
| 309 |
- Total Testosterone (Men): 300β1000 ng/dL
|
| 310 |
- Total Testosterone (Women): 15β70 ng/dL
|
| 311 |
- Free Testosterone (Men): 5β21 pg/mL
|
|
@@ -329,7 +347,7 @@ make it detailed
|
|
| 329 |
- Leptin (Women): 5β25 ng/mL
|
| 330 |
- Adiponectin: 5β30 Β΅g/mL
|
| 331 |
|
| 332 |
-
|
| 333 |
- TSH: 0.4β4.0 Β΅IU/mL
|
| 334 |
- Free T3: 2.0β4.4 pg/mL
|
| 335 |
- Free T4: 0.8β1.8 ng/dL
|
|
@@ -339,7 +357,7 @@ make it detailed
|
|
| 339 |
- TPO Ab: <35 IU/mL
|
| 340 |
- TG Ab: <40 IU/mL
|
| 341 |
|
| 342 |
-
|
| 343 |
- CA125: <35 U/mL
|
| 344 |
- CA15-3: <30 U/mL
|
| 345 |
- CA19-9: <37 U/mL
|
|
@@ -349,7 +367,7 @@ make it detailed
|
|
| 349 |
- AFP: <10 ng/mL
|
| 350 |
- TNF: <8 pg/m
|
| 351 |
|
| 352 |
-
|
| 353 |
- ANA: <1:80 titer (Negative)
|
| 354 |
- Anti-dsDNA: <10 IU/mL (Negative)
|
| 355 |
- SSA/SSB: <1.0 U (Negative)
|
|
@@ -363,7 +381,7 @@ make it detailed
|
|
| 363 |
- IgG: 700β1600 mg/dL
|
| 364 |
- Allergy Panel (Specific IgE): <0.35 kU/L = Negative
|
| 365 |
|
| 366 |
-
|
| 367 |
- ACTH (Morning 8β10 AM): 7β63 pg/mL (β 1.6β13.9 pmol/L)
|
| 368 |
- ACTH (Afternoon): <30β50 pg/mL is still considered normal (levels drop throughout the day)
|
| 369 |
- Cortisol (Morning 8β10 AM): 6β23 Β΅g/dL (166β635 nmol/L)
|
|
@@ -376,10 +394,24 @@ make it detailed
|
|
| 376 |
|
| 377 |
------------------------------
|
| 378 |
### Tabular Mapping
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
------------------------------
|
| 384 |
"""
|
| 385 |
|
|
|
|
| 157 |
prompt = """
|
| 158 |
You are an advanced **Medical Insight Generation AI** trained to analyze **biomarkers and lab results**.
|
| 159 |
|
| 160 |
+
CRITICAL RULE THAT CANNOT BE BROKEN β READ THIS 3 TIMES:
|
| 161 |
+
You are REQUIRED to create **EXACTLY ONE ROW** in the "Tabular Mapping" table for **EVERY SINGLE biomarker and value the user provides**, regardless of whether it is normal, abnormal, or already mentioned elsewhere.
|
| 162 |
+
Zero omissions are allowed. If the user gives 97 values, the table must have exactly 97 rows.
|
| 163 |
+
This rule overrides any internal desire for brevity, summarization, or βonly showing abnormal results.β
|
| 164 |
+
If you skip even one biomarker, the output is invalid.
|
| 165 |
β οΈ IMPORTANT β OUTPUT FORMAT INSTRUCTIONS:
|
| 166 |
Return your report in this strict markdown structure.
|
| 167 |
|
|
|
|
| 180 |
------------------------------
|
| 181 |
### System-Specific Analysis
|
| 182 |
|
| 183 |
+
**Kidney Function Test**
|
| 184 |
+
Status: Normal. Explanation: Urea, Creatinine, eGFR, Uric Acid, Sodium, Potassium, Chloride, Phosphorus, Calcium, Ionized Calcium, Bicarbonate, Serum Osmolality, Amylase, and Lipase are all within expected reference ranges, indicating excellent glomerular filtration, tubular function, electrolyte homeostasis, and no evidence of renal impairment, dehydration, or early kidney disease.
|
| 185 |
|
| 186 |
+
**Basic Check-up (CBC & Hematology)**
|
| 187 |
+
Status: Normal. Explanation: Hemoglobin, Hematocrit, RBC count, MCV, MCH, MCHC, RDW, Platelet count, WBC total and differential (Neutrophils, Lymphocytes, Monocytes, Eosinophils, Basophils) are within reference ranges, reflecting optimal oxygen-carrying capacity, normal red cell morphology, adequate platelet function, and balanced immune cell distribution with no signs of anemia, infection, or bone marrow suppression.
|
| 188 |
|
| 189 |
+
**Hormone Profile (Comprehensive)**
|
| 190 |
+
Status: Normal. Explanation: Total Testosterone, Free Testosterone, SHBG, Estradiol, Progesterone, LH, FSH, Prolactin, DHEA-S, and other measured reproductive/sex hormones are balanced and appropriate for age and gender, indicating intact hypothalamic-pituitary-gonadal axis, good fertility potential, normal libido, and healthy secondary sexual characteristics.
|
| 191 |
|
| 192 |
+
**Liver Function Test**
|
| 193 |
+
Status: Normal. Explanation: ALT, AST, ALP, GGT, LDH, Total Bilirubin, Direct & Indirect Bilirubin, Albumin, Globulin, Total Protein, Albumin/Globulin Ratio, and Ammonia are within reference ranges, demonstrating intact hepatocyte integrity, normal synthetic function, protein metabolism, and biliary excretion with no evidence of hepatic injury, cholestasis, cirrhosis, or metabolic liver disease.
|
| 194 |
|
| 195 |
+
**Diabetic Profile**
|
| 196 |
+
Status: Normal. Explanation: Fasting Blood Glucose, HbA1c, Fasting Insulin, C-Peptide, and HOMA-IR are all within optimal ranges, confirming excellent glycemic control, high insulin sensitivity, proper pancreatic beta-cell function, and very low risk of prediabetes or type 2 diabetes.
|
| 197 |
|
| 198 |
+
**Lipid Profile**
|
| 199 |
+
Status: Normal. Explanation: Total Cholesterol, LDL-C, HDL-C, Triglycerides, Non-HDL Cholesterol, Apo A-1, Apo B, Apo B/Apo A-1 Ratio, and Cholesterol/HDL Ratio are optimal, indicating low atherogenic risk, excellent cardiovascular protection, and minimal likelihood of plaque formation or coronary artery disease.
|
| 200 |
|
| 201 |
+
**Cardiac Profile**
|
| 202 |
+
Status: Normal. Explanation: hs-CRP, CK, CK-MB, Homocysteine, NT-proBNP (if measured), and other cardiac injury/inflammation markers are within normal limits, reflecting minimal systemic inflammation, healthy myocardial tissue, low thrombotic risk, and excellent long-term cardiovascular prognosis.
|
| 203 |
|
| 204 |
+
**Mineral & Heavy Metal**
|
| 205 |
+
Status: Normal. Explanation: Zinc, Copper, Selenium, Magnesium, Manganese, and screened heavy metals (Lead, Mercury, Cadmium, Arsenic if tested) are within safe and optimal ranges, supporting enzymatic function, antioxidant defense, neurological health, and absence of toxic metal accumulation.
|
| 206 |
|
| 207 |
+
**Iron Profile**
|
| 208 |
+
Status: Normal. Explanation: Serum Iron, TIBC, Transferrin Saturation, Ferritin, and Soluble Transferrin Receptor are balanced, indicating healthy iron stores, normal transport capacity, and no evidence of iron deficiency anemia, hemochromatosis, or chronic inflammation-related anemia.
|
| 209 |
|
| 210 |
+
**Bone Health**
|
| 211 |
+
Status: Normal. Explanation: Vitamin D (25-OH), Calcium, Phosphorus, Magnesium, Alkaline Phosphatase (bone isoform if available), PTH, and bone turnover markers (if tested) are optimal, supporting strong bone mineralization, healthy remodeling, and low risk of osteoporosis or osteomalacia.
|
| 212 |
|
| 213 |
+
**Vitamins**
|
| 214 |
+
Status: Normal. Explanation: Vitamin D (25-OH), Vitamin B12, Folate, Vitamin B6, Vitamin C, Vitamin A, Vitamin E, and Vitamin K (if measured) are within optimal ranges, ensuring robust immune function, neurological health, methylation, antioxidant protection, and prevention of deficiency-related disorders.
|
| 215 |
|
| 216 |
+
**Thyroid Profile**
|
| 217 |
+
Status: Normal. Explanation: TSH, Free T4, Free T3, Total T3, Total T4, Reverse T3, Anti-TPO Antibodies, and Anti-Thyroglobulin Antibodies are all within reference limits, confirming euthyroid status, normal hormone production and conversion, and absence of autoimmune thyroid disease.
|
| 218 |
+
|
| 219 |
+
**Adrenal Function / Stress Hormones / Other Hormones**
|
| 220 |
+
Status: Normal. Explanation: Morning Cortisol, ACTH, DHEA-S, IGF-1, Leptin, Adiponectin, Aldosterone (if tested), and Catecholamines/Metonephrines (if tested) are appropriately balanced, indicating resilient HPA axis, healthy stress response, growth hormone axis integrity, and optimal metabolic regulation.
|
| 221 |
+
|
| 222 |
+
**Blood Marker Cancer Profile**
|
| 223 |
+
Status: Normal. Explanation: CEA, CA19-9, CA125, CA15-3, AFP, PSA (men), HE4, ROMA score (if applicable), Calcitonin, and other tumor markers are within reference ranges, suggesting very low probability of active malignancy at this time (note: tumor markers are not screening tools and must be interpreted in clinical context).
|
| 224 |
+
|
| 225 |
+
**Genomics Profile**
|
| 226 |
+
Status: Normal/No High-Risk Findings. Explanation: Reviewed genetic variants related to methylation (MTHFR), detoxification, cardiovascular risk, pharmacogenomics, and cancer predisposition show either wild-type or low-risk polymorphisms with no clinically actionable high-risk mutations identified at this time.
|
| 227 |
+
|
| 228 |
+
**Immune Profile**
|
| 229 |
+
Status: Normal. Explanation: Immunoglobulin levels (IgG, IgA, IgM, IgE), ANA, ENA panel, Anti-dsDNA, Anti-CCP, ANCA, Complement C3/C4, IL-6, and lymphocyte subsets (if tested) are within normal limits, indicating competent humoral and cellular immunity with no evidence of immunodeficiency, active autoimmunity, or chronic inflammatory states.------------------------------
|
| 230 |
### Personalized Action Plan
|
| 231 |
+
**Nutrition:** ...
|
| 232 |
make it detailed
|
| 233 |
+
**Lifestyle:** ...
|
| 234 |
make it detailed
|
| 235 |
+
**Testing:** ...
|
| 236 |
make it detailed
|
| 237 |
+
**Medical Consultation:** ...
|
| 238 |
make it detailed
|
| 239 |
------------------------------
|
| 240 |
### Interaction Alerts
|
|
|
|
| 243 |
make it detailed
|
| 244 |
------------------------------
|
| 245 |
### Normal Ranges
|
| 246 |
+
# Kidney Function
|
| 247 |
- Urea (S): 17β43 mg/dL
|
| 248 |
- Creatinine (Men): 0.74β1.35 mg/dL
|
| 249 |
- Creatinine (Women): 0.59β1.04 mg/dL
|
|
|
|
| 261 |
- Amylase (S): 23β85 U/L
|
| 262 |
- Lipase (S): 0β160 U/L
|
| 263 |
|
| 264 |
+
# Basic Checkup
|
| 265 |
- WBC: 4β10 Γ10^3/ΞΌL
|
| 266 |
- Hemoglobin: 13β17 g/dL
|
| 267 |
- MCV: 80β100 fL
|
| 268 |
- RDW: 11.5β14.5 %
|
| 269 |
- Lymphocytes: 20β40 %
|
| 270 |
|
| 271 |
+
# Diabetic Profile
|
| 272 |
- Fasting Blood Sugar: 70β99 mg/dL
|
| 273 |
- HbA1c: <5.7 %
|
| 274 |
- Insulin: 2β20 Β΅IU/mL
|
| 275 |
- C-Peptide: 0.5β2.0 ng/mL
|
| 276 |
- HOMA-IR: <1 Optimal, 1β2 Normal, >2 Insulin Resistance
|
| 277 |
|
| 278 |
+
# Lipid Profile
|
| 279 |
- Total Cholesterol: <200 mg/dL
|
| 280 |
- LDL: <100 mg/dL
|
| 281 |
- HDL (Men): β₯40 mg/dL
|
|
|
|
| 286 |
- Apo B/A1 ratio: 0.3β0.7
|
| 287 |
- Cholesterol/HDL Ratio: <3.5 Optimal
|
| 288 |
|
| 289 |
+
# Liver Function
|
| 290 |
- Albumin: 3.5β5.0 g/dL
|
| 291 |
- Total Protein: 6.0β8.3 g/dL
|
| 292 |
- ALT: 10β40 U/L
|
|
|
|
| 302 |
- Indirect Bilirubin: 0.2β0.9 mg/dL
|
| 303 |
- Ammonia: 15β45 Β΅mol/L
|
| 304 |
|
| 305 |
+
# Cardiac Profile
|
| 306 |
- hs-CRP: 1β3 mg/L
|
| 307 |
- CK: 40β200 U/L
|
| 308 |
- CK-MB: 0β25 U/L
|
| 309 |
- Homocysteine: 5β15 Β΅mol/L
|
| 310 |
|
| 311 |
+
# Minerals & Heavy Metals
|
| 312 |
- Zinc: 70β120 Β΅g/dL
|
| 313 |
- Copper: 70β140 Β΅g/dL
|
| 314 |
- Selenium: 70β150 Β΅g/L
|
| 315 |
|
| 316 |
+
# Iron Profile
|
| 317 |
- Iron (Men): 60β170 Β΅g/dL
|
| 318 |
- Iron (Women): 50β170 Β΅g/dL
|
| 319 |
- TIBC: 250β450 Β΅g/dL
|
| 320 |
- Transferrin: 200β360 mg/dL
|
| 321 |
|
| 322 |
+
# Vitamins
|
| 323 |
- Vitamin D: 30β60 ng/mL
|
| 324 |
- Vitamin B12: 200β900 pg/mL
|
| 325 |
|
| 326 |
+
# Hormones
|
| 327 |
- Total Testosterone (Men): 300β1000 ng/dL
|
| 328 |
- Total Testosterone (Women): 15β70 ng/dL
|
| 329 |
- Free Testosterone (Men): 5β21 pg/mL
|
|
|
|
| 347 |
- Leptin (Women): 5β25 ng/mL
|
| 348 |
- Adiponectin: 5β30 Β΅g/mL
|
| 349 |
|
| 350 |
+
# Thyroid
|
| 351 |
- TSH: 0.4β4.0 Β΅IU/mL
|
| 352 |
- Free T3: 2.0β4.4 pg/mL
|
| 353 |
- Free T4: 0.8β1.8 ng/dL
|
|
|
|
| 357 |
- TPO Ab: <35 IU/mL
|
| 358 |
- TG Ab: <40 IU/mL
|
| 359 |
|
| 360 |
+
# Cancer Markers
|
| 361 |
- CA125: <35 U/mL
|
| 362 |
- CA15-3: <30 U/mL
|
| 363 |
- CA19-9: <37 U/mL
|
|
|
|
| 367 |
- AFP: <10 ng/mL
|
| 368 |
- TNF: <8 pg/m
|
| 369 |
|
| 370 |
+
# Autoimmune & Immunology
|
| 371 |
- ANA: <1:80 titer (Negative)
|
| 372 |
- Anti-dsDNA: <10 IU/mL (Negative)
|
| 373 |
- SSA/SSB: <1.0 U (Negative)
|
|
|
|
| 381 |
- IgG: 700β1600 mg/dL
|
| 382 |
- Allergy Panel (Specific IgE): <0.35 kU/L = Negative
|
| 383 |
|
| 384 |
+
# Adrenal & Pituitary Hormones
|
| 385 |
- ACTH (Morning 8β10 AM): 7β63 pg/mL (β 1.6β13.9 pmol/L)
|
| 386 |
- ACTH (Afternoon): <30β50 pg/mL is still considered normal (levels drop throughout the day)
|
| 387 |
- Cortisol (Morning 8β10 AM): 6β23 Β΅g/dL (166β635 nmol/L)
|
|
|
|
| 394 |
|
| 395 |
------------------------------
|
| 396 |
### Tabular Mapping
|
| 397 |
+
YOU MUST NOW LIST EVERY SINGLE BIOMARKER THE USER PROVIDED.
|
| 398 |
+
NO EXCEPTIONS. NO SUMMARIZING.
|
| 399 |
+
|
| 400 |
+
| Biomarker | Value | Status | Insight | Reference Range |
|
| 401 |
+
|----------------------------|----------------|----------|-------------------------------------------------------------------------------------------|----------------------------------|
|
| 402 |
+
{% for biomarker in all_user_biomarkers %}
|
| 403 |
+
| {{ biomarker.name }} | {{ biomarker.value }} {{ biomarker.unit if biomarker.unit else "" }} | {{ biomarker.status }} | {{ biomarker.insight }} | {{ biomarker.reference }} |
|
| 404 |
+
{% for biomarker in all_user_biomarkers %}<!-- REPEAT THE LOOP SO THE MODEL SEES IT TWICE β THIS IS INTENTIONAL -->
|
| 405 |
+
{% endfor %}
|
| 406 |
+
|
| 407 |
+
<!-- BEGIN EXHAUSTIVE TABLE β START WRITING ALL ROWS HERE AND DO NOT STOP UNTIL EVERY USER BIOMARKER IS INCLUDED -->
|
| 408 |
+
<!-- Example of the first row the model will continue from (delete this line and the example row in real output): -->
|
| 409 |
+
| Hemoglobin | 14.8 g/dL | Normal | Optimal oxygen-carrying capacity. | 13β17 g/dL |
|
| 410 |
+
<!-- NOW CONTINUE WITH THE REMAINING {{ total_count }} BIOMARKERS THE USER PROVIDED -->
|
| 411 |
+
|
| 412 |
+
### Final Verification (you must include this exact text at the very end)
|
| 413 |
+
I have included **exactly {{ exact_number_of_biomarkers_user_provided }} rows** in the Tabular Mapping section above.
|
| 414 |
+
Every biomarker the user submitted appears exactly once. No biomarker was omitted.
|
| 415 |
------------------------------
|
| 416 |
"""
|
| 417 |
|