Muhammadidrees commited on
Commit
77e66ec
Β·
verified Β·
1 Parent(s): 3634697

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -45
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
- **Cardiovascular System**
179
- Status: Normal. Explanation: Lipid profile including Total Cholesterol, LDL, HDL, Triglycerides, Apo A-1, Apo B, Apo Ratio, and Cholesterol/HDL Ratio are within reference ranges, indicating low risk of atherosclerosis, coronary artery disease, and other cardiovascular disorders. hs-CRP, CK, CK-MB, and Homocysteine levels are normal, reflecting minimal systemic inflammation and proper myocardial health.
180
 
181
- **Metabolic & Glycemic Control**
182
- Status: Normal. Explanation: Fasting Blood Sugar, HbA1c, Insulin, C-Peptide, and HOMA-IR are within healthy ranges, suggesting effective glucose metabolism, insulin sensitivity, and low risk of prediabetes or diabetes.
183
 
184
- **Liver Function**
185
- Status: Normal. Explanation: ALT, AST, ALP, GGT, LDH, Total Bilirubin, Direct and Indirect Bilirubin, Albumin, Globulin, Albumin/Globulin Ratio, Total Protein, Ammonia, and Magnesium are within reference ranges, reflecting normal hepatocellular integrity, protein synthesis, and biliary excretion. Abnormalities could indicate hepatic injury, cholestasis, or metabolic liver disorders.
186
 
187
- **Renal Function**
188
- Status: Normal. Explanation: Urea, Creatinine, eGFR, Uric Acid, Sodium, Potassium, Chloride, Phosphorus, Calcium, Ionized Calcium, Bicarbonate, Serum Osmolality, Amylase, and Lipase are within expected ranges, suggesting proper kidney filtration, electrolyte balance, and pancreatic enzyme activity. Deviations may indicate renal impairment, electrolyte disorders, or pancreatitis risk.
189
 
190
- **Thyroid Function**
191
- Status: Normal. Explanation: TSH, Free T3, Free T4, Total T3, Total T4, Reverse T3, TPO Ab, and TG Ab are within reference limits, showing normal thyroid hormone production, peripheral conversion, and autoimmune status. Abnormal levels may indicate hypothyroidism, hyperthyroidism, or thyroid autoimmunity.
192
 
193
- **Adrenal & Stress Hormones**
194
- Status: Normal. Explanation: Cortisol, ACTH, DHEA-S, IGF-1, Leptin, and Adiponectin are within normal ranges, reflecting healthy adrenal function, stress response, metabolic regulation, and energy homeostasis. Abnormalities could indicate adrenal insufficiency, Cushing’s syndrome, metabolic disorders, or leptin/adiponectin imbalance.
195
 
196
- **Sex Hormones & Reproductive Health**
197
- Status: Normal. Explanation: Total Testosterone, Free Testosterone, SHBG, Estrogen, Progesterone, LH, and FSH are within expected ranges based on gender and menstrual cycle, indicating balanced gonadal function, fertility potential, and hormonal homeostasis. Deviations may impact reproductive function, libido, or secondary sexual characteristics.
198
 
199
- **Vitamins & Minerals**
200
- Status: Normal. Explanation: Vitamin D, Vitamin B12, Iron, TIBC, Transferrin, Zinc, Copper, Selenium, and Magnesium are within reference ranges, supporting optimal hematologic function, enzymatic reactions, immune defense, and bone health. Deficiencies may lead to anemia, metabolic disturbances, or immune dysfunction.
201
 
202
- **Hematology & Immune Function**
203
- Status: Normal. Explanation: Hemoglobin, MCV, RDW, WBC, Lymphocytes, Albumin, Globulin, ANA, IgE, IgG, Anti-CCP, dsDNA, SSA/SSB, RNP, Sm Antibodies, ANCA, Anti-ENA, IL-6, and Allergy Panel are within normal limits, indicating proper oxygen transport, red blood cell morphology, and immune competence. Deviations could indicate anemia, infection, inflammation, or autoimmune conditions.
204
 
205
- **Cancer Markers**
206
- Status: Normal. Explanation: CA125, CA15-3, CA19-9, PSA, CEA, AFP, Calcitonin, and TNF are within reference ranges, suggesting low risk for malignancy or tumor activity. Elevated values may require further imaging or diagnostic evaluation.
207
 
208
- **Inflammatory Markers**
209
- Status: Normal. Explanation: hs-CRP, IL-6, and Homocysteine are within recommended ranges, reflecting low systemic inflammation and minimal cardiovascular or metabolic risk. Elevations may indicate chronic inflammation, autoimmune activity, or thrombotic risk.
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
- #### Kidney Function
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
- #### Basic Checkup
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
- #### Diabetic Profile
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
- #### Lipid Profile
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
- #### Liver Function
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
- #### Cardiac Profile
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
- #### Minerals & Heavy Metals
294
  - Zinc: 70–120 Β΅g/dL
295
  - Copper: 70–140 Β΅g/dL
296
  - Selenium: 70–150 Β΅g/L
297
 
298
- #### Iron Profile
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
- #### Vitamins
305
  - Vitamin D: 30–60 ng/mL
306
  - Vitamin B12: 200–900 pg/mL
307
 
308
- #### Hormones
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
- #### Thyroid
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
- #### Cancer Markers
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
- #### Autoimmune & Immunology
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
- #### Adrenal & Pituitary Hormones
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
- | Biomarker | Value | Status | Insight | Reference Range |
380
- | Albumin | X | Normal | ... | 3.5–5.0 g/dL |
381
- | Creatinine | X | High | ... | 0.7–1.3 mg/dL |
382
- | Glucose | X | ... | ... | 70–100 mg/dL |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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