rangerrRed commited on
Commit
c40bb71
Β·
verified Β·
1 Parent(s): ca24550

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -28
app.py CHANGED
@@ -10,14 +10,14 @@ if "page" not in st.session_state:
10
  st.session_state.page = "heart"
11
 
12
  st.title("🩺 Disease Prediction App")
13
- st.markdown("Follow the steps to assess your **Heart**, **Chest**, and **Combined Health Risk**.")
14
 
15
  # ───────────────────────────── Step 1: Heart Prediction ───────────────────────────── #
16
  if st.session_state.page == "heart":
 
 
17
  st.session_state.age = st.slider("Age", 1, 100, 30)
18
  sex = st.selectbox("Sex", ["Male", "Female"])
19
- st.header("❀️ Step 1: Heart Disease Prediction")
20
-
21
  st.session_state.sex = 1 if sex == "Male" else 0
22
 
23
  st.session_state.cp = st.selectbox("Chest Pain Type", [0, 1, 2, 3])
@@ -46,6 +46,7 @@ if st.session_state.page == "heart":
46
  elif st.session_state.page == "chest":
47
  st.header("🫁 Step 2: Chest Disease Symptoms")
48
 
 
49
  st.session_state.position = st.selectbox("View Position", ["PA", "AP"])
50
 
51
  uploaded_file = st.file_uploader("Upload Chest X-ray", type=["jpg", "jpeg", "png"])
@@ -59,47 +60,37 @@ elif st.session_state.page == "chest":
59
  st.session_state.conditions.append(1 if st.checkbox(question) else 0)
60
 
61
  if st.button("Next β†’ Combined Prediction"):
62
- if not uploaded_file:
63
- st.warning("Please upload a chest X-ray to continue.")
64
- elif not any(st.session_state.conditions):
65
- st.warning("Please answer at least one clinical question.")
66
- else:
67
  st.session_state.page = "combined"
68
  st.rerun()
 
 
69
 
70
- # ───────────────────────────── Step 3: Combined Prediction ───────────────────────────── #
71
  # ───────────────────────────── Step 3: Combined Prediction ───────────────────────────── #
72
  elif st.session_state.page == "combined":
73
  st.header("πŸ” Step 3: Combined Prediction Results")
74
 
75
- # Check required session state values
76
- if "position" in st.session_state and "conditions" in st.session_state:
77
- chest_result = predict_chest(
78
- st.session_state.position,
79
- st.session_state.conditions
80
- )
81
- else:
82
- st.error("Missing chest input data. Please complete the chest step first.")
83
- if st.button("⬅️ Go Back to Chest Symptoms"):
84
- st.session_state.page = "chest"
85
- st.rerun()
86
- st.stop()
87
-
88
- heart_result = st.session_state.get("heart_result", "Unknown")
89
 
90
  st.image(st.session_state.image, caption="Chest X-ray", use_container_width=True)
91
 
92
  if chest_result == "Chest Disease Detected":
93
- st.error(f"❌ Chest Disease Prediction: **{chest_result}**")
94
  else:
95
- st.success(f"βœ… Chest Disease Prediction: **{chest_result}**")
96
 
97
- st.success(f"❀️ Heart Disease Prediction: **{heart_result}**")
98
 
99
  if "Detected" in chest_result or "Detected" in heart_result:
100
- st.error("⚠️ Combined Risk: **High** β€” Immediate attention recommended.")
101
  else:
102
- st.success("βœ… Combined Risk: **Low** β€” You seem to be in good health.")
103
 
104
  if st.button("πŸ” Start Over"):
105
  st.session_state.clear()
 
10
  st.session_state.page = "heart"
11
 
12
  st.title("🩺 Disease Prediction App")
13
+ st.markdown("Follow the steps to assess your *Heart, **Chest, and **Combined Health Risk*.")
14
 
15
  # ───────────────────────────── Step 1: Heart Prediction ───────────────────────────── #
16
  if st.session_state.page == "heart":
17
+ st.header("❀ Step 1: Heart Disease Prediction")
18
+
19
  st.session_state.age = st.slider("Age", 1, 100, 30)
20
  sex = st.selectbox("Sex", ["Male", "Female"])
 
 
21
  st.session_state.sex = 1 if sex == "Male" else 0
22
 
23
  st.session_state.cp = st.selectbox("Chest Pain Type", [0, 1, 2, 3])
 
46
  elif st.session_state.page == "chest":
47
  st.header("🫁 Step 2: Chest Disease Symptoms")
48
 
49
+ st.session_state.gender = st.selectbox("Gender", ["Male", "Female"])
50
  st.session_state.position = st.selectbox("View Position", ["PA", "AP"])
51
 
52
  uploaded_file = st.file_uploader("Upload Chest X-ray", type=["jpg", "jpeg", "png"])
 
60
  st.session_state.conditions.append(1 if st.checkbox(question) else 0)
61
 
62
  if st.button("Next β†’ Combined Prediction"):
63
+ if uploaded_file:
 
 
 
 
64
  st.session_state.page = "combined"
65
  st.rerun()
66
+ else:
67
+ st.warning("Please upload a chest X-ray to continue.")
68
 
 
69
  # ───────────────────────────── Step 3: Combined Prediction ───────────────────────────── #
70
  elif st.session_state.page == "combined":
71
  st.header("πŸ” Step 3: Combined Prediction Results")
72
 
73
+ chest_result = predict_chest(
74
+ st.session_state.age,
75
+ st.session_state.gender,
76
+ st.session_state.position,
77
+ st.session_state.conditions
78
+ )
79
+ heart_result = st.session_state.heart_result
 
 
 
 
 
 
 
80
 
81
  st.image(st.session_state.image, caption="Chest X-ray", use_container_width=True)
82
 
83
  if chest_result == "Chest Disease Detected":
84
+ st.error(f"❌ Chest Disease Prediction: *{chest_result}*")
85
  else:
86
+ st.success(f"βœ… Chest Disease Prediction: *{chest_result}*")
87
 
88
+ st.success(f"❀ Heart Disease Prediction: *{heart_result}*")
89
 
90
  if "Detected" in chest_result or "Detected" in heart_result:
91
+ st.error("⚠ Combined Risk: *High* β€” Immediate attention recommended.")
92
  else:
93
+ st.success("βœ… Combined Risk: *Low* β€” You seem to be in good health.")
94
 
95
  if st.button("πŸ” Start Over"):
96
  st.session_state.clear()