rangerrRed commited on
Commit
6830370
Β·
verified Β·
1 Parent(s): 2a22fb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -96
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="🩺 Disease Prediction App", layout="centered")
7
 
8
- # Initialize navigation state
9
- 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 DISEASE ─────── #
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])
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
- st.session_state.image = Image.open(uploaded_file)
55
- st.image(st.session_state.image, caption="Uploaded X-ray", use_column_width=True)
56
-
57
- st.subheader("Answer Clinical Questions:")
58
- questions = [
59
- "Do you have a cough?",
60
- "Do you feel shortness of breath?",
61
- "Are you experiencing chest pain?",
62
- "Do you smoke?",
63
- "Do you have a fever?",
64
- "Do you have fatigue?",
65
- "Have you had recent respiratory infection?",
66
- "Do you have a family history of lung issues?",
67
- "Do you feel wheezing or noisy breathing?",
68
- "Have you been exposed to pollution or chemicals recently?"
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
- st.warning("Please upload a chest X-ray to continue.")
78
-
79
- # ─────── STEP 3: COMBINED PREDICTION ─────── #
80
- elif st.session_state.page == "combined":
81
- st.header("πŸ” Step 3: Combined Prediction Results")
82
-
83
- chest_result = predict_chest(
84
- st.session_state.age,
85
- st.session_state.gender,
86
- st.session_state.position,
87
- st.session_state.conditions
88
- )
89
- heart_result = st.session_state.heart_result
90
-
91
- st.image(st.session_state.image, caption="Chest X-ray", use_column_width=True)
92
-
93
- if chest_result == "Chest Disease Detected":
94
- st.error(f"❌ Chest Disease Prediction: **{chest_result}**")
95
- else:
96
- st.success(f"βœ… Chest Disease Prediction: **{chest_result}**")
97
-
98
- st.success(f"❀️ Heart Disease Prediction: **{heart_result}**")
99
-
100
- if "Detected" in chest_result or "Detected" in heart_result:
101
- st.error("⚠️ Combined Risk: **High** β€” Immediate attention recommended.")
102
- else:
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}")