Muhammadidrees commited on
Commit
e3424ef
Β·
verified Β·
1 Parent(s): 7e7e224

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +210 -1
app.py CHANGED
@@ -148,13 +148,222 @@ class BiomarkerRequest(BaseModel):
148
 
149
  # ---------------- Gemini Report ----------------
150
  def generate_report(data: BiomarkerRequest) -> str:
 
151
  user_message = f"""
152
  Patient Info:
153
  - Age: {data.age}, Gender: {data.gender}, Height: {data.height}, Weight: {data.weight}
154
  Biomarkers: {data.dict()}
155
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  model = genai.GenerativeModel(MODEL_ID)
157
- response = model.generate_content(user_message)
 
158
  if not response or not getattr(response, "text", None):
159
  return "⚠️ Gemini returned empty response."
160
  return response.text.strip()
 
148
 
149
  # ---------------- Gemini Report ----------------
150
  def generate_report(data: BiomarkerRequest) -> str:
151
+
152
  user_message = f"""
153
  Patient Info:
154
  - Age: {data.age}, Gender: {data.gender}, Height: {data.height}, Weight: {data.weight}
155
  Biomarkers: {data.dict()}
156
  """
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
+
163
+ ------------------------------
164
+ ### Executive Summary
165
+ **Top 3 Health Priorities:**
166
+ 1. ...
167
+ 2. ...
168
+ 3. ...
169
+ make it more detailed
170
+
171
+ **Key Strengths:**
172
+ - ...
173
+ - ...
174
+ 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
223
+ - ...
224
+ - ...
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
232
+ - Uric Acid (Men): 3.4–7.0 mg/dL
233
+ - Uric Acid (Women): 2.4–6.0 mg/dL
234
+ - Calcium (S): 8.5–10.5 mg/dL
235
+ - Phosphorus (S): 2.5–4.5 mg/dL
236
+ - Sodium (S): 135–145 mEq/L
237
+ - Potassium (S): 3.5–5.1 mEq/L
238
+ - Chloride (S): 98–107 mEq/L
239
+ - Bicarbonate (S): 22–28 mEq/L
240
+ - eGFR: β‰₯90 mL/min/1.73mΒ²
241
+ - Serum Osmolality: 275–295 mOsm/kg
242
+ - Ionized Calcium: 1.12–1.32 mmol/L
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
264
+ - HDL (Women): β‰₯50 mg/dL
265
+ - Triglycerides: <150 mg/dL
266
+ - Apo A-1: 120–160 mg/dL
267
+ - Apo B: <90 mg/dL
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
275
+ - AST: 10–40 U/L
276
+ - ALP: 44–147 U/L
277
+ - GGT: 8–61 U/L
278
+ - LDH: 140–280 U/L
279
+ - Globulin: 2.0–3.5 g/dL
280
+ - Albumin/Globulin Ratio: 1.1–2.5
281
+ - Magnesium: 1.7–2.2 mg/dL
282
+ - Total Bilirubin: 0.1–1.2 mg/dL
283
+ - Direct Bilirubin: 0.0–0.3 mg/dL
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
312
+ - Free Testosterone (Women): 0.5–4.2 pg/mL
313
+ - Estrogen (Men): 10–40 pg/mL
314
+ - Estrogen (Women Follicular): 30–120 pg/mL
315
+ - Estrogen (Women Ovulation): 130–370 pg/mL
316
+ - Estrogen (Women Luteal): 70–250 pg/mL
317
+ - Estrogen (Women Postmenopause): <20–30 pg/mL
318
+ - Progesterone: 0.2–1.4 ng/mL
319
+ - SHBG (Men): 10–57 nmol/L
320
+ - SHBG (Women): 18–144 nmol/L
321
+ - LH: 1.7–8.6 IU/L
322
+ - FSH: 1.5–12.4 IU/L
323
+ - DHEA-S (Men): 280–640 Β΅g/dL
324
+ - DHEA-S (Women): 65–380 Β΅g/dL
325
+ - Cortisol (AM): 6–23 Β΅g/dL
326
+ - Cortisol (PM): 2–14 Β΅g/dL
327
+ - IGF-1: 100–300 ng/mL
328
+ - Leptin (Men): 0.5–8 ng/mL
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
336
+ - Total T3: 80–180 ng/dL
337
+ - Total T4: 4.5–12 Β΅g/dL
338
+ - Reverse T3: 9–24 ng/dL
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
346
+ - PSA: <4 ng/mL
347
+ - CEA: <5 ng/mL
348
+ - Calcitonin: <10 pg/mL
349
+ - AFP: <10 ng/mL
350
+ - TNF: <8 pg/m
351
+
352
+
353
+
354
+ ------------------------------
355
+ ### Tabular Mapping
356
+ | Biomarker | Value | Status | Insight | Reference Range |
357
+ | Albumin | X | Normal | ... | 3.5–5.0 g/dL |
358
+ | Creatinine | X | High | ... | 0.7–1.3 mg/dL |
359
+ | Glucose | X | ... | ... | 70–100 mg/dL |
360
+ ------------------------------
361
+ """
362
+
363
+
364
  model = genai.GenerativeModel(MODEL_ID)
365
+ response = model.generate_content(f"{prompt}\n\n{user_message}")
366
+ ## response = model.generate_content(user_message)
367
  if not response or not getattr(response, "text", None):
368
  return "⚠️ Gemini returned empty response."
369
  return response.text.strip()