rangerrRed commited on
Commit
42a0157
·
verified ·
1 Parent(s): 6b5b0d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -76
app.py CHANGED
@@ -1,107 +1,104 @@
1
  import streamlit as st
2
- from chest_utils import predict_chest
 
3
  from heart_utils import predict_heart
4
 
5
- st.set_page_config(page_title="Disease Prediction App", layout="centered")
6
- st.title("🩺 Disease Prediction App")
7
 
8
- st.markdown(
9
- """
10
- Welcome to the Chest and Heart Disease Prediction App.
11
- Select the type of prediction from the dropdown below, fill in the details, and click *Predict*.
12
- """
13
- )
14
 
15
- option = st.selectbox("Choose the type of prediction:", ["Chest Disease", "Heart Disease", "Combined Prediction"])
 
16
 
 
 
 
 
17
  if option == "Chest Disease":
18
- st.header("🫁 Chest Disease Prediction")
19
- age = st.slider("Age", 1, 100, 25)
 
 
 
 
 
 
20
  gender = st.selectbox("Gender", ["Male", "Female"])
21
- position = st.selectbox("View Position", ["PA", "AP"])
22
- condition_questions = [
23
- "Do you have a cough?",
24
- "Do you feel shortness of breath?",
25
- "Are you experiencing chest pain?",
26
- "Do you smoke?",
27
- "Do you have a fever?",
28
- "Do you have fatigue?",
29
- "Have you had recent respiratory infection?",
30
- "Do you have a family history of lung issues?",
31
- "Do you feel wheezing or noisy breathing?",
32
- "Have you been exposed to pollution or chemicals recently?"
33
- ]
34
- conditions = [int(st.checkbox(q)) for q in condition_questions]
35
 
36
  if st.button("Predict Chest Disease"):
37
- result = predict_chest(age, gender, position, conditions)
38
- st.success(f"Prediction: *{result}*")
 
 
 
39
 
 
40
  elif option == "Heart Disease":
41
- st.header("❤ Heart Disease Prediction")
42
- age = st.slider("Age", 1, 100, 40)
43
- sex = st.selectbox("Sex", ["Male", "Female"])
44
  cp = st.selectbox("Chest Pain Type (cp)", [0, 1, 2, 3])
45
- trestbps = st.number_input("Resting Blood Pressure", min_value=80, max_value=200, value=120)
46
- chol = st.number_input("Serum Cholesterol (mg/dl)", min_value=100, max_value=600, value=200)
47
- fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", [1, 0])
48
- restecg = st.selectbox("Resting ECG Results", [0, 1, 2])
49
- thalach = st.number_input("Max Heart Rate Achieved", min_value=60, max_value=220, value=150)
50
- exang = st.selectbox("Exercise Induced Angina", [1, 0])
51
- oldpeak = st.number_input("ST Depression Induced by Exercise", min_value=0.0, max_value=6.0, value=1.0)
52
  slope = st.selectbox("Slope of ST Segment", [0, 1, 2])
53
- ca = st.selectbox("Number of Major Vessels (0–3)", [0, 1, 2, 3])
54
- thal = st.selectbox("Thalassemia", [1, 2, 3])
55
 
56
  if st.button("Predict Heart Disease"):
57
  result = predict_heart(age, sex, cp, trestbps, chol, fbs, restecg,
58
  thalach, exang, oldpeak, slope, ca, thal)
59
- st.success(f"Prediction: *{result}*")
60
 
 
61
  elif option == "Combined Prediction":
62
  st.header("🔁 Combined Disease Prediction")
63
- age = st.slider("Age", 1, 100, 30)
64
 
65
- st.subheader("Chest Symptoms")
 
66
  gender = st.selectbox("Gender", ["Male", "Female"])
