Download src/streamlit_app.py from BeyzaTopbas/Breast-Cancer-Prediction: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/BeyzaTopbas/Breast-Cancer-Prediction/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/BeyzaTopbas/Breast-Cancer-Prediction/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/BeyzaTopbas/Breast-Cancer-Prediction/resolve/main/src/streamlit_app.py
1.42 kB
| 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%})") |