Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 *
|
| 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
|
| 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 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 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: *
|
| 94 |
else:
|
| 95 |
-
st.success(f"β
Chest Disease Prediction: *
|
| 96 |
|
| 97 |
-
st.success(f"β€
|
| 98 |
|
| 99 |
if "Detected" in chest_result or "Detected" in heart_result:
|
| 100 |
-
st.error("β
|
| 101 |
else:
|
| 102 |
-
st.success("β
Combined Risk: *
|
| 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()
|