Breast-Cancer-Prediction / src /streamlit_app.py
BeyzaTopbas's picture
Update src/streamlit_app.py
28b866e verified
import streamlit as st
import pandas as pd
import joblib
import os
# ======================
# LOAD MODEL
# ======================
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
model_path = os.path.join(BASE_DIR, "model.pkl")
model = joblib.load(model_path)
# ======================
# PAGE CONFIG
# ======================
st.set_page_config(
page_title="Breast Cancer Prediction",
page_icon="๐ŸŽ—๏ธ",
layout="centered"
)
st.title("๐ŸŽ—๏ธ Breast Cancer Prediction")
st.write("Auto-generated inputs based on trained model features")
# ======================
# GET FEATURE NAMES
# ======================
feature_names = model.feature_names_in_
# ======================
# CREATE INPUTS
# ======================
st.sidebar.header("Input Features")
input_data = {}
for feature in feature_names:
input_data[feature] = st.sidebar.number_input(
feature,
value=float(model.feature_names_in_.shape[0]) # tijdelijk
)
input_df = pd.DataFrame([input_data])
st.subheader("Input Data")
st.write(input_df)
# ======================
# PREDICTION
# ======================
if st.button("Predict"):
prediction = model.predict(input_df)[0]
probability = model.predict_proba(input_df)[0][1]
st.subheader("Result")
if prediction == 1:
st.error(f"โš ๏ธ Malignant Tumor ({probability:.2%})")
else:
st.success(f"โœ… Benign Tumor ({1 - probability:.2%})")