Spaces:
Sleeping
Sleeping
Commit ·
16f357a
1
Parent(s): bd9273b
delete old python file
Browse files
app.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
# Import necessary libraries
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import joblib
|
| 4 |
-
|
| 5 |
-
# Load the trained model
|
| 6 |
-
model = joblib.load("./model-3.joblib")
|
| 7 |
-
|
| 8 |
-
# Define function to predict heart disease
|
| 9 |
-
def predict_heart_disease(sex, exang, cp_1, cp_2, cp_4, slope_1, slope_2, thal_3, thal_7):
|
| 10 |
-
print([[sex, exang, cp_1, cp_2, cp_4, slope_1, slope_2, thal_3, thal_7]])
|
| 11 |
-
prediction = model.predict([[sex, exang, cp_1, cp_2, cp_4, slope_1, slope_2, thal_3, thal_7]])
|
| 12 |
-
return prediction
|
| 13 |
-
|
| 14 |
-
# Create the Streamlit web application
|
| 15 |
-
def main():
|
| 16 |
-
# Set title and description
|
| 17 |
-
st.title("Heart Disease Prediction")
|
| 18 |
-
st.write("This app predicts the presence of heart disease based on selected attributes.")
|
| 19 |
-
|
| 20 |
-
# Design user interface
|
| 21 |
-
sex = st.selectbox("Sex", ["Female", "Male"])
|
| 22 |
-
exang = st.selectbox("Exercise Induced Angina", ["No", "Yes"])
|
| 23 |
-
cp = st.selectbox("Chest Pain Type", ["Typical Angina", "Atypical Angina", "Non-Anginal Pain", "Asymptomatic"])
|
| 24 |
-
slope = st.selectbox("Slope of Peak Exercise ST Segment", ["Upsloping", "Flat", "Downsloping"])
|
| 25 |
-
thal = st.selectbox("Thal", ["Normal", "Fixed Defect", "Reversible Defect"])
|
| 26 |
-
|
| 27 |
-
# Map selected options to numerical values
|
| 28 |
-
sex_mapping = {"Female": 0, "Male": 1}
|
| 29 |
-
exang_mapping = {"No": 0, "Yes": 1}
|
| 30 |
-
cp_1_mapping = {"Typical Angina": 1, "Atypical Angina": 0, "Non-Anginal Pain": 0, "Asymptomatic": 0}
|
| 31 |
-
cp_2_mapping = {"Typical Angina": 0, "Atypical Angina": 1, "Non-Anginal Pain": 0, "Asymptomatic": 0}
|
| 32 |
-
cp_4_mapping = {"Typical Angina": 0, "Atypical Angina": 0, "Non-Anginal Pain": 0, "Asymptomatic": 1}
|
| 33 |
-
slope_1_mapping = {"Upsloping": 1, "Flat": 0, "Downsloping": 0}
|
| 34 |
-
slope_2_mapping = {"Upsloping": 0, "Flat": 1, "Downsloping": 0}
|
| 35 |
-
thal_3_mapping = {"Normal": 1, "Fixed Defect": 0, "Reversible Defect": 0}
|
| 36 |
-
thal_7_mapping = {"Normal": 0, "Fixed Defect": 0, "Reversible Defect": 1}
|
| 37 |
-
|
| 38 |
-
# Predict button
|
| 39 |
-
if st.button("Predict"):
|
| 40 |
-
result = predict_heart_disease(sex_mapping[sex], exang_mapping[exang], cp_1_mapping[cp], cp_2_mapping[cp], cp_4_mapping[cp], slope_1_mapping[slope], slope_2_mapping[slope], thal_3_mapping[thal], thal_7_mapping[thal])
|
| 41 |
-
if result == 1:
|
| 42 |
-
st.write("The model predicts that the patient has heart disease.")
|
| 43 |
-
else:
|
| 44 |
-
st.write("The model predicts that the patient does not have heart disease.")
|
| 45 |
-
|
| 46 |
-
# Run the Streamlit app
|
| 47 |
-
if __name__ == "__main__":
|
| 48 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|