Zeeshan42 commited on
Commit
670abf6
Β·
verified Β·
1 Parent(s): fa7c5d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -34
app.py CHANGED
@@ -25,40 +25,46 @@ def predict_ckd(
25
  platelet_count, polymorphs, rbc_count, rdw_sd,
26
  wbc_count, eosinophils, creatinine, urea, gfr
27
  ):
28
- values = [
29
- sex, age, haemoglobin, hematocrit, lymphocytes,
30
- mch, mchc, mcv, monocytes, mpv, pct, pdw,
31
- platelet_count, polymorphs, rbc_count, rdw_sd,
32
- wbc_count, eosinophils, creatinine, urea, gfr
33
- ]
34
- features = pd.DataFrame([values], columns=FEATURE_ORDER)
35
-
36
- pred = model.predict(features)[0]
37
- proba = model.predict_proba(features)[0]
38
-
39
- ckd_prob = round(float(proba[1]) * 100, 2)
40
- no_ckd_prob = round(float(proba[0]) * 100, 2)
41
-
42
- if pred == 1:
43
- label = "⚠️ CKD Detected"
44
- details = (
45
- f"**Prediction: Chronic Kidney Disease (CKD)**\n\n"
46
- f"- CKD Probability: **{ckd_prob}%**\n"
47
- f"- No CKD Probability: {no_ckd_prob}%\n\n"
48
- f"> ⚠️ This result suggests the presence of Chronic Kidney Disease. "
49
- f"Please consult a qualified nephrologist for clinical evaluation."
50
- )
51
- else:
52
- label = "βœ… No CKD Detected"
53
- details = (
54
- f"**Prediction: No Chronic Kidney Disease**\n\n"
55
- f"- No CKD Probability: **{no_ckd_prob}%**\n"
56
- f"- CKD Probability: {ckd_prob}%\n\n"
57
- f"> βœ… Based on the provided blood parameters, no CKD pattern was detected. "
58
- f"Regular health check-ups are still recommended."
59
- )
60
-
61
- return label, details
 
 
 
 
 
 
62
 
63
  # ── UI ────────────────────────────────────────────────────────────────────────
64
  DESCRIPTION = """
 
25
  platelet_count, polymorphs, rbc_count, rdw_sd,
26
  wbc_count, eosinophils, creatinine, urea, gfr
27
  ):
28
+ try:
29
+ values = [
30
+ sex, age, haemoglobin, hematocrit, lymphocytes,
31
+ mch, mchc, mcv, monocytes, mpv, pct, pdw,
32
+ platelet_count, polymorphs, rbc_count, rdw_sd,
33
+ wbc_count, eosinophils, creatinine, urea, gfr
34
+ ]
35
+ features = pd.DataFrame([values], columns=FEATURE_ORDER)
36
+
37
+ pred = model.predict(features)[0]
38
+ proba = model.predict_proba(features)[0]
39
+
40
+ ckd_prob = round(float(proba[1]) * 100, 2)
41
+ no_ckd_prob = round(float(proba[0]) * 100, 2)
42
+
43
+ if pred == 1:
44
+ label = "⚠️ CKD Detected"
45
+ details = (
46
+ f"**Prediction: Chronic Kidney Disease (CKD)**\n\n"
47
+ f"- CKD Probability: **{ckd_prob}%**\n"
48
+ f"- No CKD Probability: {no_ckd_prob}%\n\n"
49
+ f"> ⚠️ This result suggests the presence of Chronic Kidney Disease. "
50
+ f"Please consult a qualified nephrologist for clinical evaluation."
51
+ )
52
+ else:
53
+ label = "βœ… No CKD Detected"
54
+ details = (
55
+ f"**Prediction: No Chronic Kidney Disease**\n\n"
56
+ f"- No CKD Probability: **{no_ckd_prob}%**\n"
57
+ f"- CKD Probability: {ckd_prob}%\n\n"
58
+ f"> βœ… Based on the provided blood parameters, no CKD pattern was detected. "
59
+ f"Regular health check-ups are still recommended."
60
+ )
61
+
62
+ return label, details
63
+
64
+ except Exception as e:
65
+ import traceback
66
+ err = traceback.format_exc()
67
+ return "❌ Prediction Error", f"```\n{err}\n```"
68
 
69
  # ── UI ────────────────────────────────────────────────────────────────────────
70
  DESCRIPTION = """