Synav commited on
Commit
7218012
·
verified ·
1 Parent(s): 2927869

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -6
src/streamlit_app.py CHANGED
@@ -451,13 +451,14 @@ if submitted:
451
  if c not in patient_cov.columns:
452
  patient_cov[c] = categorical_defaults.get(c, 0)
453
 
 
 
454
  patient_design = make_patient_design_row(patient_cov, design_cols, cat_cols)
455
- missing = None
456
  if isinstance(patient_design, tuple):
457
- patient_design, missing = patient_design
458
-
459
- if missing:
460
- st.warning(f"Design row missing columns filled with 0: {missing[:10]}" + (" ..." if len(missing) > 10 else ""))
461
 
462
  st.subheader("Individual adjusted survival curve")
463
  fig, ax = plt.subplots(figsize=(8, 5))
@@ -467,12 +468,15 @@ if submitted:
467
  ax.set_ylabel("Survival probability")
468
  st.pyplot(fig, bbox_inches="tight")
469
  plt.clf()
470
-
471
  st.write("Landmark survival probabilities:")
472
  for y in [3, 5, 10]:
473
  s = landmarks.get(y, None)
474
  if s is not None:
475
  st.write(f"{y}-year survival: {100*s:.1f}%")
 
 
 
476
 
477
  st.caption(
478
  "Choose the appropriate model from the left panel based on the outcome you want to predict. "
 
451
  if c not in patient_cov.columns:
452
  patient_cov[c] = categorical_defaults.get(c, 0)
453
 
454
+ try:
455
+ # Create one-hot design row matching training design columns
456
  patient_design = make_patient_design_row(patient_cov, design_cols, cat_cols)
 
457
  if isinstance(patient_design, tuple):
458
+ patient_design = patient_design[0] # keep only the DataFrame row
459
+
460
+ # Predict survival curve + landmarks
461
+ surv_fn, landmarks = predict_patient_survival(cph, patient_design, years=[3, 5, 10])
462
 
463
  st.subheader("Individual adjusted survival curve")
464
  fig, ax = plt.subplots(figsize=(8, 5))
 
468
  ax.set_ylabel("Survival probability")
469
  st.pyplot(fig, bbox_inches="tight")
470
  plt.clf()
471
+
472
  st.write("Landmark survival probabilities:")
473
  for y in [3, 5, 10]:
474
  s = landmarks.get(y, None)
475
  if s is not None:
476
  st.write(f"{y}-year survival: {100*s:.1f}%")
477
+
478
+ except Exception as e:
479
+ st.error(f"Survival prediction failed: {e}")
480
 
481
  st.caption(
482
  "Choose the appropriate model from the left panel based on the outcome you want to predict. "