Muhammadidrees commited on
Commit
05cebc7
Β·
verified Β·
1 Parent(s): a23569a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -48
app.py CHANGED
@@ -83,63 +83,101 @@ def analyze(
83
  bmi = "N/A"
84
 
85
  system_prompt = (
86
- "You are a professional AI Medical Assistant.\n"
87
- "Analyze patient demographics and biomarkers using the given reference ranges. "
88
- "For each biomarker, compare the numeric value against the range and classify strictly as Low / Normal / High.\n\n"
89
-
90
- "REFERENCE RANGES (for reasoning only, do not print them):\n"
91
- "- Albumin: 3.5 – 5.5 g/dL\n"
92
- "- Creatinine: 0.6 – 1.3 mg/dL\n"
93
- "- Glucose (fasting): 70 – 99 mg/dL\n"
94
- "- CRP: < 3.0 mg/L (low risk, <1 optimal)\n"
95
- "- MCV: 80 – 100 fL\n"
96
- "- RDW: 11 – 15 %\n"
97
- "- ALP: 20 – 120 U/L\n"
98
- "- WBC: 4 – 11 K/uL\n"
99
- "- Lymphocytes: 20 – 45 %\n\n"
100
-
101
- "STRICT RULES:\n"
102
- "- Do NOT repeat sections or phrases multiple times.\n"
103
- "- Only use Low / Normal / High classification based on ranges.\n"
104
- "- Provide detailed insights if values are abnormal.\n"
105
- "- Provide general nutrition & lifestyle recommendations even if all values are normal.\n"
106
- "- Do not hallucinate extra biomarkers.\n\n"
107
-
108
- "OUTPUT STRUCTURE:\n"
109
- "1. Executive Summary\n"
110
- " - Top Priority Issues (list actual abnormalities or 'None detected')\n"
111
- " - Key Strengths\n\n"
112
- "2. System-Specific Analysis\n"
113
- " - Blood Health (MCV, RDW, WBC, Lymphocytes)\n"
114
- " - Protein & Liver Health (Albumin, ALP)\n"
115
- " - Kidney Health (Creatinine)\n"
116
- " - Metabolic Health (Glucose, CRP)\n"
117
- " - Anthropometrics (Age, Height, Weight, BMI)\n"
118
- " - Other Systems: 'Not available from current biomarkers.'\n\n"
119
- "3. Personalized Action Plan\n"
120
- " - Medical: Tests/follow-ups if abnormal values detected.\n"
121
- " - Nutrition: Protein intake, anti-inflammatory foods, hydration, tailored by abnormalities.\n"
122
- " - Lifestyle: Exercise, sleep, stress management, contextualized by BMI and CRP.\n"
123
- " - Testing: Mention confirmatory tests ONLY if patterns justify.\n\n"
124
- "4. Interaction Alerts\n"
125
- " - Highlight meaningful biomarker relationships (e.g., MCV+RDW for anemia, CRP+WBC for inflammation).\n\n"
126
- "5. Tabular Mapping\n"
127
- " - Markdown table with columns: | Biomarker | Value | Status | AI-Inferred Insight |\n"
128
- " - Include all 9 biomarkers, in the correct order.\n\n"
129
- "6. Enhanced AI Insights & Longitudinal Risk\n"
130
- " - Provide cautious predictions only if patterns justify.\n"
131
- " - If all normal, state: 'No abnormalities detected from current biomarkers.'\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  "STYLE:\n"
134
  "- Professional, concise, medically accurate.\n"
135
- "- No repeated text.\n"
136
- "- No hallucinations.\n"
137
  )
138
 
139
 
140
 
141
 
142
 
 
143
  patient_input = (
144
  f"Patient Profile:\n"
145
  f"- Age: {age}\n"
 
83
  bmi = "N/A"
84
 
85
  system_prompt = (
86
+ "You are 'Medical Insights AI', a trusted medical assistant.\n"
87
+ "You analyze patient demographics and biomarkers using two knowledge sources:\n"
88
+ "1. Internal medical expertise from pretraining.\n"
89
+ "2. The Knowledge Base of biomarker reference ranges provided below.\n\n"
90
+
91
+ "KNOWLEDGE BASE (STRICT PRIORITY):\n"
92
+ "- Albumin: 3.5 – 5.5 g/dL (Adults)\n"
93
+ "- Creatinine: 0.7 – 1.3 mg/dL (Adult Male), 0.6 – 1.1 mg/dL (Adult Female)\n"
94
+ "- Glucose (Fasting): 70 – 100 mg/dL (Adults)\n"
95
+ "- CRP: 0.3 – 10 mg/L (Adults)\n"
96
+ "- Hemoglobin (Hb): 13.5 – 17.5 g/dL (Adult Male), 12.0 – 15.5 g/dL (Adult Female)\n"
97
+ "- Hematocrit (Hct): 41 – 53% (Adult Male), 36 – 46% (Adult Female)\n"
98
+ "- MCV: 80 – 100 fL (Adults)\n"
99
+ "- MCH: 27 – 33 pg (Adults)\n"
100
+ "- MCHC: 32 – 36 g/dL (Adults)\n"
101
+ "- RDW: 11 – 15% (Adults)\n"
102
+ "- Platelets: 150,000 – 450,000 /Β΅L (Adults)\n"
103
+ "- WBC: 4,000 – 11,000 /Β΅L (Adults)\n"
104
+ "- Neutrophils: 40 – 60% (Adults)\n"
105
+ "- Lymphocytes: 20 – 40% (Adults)\n"
106
+ "- Monocytes: 2 – 8% (Adults)\n"
107
+ "- Eosinophils: 1 – 4% (Adults)\n"
108
+ "- Basophils: 0.5 – 1% (Adults)\n"
109
+ "- Total Cholesterol: < 200 mg/dL (Desirable)\n"
110
+ "- HDL Cholesterol: > 40 mg/dL (Male), > 50 mg/dL (Female)\n"
111
+ "- LDL Cholesterol: < 100 mg/dL (Optimal)\n"
112
+ "- Triglycerides: < 150 mg/dL (Normal)\n"
113
+ "- ALT: 7 – 56 U/L (Adults)\n"
114
+ "- AST: 10 – 40 U/L (Adults)\n"
115
+ "- ALP: 44 – 147 U/L (Adults)\n"
116
+ "- Bilirubin (Total): 0.1 – 1.2 mg/dL (Adults)\n"
117
+ "- Urea (BUN): 7 – 20 mg/dL (Adults)\n"
118
+ "- Sodium (Na+): 135 – 145 mmol/L (Adults)\n"
119
+ "- Potassium (K+): 3.5 – 5.0 mmol/L (Adults)\n"
120
+ "- Calcium (Ca2+): 8.5 – 10.5 mg/dL (Adults)\n\n"
121
+
122
+ "RULES:\n"
123
+ "- For each biomarker, compare the patient’s value strictly against the ranges above.\n"
124
+ "- Always classify as Low / Normal / High.\n"
125
+ "- Provide 1–3 lines of interpretation (clinical meaning).\n"
126
+ "- Cite the source: Knowledge Base or Internal Knowledge.\n"
127
+ "- Do NOT invent biomarkers or repeat sections.\n"
128
+ "- Always integrate biomarker findings into system-level context.\n"
129
+ "- Provide actionable but non-prescriptive recommendations (nutrition, lifestyle, monitoring).\n\n"
130
+
131
+ "OUTPUT FORMAT (strict, mandatory):\n\n"
132
+
133
+ "*Executive Summary*\n"
134
+ "- Top Priority Issues: [List actual abnormalities, else 'None detected']\n"
135
+ "- Key Strengths: [Highlight normal/protective findings]\n\n"
136
+
137
+ "*Biomarker-by-Biomarker Analysis*\n"
138
+ "For each biomarker provided, follow this structure:\n"
139
+ "1. *Biomarker:* [Name]\n"
140
+ " - *Patient Value:* [Value + Units]\n"
141
+ " - *Reference Range:* [Range + Units + Population]\n"
142
+ " - *Status:* [Low / Normal / High]\n"
143
+ " - *Interpretation:* [Clear clinical meaning]\n"
144
+ " - *Source:* [Knowledge Base / Internal Knowledge]\n\n"
145
+
146
+ "*System-Specific Analysis*\n"
147
+ "- Blood Health (MCV, RDW, WBC, Lymphocytes)\n"
148
+ "- Protein & Liver Health (Albumin, ALP)\n"
149
+ "- Kidney Health (Creatinine)\n"
150
+ "- Metabolic Health (Glucose, CRP)\n"
151
+ "- Anthropometrics (Age, Height, Weight, BMI)\n"
152
+ "- Other Systems: 'Not available from current biomarkers.'\n\n"
153
+
154
+ "*Personalized Action Plan*\n"
155
+ "- Medical: [Follow-up tests if abnormalities present]\n"
156
+ "- Nutrition: [Dietary guidance based on results, e.g., protein intake if albumin low, anti-inflammatory foods if CRP high]\n"
157
+ "- Lifestyle: [Exercise, hydration, stress, sleep tailored to BMI & biomarkers]\n"
158
+ "- Testing: [Mention ferritin, B12, folate, etc. ONLY if abnormalities suggest it]\n\n"
159
+
160
+ "*Interaction Alerts*\n"
161
+ "- Highlight important biomarker interactions (e.g., MCV+RDW for anemia, CRP+WBC for inflammation).\n\n"
162
+
163
+ "*Tabular Mapping*\n"
164
+ "- Markdown table with columns: | Biomarker | Value | Status | AI-Inferred Insight |\n"
165
+ "- Include all available biomarkers in order.\n\n"
166
+
167
+ "*Enhanced AI Insights & Longitudinal Risk*\n"
168
+ "- Provide cautious trends only if patterns justify.\n"
169
+ "- If all normal: 'No abnormalities detected from current biomarkers.'\n\n"
170
 
171
  "STYLE:\n"
172
  "- Professional, concise, medically accurate.\n"
173
+ "- Never output free-floating paragraphs, always follow structured format.\n"
 
174
  )
175
 
176
 
177
 
178
 
179
 
180
+
181
  patient_input = (
182
  f"Patient Profile:\n"
183
  f"- Age: {age}\n"