varshitha22 commited on
Commit
c6e4f83
·
verified ·
1 Parent(s): 397b10c

Update cancer.py

Browse files
Files changed (1) hide show
  1. cancer.py +17 -13
cancer.py CHANGED
@@ -71,7 +71,7 @@ with st.sidebar:
71
  st.session_state['x_train'] = x_train
72
  st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
73
 
74
- st.title("🎗️ Cancer Prediction Using Machine Learning 🎗️")
75
 
76
  st.markdown("""<style>.big-font {font-size:20px !important;}</style>
77
  <p class="big-font">Provide patient details below to predict cancer presence:</p>""", unsafe_allow_html=True)
@@ -93,16 +93,20 @@ with col2:
93
  input_data = [[age, tumor_size, tumor_grade, symptoms_severity, smoking_history,
94
  alcohol_consumption, exercise_frequency, gender, family_history]]
95
 
96
- if st.button("Predict Cancer Presence"):
97
- input_df = pd.DataFrame(input_data, columns=x_train.columns)
98
- input_transformed = model.named_steps['preprocessor'].transform(input_df)
99
- prediction = model.named_steps['classifier'].predict(input_transformed)
100
-
101
- # Display prediction with styled text and additional message
102
- if prediction[0] == 1:
103
- st.markdown("<h3 style='color: red;'>Cancer Prediction: Positive 🟥</h3>", unsafe_allow_html=True)
104
- st.write("Unfortunately, the model predicts the presence of cancer. Please consult a doctor for further advice.")
 
 
 
 
 
 
105
  else:
106
- st.markdown("<h3 style='color: green;'>Cancer Prediction: Negative 🟩</h3>", unsafe_allow_html=True)
107
- st.write("Good news! The model predicts that there is no cancer detected. Stay healthy!")
108
-
 
71
  st.session_state['x_train'] = x_train
72
  st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
73
 
74
+ st.title("🎗️ Cancer Prediction🎗️")
75
 
76
  st.markdown("""<style>.big-font {font-size:20px !important;}</style>
77
  <p class="big-font">Provide patient details below to predict cancer presence:</p>""", unsafe_allow_html=True)
 
93
  input_data = [[age, tumor_size, tumor_grade, symptoms_severity, smoking_history,
94
  alcohol_consumption, exercise_frequency, gender, family_history]]
95
 
96
+ f st.button("Predict Cancer Presence"):
97
+ if 'trained_model' in st.session_state:
98
+ model = st.session_state['trained_model']
99
+ x_train = st.session_state['x_train']
100
+ input_df = pd.DataFrame(input_data, columns=x_train_train.columns)
101
+ input_transformed = model.named_steps['preprocessor'].transform(input_df)
102
+ prediction = model.named_steps['classifier'].predict(input_transformed)
103
+
104
+ # Change the title and prediction result
105
+ if prediction[0] == 1:
106
+ st.markdown("<h3 style='color: red;'>Cancer Prediction: Positive 🟥</h3>", unsafe_allow_html=True)
107
+ st.write("Unfortunately, the model predicts the presence of cancer. Please consult a doctor for further advice.")
108
+ else:
109
+ st.markdown("<h3 style='color: green;'>Cancer Prediction: Negative 🟩</h3>", unsafe_allow_html=True)
110
+ st.write("Good news! The model predicts that there is no cancer detected. Stay healthy!")
111
  else:
112
+ st.error("Please train a model first!")