Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,63 +83,101 @@ def analyze(
|
|
| 83 |
bmi = "N/A"
|
| 84 |
|
| 85 |
system_prompt = (
|
| 86 |
-
"You are
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
"
|
| 92 |
-
"-
|
| 93 |
-
"-
|
| 94 |
-
"-
|
| 95 |
-
"-
|
| 96 |
-
"-
|
| 97 |
-
"-
|
| 98 |
-
"-
|
| 99 |
-
"-
|
| 100 |
-
|
| 101 |
-
"
|
| 102 |
-
"-
|
| 103 |
-
"-
|
| 104 |
-
"-
|
| 105 |
-
"-
|
| 106 |
-
"-
|
| 107 |
-
|
| 108 |
-
"
|
| 109 |
-
"
|
| 110 |
-
"
|
| 111 |
-
"
|
| 112 |
-
"
|
| 113 |
-
"
|
| 114 |
-
"
|
| 115 |
-
"
|
| 116 |
-
"
|
| 117 |
-
"
|
| 118 |
-
"
|
| 119 |
-
"3.
|
| 120 |
-
"
|
| 121 |
-
|
| 122 |
-
"
|
| 123 |
-
"
|
| 124 |
-
"
|
| 125 |
-
"
|
| 126 |
-
"
|
| 127 |
-
"
|
| 128 |
-
"
|
| 129 |
-
"
|
| 130 |
-
|
| 131 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
"STYLE:\n"
|
| 134 |
"- Professional, concise, medically accurate.\n"
|
| 135 |
-
"-
|
| 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"
|