67
- position = st.selectbox("View Position", ["PA", "AP"])
68
- condition_questions = [
69
- "Do you have a cough?",
70
- "Do you feel shortness of breath?",
71
- "Are you experiencing chest pain?",
72
- "Do you smoke?",
73
- "Do you have a fever?",
74
- "Do you have fatigue?",
75
- "Have you had recent respiratory infection?",
76
- "Do you have a family history of lung issues?",
77
- "Do you feel wheezing or noisy breathing?",
78
- "Have you been exposed to pollution or chemicals recently?"
79
- ]
80
  conditions = [int(st.checkbox(q)) for q in condition_questions]
81
 
82
- st.subheader("Heart Parameters")
83
- sex = st.selectbox("Sex", ["Male", "Female"], key="heart_sex")
 
 
84
  cp = st.selectbox("Chest Pain Type (cp)", [0, 1, 2, 3])
85
- trestbps = st.number_input("Resting Blood Pressure", min_value=80, max_value=200, value=120)
86
- chol = st.number_input("Serum Cholesterol (mg/dl)", min_value=100, max_value=600, value=200)
87
- fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", [1, 0])
88
- restecg = st.selectbox("Resting ECG Results", [0, 1, 2])
89
- thalach = st.number_input("Max Heart Rate Achieved", min_value=60, max_value=220, value=150)
90
- exang = st.selectbox("Exercise Induced Angina", [1, 0])
91
- oldpeak = st.number_input("ST Depression Induced by Exercise", min_value=0.0, max_value=6.0, value=1.0)
92
  slope = st.selectbox("Slope of ST Segment", [0, 1, 2])
93
- ca = st.selectbox("Number of Major Vessels (0–3)", [0, 1, 2, 3])
94
  thal = st.selectbox("Thalassemia", [1, 2, 3])
95
 
96
  if st.button("Predict Combined Risk"):
97
- chest_result = predict_chest(age, gender, position, conditions)
98
- heart_result = predict_heart(age, sex, cp, trestbps, chol, fbs, restecg,
99
- thalach, exang, oldpeak, slope, ca, thal)
100
-
101
- st.success(f"Chest Disease Prediction: *{chest_result}*")
102
- st.success(f"Heart Disease Prediction: *{heart_result}*")
103
-
104
- if chest_result == "Chest Disease Detected" or heart_result == "Heart Disease Detected":
105
- st.error("⚠ Combined Risk: *High* — Immediate attention recommended.")
106
  else:
107
- st.success("✅ Combined Risk: *Low* — You seem to be in good health.")
 
 
 
 
 
 
 
 
 
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("Predict your risk for **Chest Disease**, **Heart Disease**, or **Both** in one place.")
 
 
 
 
10
 
11
+ # Sidebar Navigation
12
+ option = st.sidebar.radio("Choose Prediction Type", ["Chest Disease", "Heart Disease", "Combined Prediction"])
13
 
14
+ # Shared Input
15
+ age = st.slider("Age", 1, 120, 30)
16
+
17
+ # Chest Disease Section
18
  if option == "Chest Disease":
19
+ st.header("📷 Chest Disease Prediction")
20
+
21
+ st.subheader("Upload Chest X-ray")
22
+ uploaded_file = st.file_uploader("Choose a chest X-ray image...", type=["jpg", "jpeg", "png"])
23
+ if uploaded_file:
24
+ image = Image.open(uploaded_file)
25
+ st.image(image, caption="Uploaded X-ray", use_column_width=True)
26
+
27
  gender = st.selectbox("Gender", ["Male", "Female"])
28
+ view_position = st.selectbox("View Position", ["PA", "AP"])
29
+
30
+ st.subheader("Clinical Questions")
31
+ disease_inputs = [1 if st.radio(q, ["No", "Yes"], index=0) == "Yes" else 0 for q in condition_questions]
 
 
 
 
 
 
 
 
 
 
32
 
33
  if st.button("Predict Chest Disease"):
34
+ if not uploaded_file:
35
+ st.warning("Please upload a chest X-ray image.")
36
+ else:
37
+ result = predict_chest(image, age, gender, view_position, disease_inputs)
38
+ st.success(f"Chest Disease Prediction: {result}")
39
 
40
+ # Heart Disease Section
41
  elif option == "Heart Disease":
