Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,107 +1,63 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
-
from chest_utils import predict_chest
|
| 4 |
from heart_utils import predict_heart
|
| 5 |
|
| 6 |
-
st.set_page_config(page_title="
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
st.session_state.page = "heart"
|
| 11 |
|
| 12 |
-
|
| 13 |
-
st.
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
st.header("β€οΈ Step 1: Heart Disease Prediction")
|
| 18 |
|
| 19 |
-
st.
|
| 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])
|
| 24 |
-
st.session_state.trestbps = st.number_input("Resting Blood Pressure", 80, 200, 120)
|
| 25 |
-
st.session_state.chol = st.number_input("Serum Cholesterol (mg/dl)", 100, 600, 200)
|
| 26 |
-
st.session_state.fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", [0, 1])
|
| 27 |
-
st.session_state.restecg = st.selectbox("Resting ECG", [0, 1, 2])
|
| 28 |
-
st.session_state.thalach = st.number_input("Max Heart Rate", 60, 250, 150)
|
| 29 |
-
st.session_state.exang = st.selectbox("Exercise Induced Angina", [0, 1])
|
| 30 |
-
st.session_state.oldpeak = st.number_input("ST Depression", 0.0, 6.0, 1.0)
|
| 31 |
-
st.session_state.slope = st.selectbox("Slope of ST Segment", [0, 1, 2])
|
| 32 |
-
st.session_state.ca = st.selectbox("Number of Major Vessels", [0, 1, 2, 3])
|
| 33 |
-
st.session_state.thal = st.selectbox("Thalassemia", [1, 2, 3])
|
| 34 |
-
|
| 35 |
-
if st.button("Next β Chest Symptoms"):
|
| 36 |
-
st.session_state.heart_result = predict_heart(
|
| 37 |
-
st.session_state.age, st.session_state.sex, st.session_state.cp, st.session_state.trestbps,
|
| 38 |
-
st.session_state.chol, st.session_state.fbs, st.session_state.restecg, st.session_state.thalach,
|
| 39 |
-
st.session_state.exang, st.session_state.oldpeak, st.session_state.slope,
|
| 40 |
-
st.session_state.ca, st.session_state.thal
|
| 41 |
-
)
|
| 42 |
-
st.session_state.page = "chest"
|
| 43 |
-
st.rerun()
|
| 44 |
-
|
| 45 |
-
# βββββββ STEP 2: CHEST DISEASE βββββββ #
|
| 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"])
|
| 53 |
if uploaded_file:
|
| 54 |
-
|
| 55 |
-
st.image(
|
| 56 |
-
|
| 57 |
-
st.
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
st.session_state.conditions = [1 if st.checkbox(q) else 0 for q in questions]
|
| 71 |
-
|
| 72 |
-
if st.button("Next β Combined Prediction"):
|
| 73 |
-
if uploaded_file:
|
| 74 |
-
st.session_state.page = "combined"
|
| 75 |
-
st.rerun()
|
| 76 |
else:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
elif
|
| 81 |
-
st.header("
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
st.
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
st.success("β
Combined Risk: **Low** β You seem to be in good health.")
|
| 104 |
-
|
| 105 |
-
if st.button("π Start Over"):
|
| 106 |
-
st.session_state.clear()
|
| 107 |
-
st.rerun()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
+
from chest_utils import predict_chest, condition_questions
|
| 4 |
from heart_utils import predict_heart
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="Health Predictor", layout="centered")
|
| 7 |
|
| 8 |
+
st.title("π©Ί Health Predictor")
|
| 9 |
+
st.markdown("Supports both *Chest Disease* and *Heart Disease* predictions.")
|
|
|
|
| 10 |
|
| 11 |
+
# Sidebar for navigation
|
| 12 |
+
disease_type = st.sidebar.radio("Select Disease Type", ["Chest Disease", "Heart Disease"])
|
| 13 |
|
| 14 |
+
if disease_type == "Chest Disease":
|
| 15 |
+
st.header("Chest Disease Prediction")
|
|
|
|
| 16 |
|
| 17 |
+
st.subheader("Upload Chest X-ray")
|
| 18 |
+
uploaded_file = st.file_uploader("Choose a chest X-ray image...", type=["jpg", "jpeg", "png"])
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
if uploaded_file:
|
| 21 |
+
image = Image.open(uploaded_file)
|
| 22 |
+
st.image(image, caption="Uploaded X-ray", use_column_width=True)
|
| 23 |
+
|
| 24 |
+
age = st.number_input("Age", min_value=1, max_value=120, step=1)
|
| 25 |
+
gender = st.selectbox("Gender", ["Male", "Female"])
|
| 26 |
+
view_position = st.selectbox("View Position", ["PA", "AP"])
|
| 27 |
+
|
| 28 |
+
st.subheader("Answer the following clinical questions:")
|
| 29 |
+
disease_inputs = []
|
| 30 |
+
for question in condition_questions:
|
| 31 |
+
answer = st.radio(question, ["No", "Yes"], index=0, key=question)
|
| 32 |
+
disease_inputs.append(1 if answer == "Yes" else 0)
|
| 33 |
+
|
| 34 |
+
if st.button("Predict Chest Disease"):
|
| 35 |
+
if uploaded_file is None:
|
| 36 |
+
st.warning("Please upload a chest X-ray image.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
else:
|
| 38 |
+
result = predict_chest(age, gender, view_position, disease_inputs)
|
| 39 |
+
st.success(f"Prediction: {result}")
|
| 40 |
+
|
| 41 |
+
elif disease_type == "Heart Disease":
|
| 42 |
+
st.header("Heart Disease Prediction")
|
| 43 |
+
|
| 44 |
+
age = st.number_input("Age", min_value=1, max_value=120, step=1)
|
| 45 |
+
sex = st.selectbox("Sex", [0, 1], format_func=lambda x: "Male" if x == 1 else "Female")
|
| 46 |
+
cp = st.selectbox("Chest Pain Type (cp)", [0, 1, 2, 3])
|
| 47 |
+
trestbps = st.number_input("Resting Blood Pressure (trestbps)", min_value=50, max_value=250)
|
| 48 |
+
chol = st.number_input("Cholesterol (chol)", min_value=100, max_value=600)
|
| 49 |
+
fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl (fbs)", [0, 1])
|
| 50 |
+
restecg = st.selectbox("Resting ECG (restecg)", [0, 1, 2])
|
| 51 |
+
thalach = st.number_input("Max Heart Rate (thalach)", min_value=60, max_value=250)
|
| 52 |
+
exang = st.selectbox("Exercise Induced Angina (exang)", [0, 1])
|
| 53 |
+
oldpeak = st.number_input("ST depression (oldpeak)", min_value=0.0, max_value=10.0, step=0.1)
|
| 54 |
+
slope = st.selectbox("Slope of peak exercise ST segment", [0, 1, 2])
|
| 55 |
+
ca = st.selectbox("Number of major vessels colored by fluoroscopy (ca)", [0, 1, 2, 3, 4])
|
| 56 |
+
thal = st.selectbox("Thal", [0, 1, 2, 3])
|
| 57 |
+
|
| 58 |
+
if st.button("Predict Heart Disease"):
|
| 59 |
+
result = predict_heart(
|
| 60 |
+
age, sex, cp, trestbps, chol, fbs, restecg,
|
| 61 |
+
thalach, exang, oldpeak, slope, ca, thal
|
| 62 |
+
)
|
| 63 |
+
st.success(f"Prediction: {result}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|