42
+ st.header("❤️ Heart Disease Prediction")
43
+
44
+ sex = st.selectbox("Sex", [0, 1], format_func=lambda x: "Male" if x == 1 else "Female")
45
  cp = st.selectbox("Chest Pain Type (cp)", [0, 1, 2, 3])
46
+ trestbps = st.number_input("Resting Blood Pressure", 50, 250)
47
+ chol = st.number_input("Cholesterol (mg/dL)", 100, 600)
48
+ fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", [0, 1])
49
+ restecg = st.selectbox("Resting ECG", [0, 1, 2])
50
+ thalach = st.number_input("Max Heart Rate", 60, 250)
51
+ exang = st.selectbox("Exercise Induced Angina", [0, 1])
52
+ oldpeak = st.number_input("ST Depression", 0.0, 10.0, step=0.1)
53
  slope = st.selectbox("Slope of ST Segment", [0, 1, 2])
54
+ ca = st.selectbox("Number of Major Vessels (ca)", [0, 1, 2, 3, 4])
55
+ thal = st.selectbox("Thal", [0, 1, 2, 3])
56
 
57
  if st.button("Predict Heart Disease"):
58
  result = predict_heart(age, sex, cp, trestbps, chol, fbs, restecg,
59
  thalach, exang, oldpeak, slope, ca, thal)
60
+ st.success(f"Heart Disease Prediction: {result}")
61
 
62
+ # Combined Section
63
  elif option == "Combined Prediction":
64
  st.header("🔁 Combined Disease Prediction")
 
65
 
66
+ # Chest Section
67
+ st.subheader("Chest Disease Part")
68
  gender = st.selectbox("Gender", ["Male", "Female"])
69
+ view_position = st.selectbox("View Position", ["PA", "AP"])
70
+ uploaded_file = st.file_uploader("Upload Chest X-ray...", type=["jpg", "jpeg", "png"])
71
+
72
+ st.markdown("### Clinical Questions")
 
 
 
 
 
 
 
 
 
73
  conditions = [int(st.checkbox(q)) for q in condition_questions]
74
 
75
+ # Heart Section
76
+ st.subheader("Heart Disease Part")
77
+ sex = st.selectbox("Sex", ["Male", "Female"], key="combined_sex")
78
+ sex_val = 1 if sex == "Male" else 0
79
  cp = st.selectbox("Chest Pain Type (cp)", [0, 1, 2, 3])
80
+ trestbps = st.number_input("Resting Blood Pressure", 80, 200, value=120)
81
+ chol = st.number_input("Cholesterol (mg/dL)", 100, 600, value=200)
82
+ fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", [0, 1])
83
+ restecg = st.selectbox("Resting ECG", [0, 1, 2])
84
+ thalach = st.number_input("Max Heart Rate Achieved", 60, 220, value=150)
85
+ exang = st.selectbox("Exercise Induced Angina", [0, 1])
86
+ oldpeak = st.number_input("ST Depression", 0.0, 6.0, value=1.0)
87
  slope = st.selectbox("Slope of ST Segment", [0, 1, 2])
88
+ ca = st.selectbox("Number of Major Vessels (ca)", [0, 1, 2, 3])
89
  thal = st.selectbox("Thalassemia", [1, 2, 3])
90
 
91
  if st.button("Predict Combined Risk"):
92
+ # Chest Prediction
93
+ if not uploaded_file:
94
+ st.warning("Please upload a chest X-ray image.")
 
 
 
 
 
 
95
  else:
96
+ image = Image.open(uploaded_file)
97
+ chest_result = predict_chest(image, age, gender, view_position, conditions)
98
+ heart_result = predict_heart(
99
+ age, sex_val, cp, trestbps, chol, fbs, restecg,
100
+ thalach, exang, oldpeak, slope, ca, thal
101
+ )
102
+
103
+ st.success(f"Chest Disease Prediction: {chest_result}")
104
+ st.success(f"Heart Disease Prediction: {heart_result}")